BiliOnlineHook

B站直播间同接数显示

2024-02-01 يوللانغان نەشرى. ئەڭ يېڭى نەشرىنى كۆرۈش.

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

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.

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

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

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