Video Speed Controller for phone

Add a video speed controller to webpages with videos.

目前為 2023-08-18 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Video Speed Controller for phone
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  Add a video speed controller to webpages with videos.
// @author       Cool
// @match        *://*/*
// @grant        GM_addStyle
// @license MIT
// ==/UserScript==


(function () {
    'use strict';
    // Add a button to control video speed
    const speedButton = document.createElement('div');
    speedButton.id = 'videoSpeedButton';
    speedButton.innerHTML = '1.0x';
    speedButton.style.cssText = `
        position: fixed;
        top: 50%;
        right: 20px;
        background: rgba(0, 0, 0, 0.3);
        color: white;
        border-radius: 50%;
        width: 40px;
        height: 40px;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        z-index: 99999;
        font-size: 12px;
    `;
    document.body.appendChild(speedButton);

    // Define video playback speeds
    const playbackSpeeds = [1.0, 1.25, 1.5, 2.0, 2.5, 3.0, 4.0, 'Close'];

    speedButton.addEventListener('mouseenter', () => {
        const speedList = document.createElement('ul');
        speedList.style.cssText = `
            position: absolute;
            top: 0;
            left: 0;
            list-style: none;
            background: rgba(0, 0, 0, 0.8);
            padding: 5px;
            border-radius: 5px;
            text-align: center;
        `;

        playbackSpeeds.forEach(speed => {
            const listItem = document.createElement('li');
            listItem.style.padding = '5px';
            listItem.style.cursor = 'pointer';
            listItem.textContent = speed === 'Close' ? 'Close' : speed.toFixed(2) + 'x';

            listItem.addEventListener('click', () => {
                if (speed === 'Close') {
                  speedButton.removeChild(speedList);
                  speedButton.style.display = 'none';
                } else {
                    document.querySelectorAll('video').forEach(video => {
                        video.playbackRate = speed;
                    });
                  speedButton.textContent = speed.toFixed(2) + 'x';
                }
            });

            speedList.appendChild(listItem);
        });

        speedButton.appendChild(speedList);
    });

    speedButton.addEventListener('mouseleave', () => {
        speedButton.removeChild(speedButton.querySelector('ul'));
    });

    // Add styles to the button
    GM_addStyle(`
        #videoSpeedButton:hover {
            background: rgba(0, 0, 0, 0.6);
        }
    `);
})();