键盘修改b站播放速度

使用键盘修改播放速度,且能突破b站上限 更新2.0

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

    // ==UserScript==
    // @name         键盘修改b站播放速度
    // @namespace    http://tampermonkey.net/
    // @version      [email protected]
    // @description  使用键盘修改播放速度,且能突破b站上限 更新2.0
    // @author       XinYu@19
    // @match        https://www.bilibili.com/video/*/*
    // @icon         https://www.bilibili.com/favicon.ico
    // @license      GPLv3
    // @grant        GM_addStyle
    // ==/UserScript==

    (function() 
    {
        'use strict';
        console.log('1.0更新');
        console.log('新增数字组合键实现播放速度改变');
        console.log('例如按键1+2可实现1.2倍速播放');
        console.log('单按数字键也可直接改变');
        console.log('+键可直接16倍速播放');
        let video = document.querySelector("video");
        let pressedKeys = []; // 用于存储按下的数字键
        let baseSpeed = 1; // 播放速度的基数,初始为1倍速

        window.addEventListener('keydown', function(e)
        {
            const key = e.key;
            if (/\d/.test(key))
            {
                pressedKeys.push(Number(key));
                if (pressedKeys.length === 2)
                {
                    baseSpeed = pressedKeys[0] + pressedKeys[1] * 0.1;
                    pressedKeys = [];
                }
                else if(pressedKeys.length === 1)
                {
                    baseSpeed = pressedKeys[0]
                }
            }
            else if(key == '+')//觉得+键不方便可自行更改
            {
                baseSpeed = 16;//也可以自行定义倍速
            }
            video.playbackRate = baseSpeed;
            console.log(`当前倍速:${video.playbackRate}`);
        });


        window.addEventListener('keyup', function()
        {
            if (pressedKeys.length !== 2) 
            {
                pressedKeys = [];
            }
        });
        // Your code here...
    })();