Video Speed Controller

Change video playback speed with hotkeys.

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램을 설치해야 합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

Advertisement:

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

Advertisement:

// ==UserScript==
// @name           Video Speed Controller
// @icon           https://www.favicon.cc/favicon/39/699/favicon.png
// @namespace
// @version        1.0
// @description    Change video playback speed with hotkeys.
// @author         BlueAG
// @license        MIT
// @match          *://*/*
// @grant          none
// @run-at         document-idle
// @namespace https://greasyfork.org/users/1452677
// ==/UserScript==

(function() {
    'use strict';

    // Speed step for increase/decrease
    const SPEED_STEP = 0.25;
    const MIN_SPEED = 0.25;
    const MAX_SPEED = 10.0;

    // Show toast notification
    function showToast(text) {
        let toast = document.getElementById('tm-speed-toast');
        if (!toast) {
            toast = document.createElement('div');
            toast.id = 'tm-speed-toast';
            toast.style.cssText = `
                position: fixed;
                top: 20px;
                right: 20px;
                background: rgba(0,0,0,0.8);
                color: #fff;
                padding: 10px 16px;
                border-radius: 8px;
                font-family: Arial, sans-serif;
                font-size: 16px;
                font-weight: bold;
                z-index: 999999;
                transition: opacity 0.3s;
                pointer-events: none;
            `;
            document.body.appendChild(toast);
        }
        toast.textContent = text;
        toast.style.opacity = '1';
        clearTimeout(toast._timeout);
        toast._timeout = setTimeout(() => toast.style.opacity = '0', 1000);
    }

    // Get all video elements on page
    function getVideos() {
        return Array.from(document.querySelectorAll('video, audio'));
    }

    // Set speed for all videos
    function setSpeed(speed) {
        const videos = getVideos();
        if (videos.length === 0) return;

        // Clamp speed
        speed = Math.max(MIN_SPEED, Math.min(MAX_SPEED, speed));

        videos.forEach(v => {
            v.playbackRate = speed;
        });

        showToast(`${speed.toFixed(2)}x`);
    }

    // Adjust speed by delta
    function adjustSpeed(delta) {
        const videos = getVideos();
        if (videos.length === 0) return;

        const currentSpeed = videos[0].playbackRate;
        setSpeed(currentSpeed + delta);
    }

    // Reset speed to 1.0x
    function resetSpeed() {
        setSpeed(1.0);
    }

    // Hotkey listener
    document.addEventListener('keydown', (e) => {
        // Ignore if typing in input/textarea
        if (e.target.matches('input, textarea, [contenteditable="true"]')) return;

        switch(e.key) {
            case ']': // increase speed
            case ']':
                adjustSpeed(SPEED_STEP);
                e.preventDefault();
                break;

            case '[': // decrease speed
            case '[':
                adjustSpeed(-SPEED_STEP);
                e.preventDefault();
                break;

            case '0': // reset to 1.0x
                resetSpeed();
                e.preventDefault();
                break;


			case 'p': // pause/play toggle
			case 'P':
				getVideos().forEach(v => {
					if (v.paused) {
					v.play();
					showToast('▶ Play');
					} else {
					v.pause();
					showToast('⏸ Pause');
					}
				});
				e.preventDefault();
				break;

			case 'z': // mute/unmute toggle
			case 'Z':
                getVideos().forEach(v => {
                   v.muted = !v.muted;
                   showToast(v.muted ? '🔇 Muted' : '🔊 Unmuted');
                });
                e.preventDefault();
                break;
		}
    });

    // Apply 1.0x to new videos that load later
    const observer = new MutationObserver(() => {
        // Don't auto-set here or it'll override user changes
        // But we could show current speed if needed
    });

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

})();