bilibili视频倍速工具

按c加速,按x减速,步长0.05。

当前为 2022-11-21 提交的版本,查看 最新版本

// ==UserScript==
// @name         bilibili视频倍速工具
// @namespace    http://tampermonkey.net/
// @version      0.2.3
// @description  按c加速,按x减速,步长0.05。
// @author       You
// @match        https://www.bilibili.com/video/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=bilibili.com
// @grant        none
// @run-at document-end
// @license MIT
// ==/UserScript==

(function () {
    'use strict';
    const video = document.querySelector('video')
    const step = 0.05
    let speed = video.playbackRate
    video.addEventListener('ratechange', function () {
        speed = video.playbackRate
    })
    window.addEventListener('keypress', function (e) {
        if (e.key === "c") {
            speed = Math.round((speed + step) * 100) / 100
            video.playbackRate = speed
            notify(video.playbackRate)
        }
        if (e.key === "x") {
            speed = Math.round((speed - step) * 100) / 100
            video.playbackRate = speed
            notify(video.playbackRate)
        }
        if (e.key === "z") {
            speed = 1
            video.playbackRate = speed
            notify(video.playbackRate)
        }
    })

    function notify(msg) {
        const videoWrap = document.querySelector('.bpx-player-video-wrap')
        const className = 'edbe85b469d47a8833b84e259864e33'
        const box = document.createElement('div')
        box.className = className
        box.style.background = '#333'
        box.style.color = '#fff'
        box.style.padding = '8px 20px'
        box.style.position = 'fixed'
        box.style.margin = "auto"
        box.style.left = '50%'
        box.style.top = '30px'
        box.style.transform = "translateX(-50%)";
        box.style.borderRadius = "5px"
        box.style.zIndex = '10000'
        box.innerHTML = msg
        const oldBox = document.querySelectorAll('.' + className)
        if (oldBox.length) {
            oldBox.forEach(b => {
                b.remove()
            });
        }
        if (document.fullscreenElement) {
            videoWrap.appendChild(box)
        } else {
            document.body.appendChild(box)
        }
        setTimeout(() => {
            box.remove()
        }, 2000);
    }
})();

QingJ © 2025

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