B站共同关注查询

查成分!

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

Advertisement:

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

Advertisement:

// ==UserScript==
// @name         B站共同关注查询
// @namespace    https://github.com/XiaoMiku01
// @version      0.2
// @description  查成分!
// @author       晓轩
// @match        https://*.bilibili.com/*
// @icon         https://www.google.com/s2/favicons?domain=bilibili.com
// @grant        none
// ==/UserScript==
(function () {
    async function readJSON(uid) {
        return new Promise((resolve, reject) => {
            fetch('https://api.bilibili.com/x/relation/same/followings?vmid=' + uid, {
                credentials: 'include'
            }).then(function (data) { resolve(data.json()) })
        })
    }
    var handler = function () {
        setTimeout(async function addP() {
            let a = document.getElementsByClassName("user-card")[0].getElementsByClassName("info");
            let p = document.createElement("p");
            let uid = a[0].getElementsByClassName("user")[0].getElementsByClassName("name")[0].getAttribute("href").split("/").slice(-1);
            let names = '共同关注:</br>';
            try {
                let data = await readJSON(uid);
                for (let i of data.data.list) {
                    names += i.uname + '</br>'
                }
            } catch (error) {
                names = "关注列表未开放";
            }
            p.innerHTML = names;
            a[0].appendChild(p);
        }, 1000);
    }
    var myVar = setInterval(function () { myTimer() }, 1000);
    function myTimer() {
        if (document.getElementsByClassName("user-face").length < 2) {}
        else {
            for (let i of document.querySelectorAll('.user-face, .reply-face')) {
                i.removeEventListener("mouseenter", handler)
                i.addEventListener("mouseenter", handler)
            }
        }
    }
})();