BiliOnlineHook

B站直播间同接数显示

2024-02-01 기준 버전입니다. 최신 버전을 확인하세요.

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램을 설치해야 합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 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();
})();