BiliOnlineHook

B站直播间同接数显示

Stan na 01-02-2024. Zobacz najnowsza wersja.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==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();
})();