showbilibililocation

B站评论区展示IP归属地

Du musst eine Erweiterung wie Tampermonkey, Greasemonkey oder Violentmonkey installieren, um dieses Skript zu installieren.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

Sie müssten eine Skript Manager Erweiterung installieren damit sie dieses Skript installieren können

(Ich habe schon ein Skript Manager, Lass mich es installieren!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         showbilibililocation
// @namespace    github/BlackVisor
// @version      v1.0.0
// @description  B站评论区展示IP归属地
// @license      GPL-3.0
// @icon         data:image/svg+xml;charset=utf-8,%3Csvg%20viewBox%3D%220%200%201024%201024%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Cpath%20d%3D%22M834.307%20432.093s67.731%2029.89%2062.994%20184.286l48.828%2048.766s51.971-119.645%2033.066-222.092c0%200-1.554-96.101-173.26-223.653%200%200-85.077%209.405-78.757-78.784l-67.731-67.764-122.881%20122.879%2059.855%2059.917s148.077%206.229%2096.105%20127.546l-222.098%20223.713-42.54-6.291-253.607%20253.607s-17.345%2061.411%2026.778%2099.215c0%200%2028.34%2034.69%2088.221%2033.072l248.868-258.341%204.738-42.54%20253.573-251.988s14.202-22.051%2037.84-1.554v0.003M353.842%20460.372l80.345%2080.398%20108.707-108.679-83.521-83.521c88.221-201.664-165.382-280.388-165.382-280.388-47.243-12.642-37.805%2023.6-37.805%2023.6%2099.246%2081.902%2083.489%20108.683%2083.489%20108.683-12.583%2094.54-94.512%20130.793-94.512%20130.793-81.899%2034.628-149.629-80.345-149.629-80.345-26.781-4.73-23.636%2025.227-23.636%2025.227%2066.171%20291.412%20281.943%20184.223%20281.943%20184.223v0.006M607.476%20723.443l250.431%20266.245%20122.884-122.879-263.075-253.607-110.239%20110.239M857.905%20808.517l50.951%2036.993-19.466%2059.917h-62.966l-19.433-59.917%2050.913-36.993M857.905%20808.517z%22%3E%3C%2Fpath%3E%3C%2Fsvg%3E
// @match        https://*.bilibili.com/video/*
// @match        https://*.bilibili.com/list/watchlater*
// @exclude      https://live.bilibili.com/*
// @grant        unsafeWindow
// @run-at       document-start
// ==/UserScript==

(function () {
  'use strict';

  const handleInject = (shadowRoot, location) => {
    requestAnimationFrame(() => {
      if (!shadowRoot || shadowRoot.getElementById("ip")) return;
      const likeBtn = shadowRoot.querySelector("div#like") || shadowRoot.children[0];
      if (likeBtn) {
        const ipSpan = document.createElement("span");
        ipSpan.id = "ip";
        ipSpan.innerText = location;
        shadowRoot.insertBefore(ipSpan, likeBtn);
      }
    });
  };
  (function() {
    const originalAttach = Element.prototype.attachShadow;
    Element.prototype.attachShadow = function(init) {
      const shadow = originalAttach.call(this, init);
      const host = this;
      if (host.tagName === "BILI-COMMENT-ACTION-BUTTONS-RENDERER") {
        let retryCount = 0;
        const checkData = () => {
          retryCount++;
          const data = host.__data;
          if (data?.reply_control?.location) {
            handleInject(shadow, data.reply_control.location);
          } else {
            if (retryCount < 10) {
              setTimeout(checkData, 100);
            }
          }
        };
        checkData();
      }
      return shadow;
    };
  })();

})();