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.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

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

(I already have a user script manager, let me install it!)

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.

(I already have a user style manager, let me install it!)

// ==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);
    });

})();