bilibili多倍速调节(支持剧集和视频)转载

// @name         bilibili多倍速调节(支持剧集和视频)
// @namespace    lgldlk
// @version      0.2
// @description  bilibili多倍速调节(支持剧集和视频)~~~
// @author       lgldlk
// @include      *://*.bilibili.com/video/*
// @include      *://*.bilibili.tv/video/*
// @include      *://*.bilibili.com/bangumi/*
// @include      *://*.bilibili.tv/bangumi/*
// @run-at       document-start
// @grant        none
// ==/UserScript==
let cacheRate = 1,
    cacheFlag = true,
    rateArr = [5,4.8,4.6,4.4,4.2,4,3.8,3,6,3.4,3.2,3,2.8,2.6,2.4,2.2,2,1.8,1.6,1.4,1.2,1,0.8,0.6,0.4,0.2]
 
function waitForNode(nodeSelector, callback) {
    var node = nodeSelector();
    if (node) {
        callback(node);
    } else {
        setTimeout(function() { waitForNode(nodeSelector, callback); }, 100);
    }
}
 
 
function debounce(func, wait) {
    let timer;
    return function() {
        let context = this;
        let args = arguments;
        if (timer) clearTimeout(timer);
        timer = setTimeout(() => {
            func.apply(this, args)
        }, wait)
    }
}
 
function deleteChild(e) {
    var child = e.lastElementChild;
    while (child) {
        e.removeChild(child);
        child = e.lastElementChild;
    }
}
 
function setCacheRate(video, rate) {
    video.playbackRate = rate;
}
 
function setRateText(rate) {
    document.querySelector(".bilibili-player-video-btn-speed-name").innerText = `${rate}x`;
}
function detection(){
    let rateButtons=document.querySelector(".bilibili-player-video-btn-speed-menu-list");
    if(rateButtons.innerHTML!="5x"){
        initRateBody(null);
    }
 
}
const initRateBody = function(callBack) {
    waitForNode(() => document.querySelector('div.bilibili-player-video-btn-speed > div > ul'),
        (node) => {
            var oV = document.getElementsByTagName("video")[0];
            deleteChild(node)
            for (let i of rateArr) {
 
                var tmpLi = document.createElement('li');
                tmpLi.classList = "bilibili-player-video-btn-speed-menu-list";
                tmpLi.innerText = `${ i}x`;
                tmpLi.style.height="30px"
                tmpLi.style["font-size"]="16px"
                tmpLi.style["line-height"]="30px"
                tmpLi.addEventListener("click", function(k) {
                    return function() {
                        cacheRate = k
                        setCacheRate(oV, k)
                        setRateText(k)
                    }
                }(i));
                node.appendChild(tmpLi);
            }
            setTimeout(detection,1000)
            oV.addEventListener('DOMNodeRemoved', () => {
                if (cacheFlag == true) {
                    let tmp = debounce(function() {
                        initRateBody(setCacheRate(oV, cacheRate));
                        setRateText(cacheRate)
                        cacheFlag = true;
                    }, 1000)
                    tmp();
                }
                cacheFlag = false
            });
            callBack && callBack();
        });
};
window.onload = initRateBody(null);
window.onhashchange = function() {
    initRateBody(setCacheRate);
}

转载自:https://greasyfork.org/id/scripts/416424-bilibili%E5%A4%9A%E5%80%8D%E9%80%9F%E8%B0%83%E8%8A%82-%E6%94%AF%E6%8C%81%E5%89%A7%E9%9B%86%E5%92%8C%E8%A7%86%E9%A2%91/code

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值