Rutube custom seek time

Скрипт, задающий время перемотки по нажатию стрелок на клавиатуре

As of 09.11.2024. See апошняя версія.

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         Rutube custom seek time
// @description  Скрипт, задающий время перемотки по нажатию стрелок на клавиатуре
// @namespace    http://tampermonkey.net/
// @version      0.0.2
// @author       4ndefined
// @run-at       document-end
// @match        *://rutube.ru/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=rutube.ru
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // Время перемотки в секундах
    const SEEK_SECONDS = 5;

    const video = document.querySelector('[data-testid="video-portal"]');

    window.addEventListener('keydown', vidCtrl, true);

    injectStyles();

    function vidCtrl(e) {
        const vid = document.querySelector('video');
        const key = e.code;

        e.stopImmediatePropagation();

        if (key === 'ArrowLeft') {
            vid.currentTime -= SEEK_SECONDS;
            if (vid.currentTime < 0) {
                vid.pause();
                vid.currentTime = 0;
            }
        } else if (key === 'ArrowRight') {
            vid.currentTime += SEEK_SECONDS;
            if (vid.currentTime > vid.duration) {
                vid.pause();
                vid.currentTime = 0;
            }
        } else if (key === 'Space') {
            if (vid.paused || vid.ended) {
                vid.play();
            } else {
                vid.pause();
            }
        }
    }

    function injectStyles() {
        const styles = `
          .wdp-video-wrapper-module__videoWrapper {
	        padding-top: 51.25% !important;
          }
        `;

        document.head.insertAdjacentHTML("beforeend", `<style type="text/css" id="rutubeEnchacedStyles">${styles}</style>`)
    }

})();