BLTH icon indicating copy to clipboard operation
BLTH copied to clipboard

禁止在页面不可见时切换画质

Open JellyBeanXiewh opened this issue 9 months ago • 1 comments

描述

B站最近更新了一个特性,通过监听 visibilitychange 事件,在页面切换至不可见状态(document.visibilityState === "hidden")超过30秒后,自动把直播画质降到最低档,页面切换至可见状态时恢复原画质。此行为会导致画质切换时的音频卡顿,影响观看体验。希望能增加禁止在页面不可见时切换画质的功能。

脚本地址:https://s1.hdslb.com/bfs/static/blive/blfe-live-room/static/js/179.cef10c62090003b387b5.js

相关代码摘录如下:

...
this.visibilityChange = function() {
    var e, n;
    try {
        "hidden" === document.visibilityState ? ((null === (e = t.playInfo()) || void 0 === e ? void 0 : e.playingStatus) && t.beginCountDown(),
        (0,
        Ve.nO)("live_room_visibility_quality_change_hidden", {
            visibilityState: document.visibilityState,
            playingStatus: null === (n = t.playInfo()) || void 0 === n ? void 0 : n.playingStatus
        }, "custom", 0)) : (t.clearCountDown(),
        a()(t.currentQuality).length && t.switchToFrontend())
    } catch (t) {
        console.warn("handleVisibilityChange error:", t)
    }
}
,
this.beginCountDown = function() {
    t.clearCountDown(),
    t.timer = setInterval((function() {
        t.maxCountDown > 0 ? t.maxCountDown-- : (t.clearCountDown(),
        t.switchToBackend())
    }
    ), 1e3)
}
,
this.clearCountDown = function() {
    t.timer && (t.maxCountDown = 30,
    clearInterval(t.timer))
}
...

可能可以参考的内容

阻止B站检测后台标签页运行

JellyBeanXiewh avatar Apr 03 '25 16:04 JellyBeanXiewh

感谢,等我再研究一下之后会添加这个功能

andywang425 avatar May 31 '25 16:05 andywang425

7.2.1已更新,该功能已被添加至【屏蔽挂机检测】中

andywang425 avatar Jun 28 '25 06:06 andywang425