Fullscreen Video Speed Controller

Control playback speed, fix A/V sync issues, and seek for fullscreen videos

目前為 2025-05-16 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Fullscreen Video Speed Controller
// @version      2.0.0
// @description  Control playback speed, fix A/V sync issues, and seek for fullscreen videos
// @author       Wanten
// @copyright    2025 Wanten
// @license      MIT
// @supportURL   https://gist.github.com/WantenMN/c0afabc32a911d4dd10e06cff6bcb211
// @homepageURL  https://gist.github.com/WantenMN/c0afabc32a911d4dd10e06cff6bcb211
// @namespace    https://greasyfork.org/en
// @run-at       document-end
// @match        https://*/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Helper function to get the fullscreen video element
    function getFullscreenVideo() {
        if (document.fullscreenElement && document.fullscreenElement.tagName === 'VIDEO') {
            return document.fullscreenElement;
        }

        const videos = document.getElementsByTagName('video');
        for (const video of videos) {
            if (video.offsetWidth === window.innerWidth && video.offsetHeight === window.innerHeight) {
                return video;
            }
        }
        return null;
    }

    // Function to set the video speed
    function setVideoSpeed(speed) {
        const video = getFullscreenVideo();
        if (video) {
            video.playbackRate = speed;
        }
    }

    // Function to seek the video forward or backward
    function seekVideo(offset) {
        const video = getFullscreenVideo();
        if (video) {
            video.currentTime += offset;
        }
    }

    // Event listeners for key presses
    document.addEventListener('keydown', function(event) {
        switch(event.key) {
            case 'j':
                setVideoSpeed(1.00);
                break;
            case 'k':
                setVideoSpeed(2);
                break;
            case 'l':
                setVideoSpeed(3.00);
                break;
            case 'i': // Fix audio/video synchronization issues
                seekVideo(0.00001);
                break;
            case 'h':
                seekVideo(-5); // Rewind 5 seconds
                break;
            case ';':
                seekVideo(5); // Fast-forward 5 seconds
                break;
        }
    });
})();