百度云网盘视频允许倍速播放

适用于百度云在线视频播放,倍速播放,没有额外的按钮,直接点击视频中的倍数按钮 即可倍数播放。需要定制脚本请联系QQ2847046608

// ==UserScript==
// @name         百度云网盘视频允许倍速播放
// @namespace    http://tampermonkey.net/
// @version      2024-11-27
// @description  适用于百度云在线视频播放,倍速播放,没有额外的按钮,直接点击视频中的倍数按钮 即可倍数播放。需要定制脚本请联系QQ2847046608
// @author       You
// @match        https://pan.baidu.com/pfile/video?*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=baidu.com
// @grant        none
// @license MIT
// ==/UserScript==

(function () {
    'use strict';
    clearInterval(window.asdasd);
    window.asdasd = setInterval(() => {
        var affsdasd = document.querySelector(".vp-video__control-bar--playback-rates");
        if (!!affsdasd && !affsdasd.classList.contains("aaaa")) {
            affsdasd.classList.add("aaaa");
            clearInterval(window.asdasd);

            affsdasd.insertAdjacentHTML('afterbegin', `
<div class="vp-video__control-bar--video-button is-svip"><!----><button type="button" class="vp-btn normal is-round" style=""><!----><span><!----> 4X</span></button><!----><!----></div>
  <div class="vp-video__control-bar--video-button is-svip"><!----><button type="button" class="vp-btn normal is-round" style=""><!----><span><!----> 3X</span></button><!----><!----></div>
  <div class="vp-video__control-bar--video-button is-svip"><!----><button type="button" class="vp-btn normal is-round" style=""><!----><span><!----> 2.5X</span></button><!----><!----></div>
`)

            function changeSpeed(sp) {
                if (!!!sp) {
                    sp = localStorage.playSpeed ?? 1;
                }
                document.querySelector("video").playbackRate = sp;

                document.querySelector(".chgsp.is-selected")?.classList.remove("is-selected");
                document.querySelector(".sp" + (sp + "").replace(/\./g, "-"))?.classList.add("is-selected");
            }

            document.querySelectorAll(".vp-video__control-bar--playback-rates > .vp-video__control-bar--video-button").forEach(o => {
                o.classList.add("chgsp");
                var sps = "sp" + o.querySelector("button").innerText.replace("X", "").trim().replace(/\./g, "-");
                o.classList.add(sps);

                o.onclick = function () {
                    localStorage.playSpeed = o.querySelector("button").innerText.replace("X", "").trim();
                    changeSpeed();
                    document.querySelector("video").play();
                    document.querySelector("wora-pc-dialog").style.display = "none";
                }
            });
            document.querySelector("video").onplay = function(){
                changeSpeed();
            }

            window.isRightDownTime = undefined;
            [
                document.body,
                document.querySelector(".video-js"), ...document.querySelector(".video-js").querySelectorAll('*')
            ].forEach(oo => {
                oo.onkeydown = () => {
                    switch (event.code) {
                        case "Right":
                        case "ArrowRight":
                            if (!!!window.isRightDownTime) {
                                window.isRightDownTime = new Date();
                            } else {
                                changeSpeed(4.3);
                            }
                            event.stopImmediatePropagation();
                            break;
                    }
                };

                oo.onkeyup = () => {
                    switch (event.code) {
                        case "Right":
                        case "ArrowRight":
                            if (new Date() - window.isRightDownTime < 450) {
                                document.querySelector("video").currentTime += 20;
                            }
                            window.isRightDownTime = undefined;
                            changeSpeed();
                            event.stopImmediatePropagation();
                            break;
                    }
                };
            });
        }
    }, 1000)
})();