Google Home Video Speed Controller

Adds a simple, stable dropdown to control playback speed (including slow motion) on home.google.com.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Google Home Video Speed Controller
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Adds a simple, stable dropdown to control playback speed (including slow motion) on home.google.com.
// @author       Your Name
// @match        https://home.google.com/*
// @grant        none
// @run-at       document-idle
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    function createSpeedControl(playerElement, videoElement) {
        // Updated options to include slow-motion, normal, and fast-forward speeds
        const speedOptions = [
            { label: '0.25x', value: 0.25 },
            { label: '0.5x', value: 0.5 },
            { label: '0.75x', value: 0.75 },
            { label: 'Normal', value: 1 },
            { label: '1.5x', value: 1.5 },
            { label: '2x', value: 2 },
            { label: '3x', value: 3 },
            { label: '5x', value: 5 },
            { label: '10x', value: 10 }
        ];

        const selectContainer = document.createElement('div');
        selectContainer.id = 'speed-control-container';
        selectContainer.style.cssText = 'display: inline-block; margin-left: 15px; vertical-align: middle;';

        const select = document.createElement('select');
        select.id = 'speed-select';
        select.style.cssText = 'background: #202124; color: white; border: 1px solid #5f6368; border-radius: 4px; padding: 8px 12px; font-size: 14px; cursor: pointer;';

        speedOptions.forEach(option => {
            const opt = document.createElement('option');
            opt.value = option.value;
            opt.innerHTML = option.label;
            if (option.value === 1) opt.selected = true;
            select.appendChild(opt);
        });

        select.addEventListener('change', (event) => {
            const speed = parseFloat(event.target.value);
            videoElement.playbackRate = speed;
        });

        const centerButtons = playerElement.querySelector('.center-buttons');
        if (centerButtons) {
            centerButtons.appendChild(selectContainer);
            selectContainer.appendChild(select);
        }
    }

    function initialize() {
        const observer = new MutationObserver((mutations) => {
            const player = document.querySelector('ghw-full-player');
            if (player && player.querySelector('.center-buttons') && !document.getElementById('speed-control-container')) {
                const video = player.querySelector('video.isZoomable');
                if (video) {
                    createSpeedControl(player, video);
                    observer.disconnect();
                }
            }
        });

        observer.observe(document.body, { childList: true, subtree: true });
    }

    initialize();

})();