Smooth YouTube livestream

5/11/2025, 9:27:12 PM

当前为 2025-05-11 提交的版本,查看 最新版本

// ==UserScript==
// @name                Smooth YouTube livestream
// @namespace           UserScripts
// @version             0.1.1
// @license             MIT License
// @match               https://www.youtube.com/*
// @grant               none
// @author              -
// @description         5/11/2025, 9:27:12 PM
// ==/UserScript==
(() => {
    let cid = 0;
    document.addEventListener('canplay', (e) => {
        if (!e || !e.isTrusted || !(e.target instanceof HTMLMediaElement)) return;
        const p = document.querySelector('.ytp-live-badge.ytp-live-badge-is-livehead');
        const media = e.target;
        if (p && media.playbackRate === 1) {
            if (cid) clearTimeout(cid);
            cid = setTimeout(() => {
                if (media.isConnected && media.matches('#player *, #ytd-player *') && media.playbackRate === 1 && p === document.querySelector('.ytp-live-badge.ytp-live-badge-is-livehead')) {
                    if (cid) clearTimeout(cid);
                    media.playbackRate = 0.968;
                    cid = setTimeout(() => {
                        // L = n * 1 - n * 0.968
                        if (media.isConnected && media.playbackRate === 0.968) {
                            media.playbackRate = 1;
                        }
                    }, 30000);
                }
            }, 100);
        }
    }, true);
})();