HDrezka 1.75x Speed Toggle Button

Add custom speed toggle button for HDrezka media player

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name            HDrezka 1.75x Speed Toggle Button
// @name:en         HDrezka 1.75x Speed Toggle Button
// @name:uk         HDrezka 1.75x Speed Toggle Button
// @name:ru         HDrezka 1.75x Speed Toggle Button
// @author          zlost666
// @namespace       http://tampermonkey.net/
// @version         1.0
// @license         MIT
// @description     Add custom speed toggle button for HDrezka media player
// @description:uk  Add custom speed toggle button for HDrezka media player
// @description:ru  Add custom speed toggle button for HDrezka media player
// @include         http*://*rezka*/*
// @include         http*://hdrezka*/*
// @include         http*://rezka*/*
// @include         http*://hdrezka.me/*
// @include         http*://hdrezka.co/*
// @include         http*://rezka.ag/*
// @include         http*://rezkify.com/*
// @include         http*://rezkery.com/*
// @include         http*://kinopub.me/*
// @grant           none
// ==/UserScript==

(function() {
    'use strict';

    let isSpeedSet = false;

    // Function to create and add the custom speed button
    function addSpeedButton() {
        let videoPlayer = document.querySelector('video');

        if (videoPlayer) {
            let button = document.createElement('button');
            button.innerText = '1.75x';
            button.style.position = 'fixed';
            button.style.top = '20px';
            button.style.left = '50%';
            button.style.transform = 'translateX(-50%)';
            button.style.zIndex = 1000;
            button.style.padding = '5px';
            button.style.backgroundColor = 'rgba(0,0,0,0.5)';
            button.style.color = 'white';
            button.style.border = 'none';
            button.style.cursor = 'pointer';

            button.addEventListener('click', function() {
                if (isSpeedSet) {
                    videoPlayer.playbackRate = 1;
                    button.style.backgroundColor = 'rgba(0,0,0,0.5)';
                    button.innerText = '1.75x';
                } else {
                    videoPlayer.playbackRate = 1.75;
                    button.style.backgroundColor = 'rgba(0,150,0,0.5)';
                    button.innerText = 'Normal';
                }
                isSpeedSet = !isSpeedSet;
            });

            document.body.appendChild(button);
        } else {
            console.warn('HDrezka video player not found.');
        }
    }

    // Add the button when the page loads
    window.addEventListener('load', function() {
        setTimeout(addSpeedButton, 1000);
    });

    // Add the button when a new video is loaded
    document.addEventListener('DOMNodeInserted', function(event) {
        if (event.target && event.target.tagName === 'VIDEO') {
            addSpeedButton();
        }
    });

    console.log('HDrezka Custom Speed Toggle Button script loaded.');
})();