Rutube custom seek time

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

Versione datata 09/11/2024. Vedi la nuova versione l'ultima versione.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

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

})();