Greasy Fork

来自缓存

Greasy Fork is available in English.

恢复B站直播视频码率显示

恢复哔哩哔哩直播网页播放器的视频统计信息里的视频码率信息显示

当前为 2022-04-09 提交的版本,查看 最新版本

// ==UserScript==
// @name         恢复B站直播视频码率显示
// @version      0.2
// @namespace    https://genteure.github.io/userscripts
// @description  恢复哔哩哔哩直播网页播放器的视频统计信息里的视频码率信息显示
// @license      MIT
// @author       Genteure
// @match        https://live.bilibili.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=bilibili.com
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    // 说明:
    // 脚本里的 module id 是写死的,B站重新打包播放器 js 后可能会失效,需要手动重新找一下 id
    // 完整的信息会复制到 window.pstreaminfo 可在 console 里获取

    function replaceFunction(ptype) {
        let original_updateVideoTemplate = ptype.updateVideoTemplate;

        if (!original_updateVideoTemplate) {
            console.log('[直播码率信息UserScript] 没有找到 updateVideoTemplate', window.location.href);
        } else {
            let new_updateVideoTemplate = function () {
                window.pstreaminfo = arguments[0];
                let i = arguments[0].mediaInfo;
                let result = original_updateVideoTemplate.apply(this, arguments);
                try {
                    document.querySelector('#p-video-info-videoInfo > .web-player-line-data').textContent = i.width + "x" + i.height + ", " + i.fps + "FPS, " + this.computeBps(i.videoDataRate)
                } catch (error) {}
                return result;
            };

            ptype.updateVideoTemplate = new_updateVideoTemplate;
            console.log('[直播码率信息UserScript] updateVideoTemplate 替换完成', window.location.href);
        }
    }

    function findBase(prequire) {
        while (prequire) {
            if (typeof prequire.cache.SR9Z === 'object') {
                return prequire.cache.SR9Z.exports.default.prototype;
            } else {
                prequire = prequire.parent;
            }
        }
    }

    const ptype = findBase(window.parcelRequire);

    if (!ptype) {
        console.log('[直播码率信息UserScript] 没有找到 updateVideoTemplate 所在的 prototype', window.location.href);
    } else {
        replaceFunction(ptype);
    }

})();