Greasy Fork

Greasy Fork is available in English.

视频神器-改变播放速度

无视限制,改变网页端视频播放速度

当前为 2024-12-22 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         视频神器-改变播放速度
// @namespace    http://tampermonkey.net/
// @version      2024-12-21
// @description  无视限制,改变网页端视频播放速度
// @author       You
// @match        *://*/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=greasyfork.org
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';
    window.onload = function() {
    setTimeout(() => {
    // 获取页面上的所有video元素
    const videos = document.querySelectorAll('video');
    if (videos?.length <= 0) {
      console.log('this website has no video tag');
      return;
    }
        // 创建一个最外层的容器来包裹所有元素
    const outerContainer = document.createElement('div');
    outerContainer.id = 'playback-rate-controller-outer';
    outerContainer.style.position = 'fixed';
    outerContainer.style.top = '10px';
    outerContainer.style.right = '10px';
    outerContainer.style.zIndex = '9999';
    outerContainer.style.display = 'flex';
    outerContainer.style.flexDirection = 'column';
    outerContainer.style.alignItems = 'flex-end'; // 将内容对齐到容器的右侧
    outerContainer.style.backgroundColor = 'rgba(255, 255, 255, 0.9)'; // 设置半透明背景
    outerContainer.style.padding = '10px';
    outerContainer.style.borderRadius = '5px';
    outerContainer.style.boxShadow = '0 0 10px rgba(0, 0, 0, 0.1)';

    // 创建标题行
    const title = document.createElement('div');
    title.textContent = '播放速度控制条';
    title.style.fontWeight = 'bold';
    title.style.marginBottom = '10px'; // 添加底部间距以分隔标题与内容

    // 创建一个内层容器来包裹输入框和按钮
    const innerContainer = document.createElement('div');
    innerContainer.style.display = 'flex';
    innerContainer.style.alignItems = 'center';

    // 创建输入框
    const inputBox = document.createElement('input');
    inputBox.type = 'number';
    inputBox.value = '1.0'; // 设定默认播放速率为1.0
    inputBox.min = '0.1'; // 设定最小播放速率为0.1
    inputBox.max = '10.0'; // 设定最大播放速率为4.0(根据浏览器和视频支持情况调整)
    inputBox.step = '0.1'; // 设定步长为0.1
    inputBox.style.width = '60px';
    inputBox.style.padding = '5px';
    inputBox.style.marginRight = '10px'; // 为按钮预留间距

    // 创建按钮
    const applyButton = document.createElement('button');
    applyButton.textContent = '应用';
    applyButton.style.padding = '5px 10px';
    applyButton.style.cursor = 'pointer';

    // 将元素添加到内层容器中
    innerContainer.appendChild(inputBox);
    innerContainer.appendChild(applyButton);

    // 将标题和内层容器添加到外层容器中
    outerContainer.appendChild(title);
    outerContainer.appendChild(innerContainer);

    // 将外层容器添加到页面的body中
    document.body.appendChild(outerContainer);

    // 为按钮添加点击事件监听器
    applyButton.addEventListener('click', function() {
        const rate = parseFloat(inputBox.value);
        videos.forEach(video => {
            if (video.playbackRate !== rate) { // 避免不必要的设置,如果速率未改变
                video.playbackRate = rate;
            }
        });
    });

    let isDragging = false;
    let startX, startY, initialLeft, initialTop;

    outerContainer.addEventListener('mousedown', function(e) {
        isDragging = true;
        startX = e.clientX;
        startY = e.clientY;
        initialLeft = parseInt(outerContainer.style.left, 10);
        initialTop = parseInt(outerContainer.style.top, 10);
        document.addEventListener('mousemove', onMouseMove);
        document.addEventListener('mouseup', onMouseUp);
       // e.preventDefault(); // 阻止默认行为,如文本选择
    });

    function onMouseMove(e) {
        if (isDragging) {
            const deltaX = e.clientX - startX;
            const deltaY = e.clientY - startY;
            let left = initialLeft + deltaX;
            let top = initialTop + deltaY;
            if (left < 0) {
              left = 0;
            }
            if (top < 0) {
              top = 0;
            }
            if (top >= 300) {
              top = 300;
            }
            console.log(`left:${left} top ${top}`);
            outerContainer.style.left = `${left}px`;
            outerContainer.style.top = `${top}px`;
        }
    }

    function onMouseUp() {
        isDragging = false;
        document.removeEventListener('mousemove', onMouseMove);
        document.removeEventListener('mouseup', onMouseUp);
    }

    }, 1000);

    }



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