Greasy Fork 还支持 简体中文。

BiliOnlineHook

B站直播间同接数显示

目前為 2024-02-01 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         BiliOnlineHook
// @description  B站直播间同接数显示
// @namespace    http://tampermonkey.net/
// @version      0.0.4
// @author       jeffz615
// @match        *://live.bilibili.com/*
// @icon         https://live.bilibili.com/favicon.ico
// @sandbox      raw
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';
    function hook_wrapper() {
        let g_rank_count = 0;
        let g_online_count = 0;

        function on_online_rank_count(obj) {
            const rank_count = obj.data.count;
            const online_count = obj.data.online_count;
            let flag = false;
            if (rank_count && rank_count !== g_rank_count) {
                g_rank_count = rank_count;
                flag = true;
            }
            if (online_count && online_count !== g_online_count) {
                g_online_count = online_count;
                flag = true;
            }
            if (flag) {
                const showers = document.querySelectorAll("#rank-list-ctnr-box > div.tabs > ul > li.item")
                if (showers.length > 0) {
                    showers[0].innerText = '高能用户(' + g_rank_count + '/' + g_online_count + ')';
                    showers[0].setAttribute('title', '除号左边是贡献值非0人数,右边是所有人数。' + (g_online_count === 0 ? '' : ('计算结果:' + (g_rank_count / g_online_count * 100).toFixed(2) + '%')));
                }
            }
        }

        const cb_map = {
            "ONLINE_RANK_COUNT": on_online_rank_count,
        };

        Array.prototype.push = new Proxy(Array.prototype.push, {
            apply(target, thisArg, argArray) {
                try {
                    if (argArray && argArray.length > 0) {
                        for (let i = 0; i < argArray.length; i++) {
                            if (argArray[i] && argArray[i].cmd) {
                                if (cb_map[argArray[i].cmd]) {
                                    cb_map[argArray[i].cmd](argArray[i]);
                                }
                            } else {
                                break;
                            }
                        }
                    }
                } catch (e) {
                    console.error(e);
                }
                return Reflect.apply(target, thisArg, argArray);
            }
        });
    }
    hook_wrapper();
})();