Video Speed Control

Adds a video speed control to the top right corner of the website if a video is present

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

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Video Speed Control
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Adds a video speed control to the top right corner of the website if a video is present
// @author       mboerr
// @match        https://www.youtube.com/*
// @match        https://www.twitch.tv/videos/*
// @match        https://www.amazon.de/gp/video/*
// @match        *
// @icon         https://www.google.com/s2/favicons?domain=youtube.com
// @grant        none
// @license MIT 
// ==/UserScript==

(function() {
    'use strict';

    // Create the slider element
    var slider = document.createElement("INPUT");
    const maxSpeed = 6;
    slider.setAttribute("type", "range");
    slider.setAttribute("min", "1");
    slider.setAttribute("max", maxSpeed);
    slider.setAttribute("value", "1");
    slider.setAttribute("step", "0.5");
    slider.setAttribute("list", "tickmarks");
    slider.style.cssText = "width: 200px;z-index:99999";

    // Create the datalist element
    var datalist = document.createElement("DATALIST");
    datalist.setAttribute("id", "tickmarks");
    datalist.style.cssText = "display: flex; flex-direction: column; justify-content: space-between; writing-mode: vertical-lr; width: 200px;";

    // Add all integers from 1 to maxSpeed to the datalist
    for (var i = 1; i <= maxSpeed; i++) {
        var option = document.createElement("OPTION");
        option.setAttribute("value", i);
        option.innerHTML = i + "x"; // Add a label to the option
        datalist.style.cssText = "padding:0;"
        datalist.appendChild(option);
    }

    // Create the div element
    var div = document.createElement("DIV");
    div.style.cssText = "position: fixed; top: 50px; right: 10px; z-index:9999; background-color:#ffffff80; border-radius:8px;";

    // Add the datalist and slider to the div
    div.appendChild(datalist);
    div.appendChild(slider);

    // Add the div to the page
    document.body.appendChild(div);

    // Add an event listener for when the slider value changes
    slider.addEventListener("input", function() {
        // Change playback speed of all videos
        const videos = document.querySelectorAll('video');
        for (let video of videos) {
            video.playbackRate = this.value;
        }
        //document.getElementsByTagName("video")[0].playbackRate = this.value;
    });
})();