🏠 Home 

微博ip属地显示助手

##微博显示用户ip属地


安装此脚本?
  1. // ==UserScript==
  2. // @name 微博ip属地显示助手
  3. // @name:zh 微博ip属地显示助手
  4. // @name:zh-CN 微博ip属地显示助手
  5. // @description ##微博显示用户ip属地
  6. // @description:zh ##微博显示用户ip属地
  7. // @description:zh-CN ##微博显示用户ip属地
  8. // @version 1.3
  9. // @author NiaoBlush
  10. // @license GPL
  11. // @namespace https://github.com/NiaoBlush/weibo-ip-location
  12. // @homepageURL https://github.com/NiaoBlush/weibo-ip-location
  13. // @supportURL https://github.com/NiaoBlush/weibo-ip-location/issues
  14. // @match https://weibo.com/*
  15. // @match https://m.weibo.cn/*
  16. // @require https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js
  17. // @grant GM.xmlHttpRequest
  18. // @connect weibo.com
  19. // ==/UserScript==
  20. (function () {
  21. "use strict";
  22. function getRegion(uid) {
  23. return new Promise((resolve, reject) => {
  24. $.get(`https://weibo.com/ajax/profile/detail?uid=${uid}`, function (res) {
  25. if (res.data && res.data.ip_location) {
  26. const regionFull = res.data.ip_location;
  27. console.debug("[weibo-ip-location] info", uid, regionFull);
  28. const array = /IP属地:(.+)/.exec(regionFull);
  29. if (array != null) {
  30. resolve(array[1]);
  31. } else {
  32. resolve("")
  33. }
  34. } else {
  35. resolve("")
  36. }
  37. })
  38. })
  39. }
  40. function getRegionGM(uid) {
  41. return new Promise(((resolve, reject) => {
  42. GM.xmlHttpRequest({
  43. url: `https://weibo.com/ajax/profile/detail?uid=${uid}`,
  44. method: "GET",
  45. onload: function (xhr) {
  46. const res = JSON.parse(xhr.responseText)
  47. if (res.data && res.data.ip_location) {
  48. const regionFull = res.data.ip_location;
  49. console.debug("[weibo-ip-location] info", uid, regionFull);
  50. const array = /IP属地:(.+)/.exec(regionFull);
  51. if (array != null) {
  52. resolve(array[1]);
  53. } else {
  54. resolve("")
  55. }
  56. } else {
  57. resolve("")
  58. }
  59. }
  60. });
  61. }))
  62. }
  63. const district = ["北#", "天津", "河北", "山西", "内蒙古", "辽宁", "吉林", "黑龙江", "上海", "江苏", "浙江", "安徽", "福建", "江西", "山东", "河南", "湖北", "湖南", "广东", "广西", "海南", "重庆", "四川", "贵州", "云南", "##", "陕西", "甘肃", "青海", "宁夏", "##", "##", "####", "#门"];
  64. const mark = ($obj, region) => {
  65. const markedClass = "weibo-ip-marked";
  66. if (!region || ($obj.hasClass(markedClass))) {
  67. return;
  68. }
  69. $obj.addClass(markedClass);
  70. const foreign = region && district.indexOf(region) === -1
  71. let html;
  72. if (foreign) {
  73. html = `<span style="background-color: red;color: #FFF;margin-left: 5px;font-weight: bold;border-radius: 8px;padding: 2px 5px;">${region}</span>`;
  74. } else {
  75. html = `<span style="color: #00d0ff;margin-left: 5px;font-weight: normal;border-radius: 8px;padding: 2px 5px;">(${region})</span>`;
  76. }
  77. $obj.append(html);
  78. }
  79. console.log("[weibo ip region] $.fn.jquery", $.fn.jquery);
  80. const regionMap = {}
  81. //v6
  82. $(".WB_main").bind("DOMNodeInserted", function (e) {
  83. const $e = $(e.target);
  84. if ($e.attr("id") === "v6_pl_content_homefeed") {
  85. $(".WB_main").unbind();
  86. console.log("$e.html()", $e.html());
  87. $e.bind("DOMNodeInserted", function (ev) {
  88. processList($(ev.target))
  89. })
  90. }
  91. })
  92. //v7
  93. $("[class^='Home_feed']").bind("DOMNodeInserted", function (e) {
  94. const ele = $(e.target)
  95. processList(ele)
  96. })
  97. function processList($ele) {
  98. const list = $ele.find("a[class^='ALink_default']:not([aria-label]),.WB_info>a[usercard]")
  99. list.each(async function () {
  100. const href = $(this).attr("href");
  101. const array = /\/u\/(\d+)/.exec(href)
  102. if (array != null) {
  103. const uid = array[1];
  104. let region = regionMap[uid]
  105. if (region === undefined) {
  106. region = await getRegion(uid);
  107. regionMap[uid] = region;
  108. }
  109. mark($(this), region)
  110. }
  111. })
  112. }
  113. //mobile
  114. if (location.host === "m.weibo.cn") {
  115. $("#app").bind("DOMNodeInserted", function (appE) {
  116. const appChild = $(appE.target)
  117. if (appChild.hasClass("main-wrap")) {
  118. $("#app").unbind("DOMNodeInserted");
  119. appChild.bind("DOMNodeInserted", function (mainE) {
  120. const mainChild = $(mainE.target)
  121. if (mainChild.is("div") && mainChild.attr("class") === undefined) {
  122. appChild.unbind("DOMNodeInserted");
  123. processMobileList(mainChild);
  124. $(".pannelwrap").bind("DOMNodeInserted", function (pE) {
  125. processMobileList($(pE.target));
  126. })
  127. }
  128. })
  129. }
  130. })
  131. function processMobileList($ele) {
  132. const list = $ele.find(".weibo-top .m-text-box > a, .weibo-text > span > a:not([data-hide])")
  133. list.each(async function () {
  134. let $target = $(this);
  135. const href = $target.attr("href");
  136. const array = /\/profile\/(\d+)/.exec(href);
  137. if ($(this).parent().hasClass("m-text-box")) {
  138. $target = $target.find("h3").first();
  139. }
  140. if (array != null) {
  141. const uid = array[1];
  142. let region = regionMap[uid]
  143. if (region === undefined) {
  144. region = await getRegionGM(uid);
  145. regionMap[uid] = region;
  146. }
  147. mark($target, region)
  148. }
  149. })
  150. }
  151. }
  152. })();