Rutube custom seek time

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

// ==UserScript==
// @name         Rutube custom seek time
// @description  Скрипт, задающий время перемотки по нажатию стрелок на клавиатуре
// @namespace    http://tampermonkey.net/
// @version      0.0.3
// @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;

    // Исправление размера видео (вкл = 1, выкл = 0)
    const ENABLE_STYLES_FIX = 1;

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

    if (ENABLE_STYLES_FIX) {
        injectStyles();
    }

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

        e.preventDefault();
        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: 0 !important;
            height: calc(100vh - 88px);
          }
        `;

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

})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址