B站视频倍速控制器脚本

调整B站视频播放速度

目前为 2022-03-01 提交的版本。查看 最新版本

// ==UserScript==
// @name         B站视频倍速控制器脚本
// @namespace    https://github.com/csXLJ/bzplayer/
// @version      2.0
// @description  调整B站视频播放速度
// @author       csXLJ
// @icon         https://www.bilibili.com/favicon.ico?v=1
// @include      https://www.bilibili.com/*
// @match        https://www.bilibili.com/video/*
// @grant        none
// @license      GPL
// ==/UserScript==

var controller = (function () {
    var timeId;
    var speed;
    function keyd(e) {
        var whichVideo = document.querySelector('bwp-video') != null ? document.querySelector('bwp-video') : document.querySelector('video');
        speed = whichVideo.playbackRate;
        if (e.key == "+") {
            if (speed == 16) {
                speed = 16;
            } else {
                speed = speed + 0.1;
                speed = roundFun(speed, 1);
            }
        } else if (e.key == "-") {
            if (speed == 0) {
                speed = 0;
            } else {
                speed = speed - 0.1;
                speed = roundFun(speed, 1);
            }
        }
        var str = "播放速度:"+speed + "x";
        addAndDelTil(whichVideo, "div", str);
        whichVideo.playbackRate = speed;
    }

    document.body.removeEventListener('keydown', keyd);
    document.body.addEventListener('keydown', keyd);

    function roundFun(value, n) {
        return Math.round(value * Math.pow(10, n)) / Math.pow(10, n);
    }

    function addAndDelTil(element, tab, str) {
        if (timeId != null) {
            $(element).prev().remove();
            clearTimeout(timeId);
        }
        var para = document.createElement(tab);
        var node = document.createTextNode(str);
        para.appendChild(node);
        para.style.position = "absolute";
        para.style.color = "white";
        //para.style.textShadow = "2px 2px 5px #00a1d6";
        para.style.fontWeight = "bold";
        para.style.borderRadius = "15px";
        para.style.border = "2px solid #00a1d6";
        para.style.backgroundColor = "#00a1d6";
        para.style.padding = "1px";
        para.style.opacity = "0.5";
        para.style.fontFamily = "-apple-system,BlinkMacSystemFont,Helvetica Neue,Helvetica,Arial,PingFang SC,Hiragino Sans GB,Microsoft YaHei,sans-serif";
        para.style.left = "1%";
        para.style.top = "1%";
        para.style.zIndex = 99999;
        element.before(para);
        timeId = setTimeout(function () {
            para.remove();
            clearTimeout(timeId);
        }, 2000);

    }
    // Your code here...
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址