Bilibili 鼠标左键长按倍速播放

模仿 YouTube,鼠标左键长按视频加速播放,松开恢复,并防止触发暂停行为(模仿youtube长按加速,松开暂停的)

目前为 2025-05-12 提交的版本,查看 最新版本

// ==UserScript==
// @license MIT
// @name         Bilibili 鼠标左键长按倍速播放
// @namespace    https://bilibili.com/
// @version      2.0
// @description  模仿 YouTube,鼠标左键长按视频加速播放,松开恢复,并防止触发暂停行为(模仿youtube长按加速,松开暂停的)
// @author       toc178
// @match        *://www.bilibili.com/video/*
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    const ACCELERATED_RATE = 2.0;
    let originalRate = 1.0;
    let pressTime = 0;
    let suppressNextClick = false;

    function getVideo() {
        return document.querySelector('video');
    }

    function onPointerDown(event) {
        if (event.button !== 0) return; // 左键
        const video = getVideo();
        if (!video) return;
        originalRate = video.playbackRate;
        video.playbackRate = ACCELERATED_RATE;
        pressTime = Date.now();
    }

    function onPointerUp(event) {
        if (event.button !== 0) return;
        const video = getVideo();
        if (!video) return;
        video.playbackRate = originalRate;

        // 判断是否为长按
        if (Date.now() - pressTime > 150) {
            suppressNextClick = true;
        }
    }

    function onClick(event) {
        if (suppressNextClick) {
            event.stopImmediatePropagation();
            event.preventDefault();
            suppressNextClick = false;
            console.log("🎯 阻止了一次点击以防暂停");
        }
    }

    function register() {
        const target = document.querySelector('.bpx-player-video-wrap') || document;
        target.addEventListener('pointerdown', onPointerDown, true);
        target.addEventListener('pointerup', onPointerUp, true);
        target.addEventListener('click', onClick, true);
    }

    function waitForVideo() {
        const timer = setInterval(() => {
            if (getVideo()) {
                clearInterval(timer);
                register();
                console.log('🚀 Bilibili 鼠标长按倍速脚本已启用(暂停已完全阻止)');
            }
        }, 500);
    }

    waitForVideo();
})();

QingJ © 2025

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