VkvideoCustomizableRewindVideo

Changes the video rewind speed in VK videos. When you press the "right arrow" and "left arrow" keys, it changes from 10 to 5 seconds. When you press the "<" and ">" keys, it changes to 0.1 seconds.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         VkvideoCustomizableRewindVideo
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Changes the video rewind speed in VK videos. When you press the "right arrow" and "left arrow" keys, it changes from 10 to 5 seconds. When you press the "<" and ">" keys, it changes to 0.1 seconds.
// @author       Darkselia
// @match        https://vkvideo.ru/*
// @license MIT


// ==/UserScript==

(function() {
    let TIME = 5;

    function waitForElement(selector, callback) {
        const el = document.querySelector(selector);
        if (el) return callback(el);

        const observer = new MutationObserver(() => {
            const el = document.querySelector(selector);
            if (el) {
                observer.disconnect();
                callback(el);
            }
        });
        observer.observe(document.body, { childList: true, subtree: true });
    }

    waitForElement('video.videoplayer_media_provider', (video) => {
        if (window.__speedControlKeyDown) {
            document.removeEventListener('keydown', window.__speedControlKeyDown, true);
            window.__speedControlKeyDown = undefined;
        }
        if (window.__speedControlKeyUp) {
            document.removeEventListener('keyup', window.__speedControlKeyUp, true);
            window.__speedControlKeyUp = undefined;
        }

        function seek(e, time){
            e.preventDefault();
            e.stopImmediatePropagation();

            const t = video.currentTime;
            const a = e.key === 'ArrowLeft' || e.keyCode === 188 ? -1 : 1;

            video.currentTime = Math.max(Math.min(video.duration, t + time*a), 0);
        }

        function handleKeyDown(e) {
            if (e.key === 'ArrowLeft' || e.key === 'ArrowRight') seek(e, TIME);


            if (e.keyCode === 188 || e.keyCode === 190) seek(e, 0.1);
        }

        function handleKeyUp(e) {
            if (e.key !== 'ArrowLeft' && e.key !== 'ArrowRight' && e.keyCode !== 188 && e.keyCode !== 190) return;

            e.preventDefault();
            e.stopImmediatePropagation();
        }

        window.__speedControlKeyDown = handleKeyDown;
        window.__speedControlKeyUp = handleKeyUp;

        document.addEventListener('keydown', handleKeyDown, true);
        document.addEventListener('keyup', handleKeyUp, true);
    });

})();