Rutube Enhancer

Скрипт, добавляющий некоторые фишки для рутуба

// ==UserScript==
// @name         Rutube Enhancer
// @description  Скрипт, добавляющий некоторые фишки для рутуба
// @namespace    http://tampermonkey.net/
// @version      0.0.7
// @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;

    // Включает макет страницы на всю ширину
    const USE_FULL_WIDTH_LAYOUT = 1;

    if (ENABLE_STYLES_FIX) {
        injectStyles();
    }

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

    function stopEvent(e) {
        e.preventDefault();
        e.stopImmediatePropagation();
    }

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

        if (key === 'ArrowLeft') {
            stopEvent(e);

            vid.currentTime -= SEEK_SECONDS;

            if (vid.currentTime < 0) {
                vid.pause();
                vid.currentTime = 0;
            }
        } else if (key === 'ArrowRight') {
            stopEvent(e);

            vid.currentTime += SEEK_SECONDS;

            if (vid.currentTime > vid.duration) {
                vid.pause();
                vid.currentTime = 0;
            }
        } else if (key === 'Space') {
            stopEvent(e);

            if (vid.paused || vid.ended) {
                vid.play();
            } else {
                vid.pause();
            }
        }
    }

    function injectStyles() {
        const styles = `
          .wdp-video-adfox-module__container {
            display: none !important;
          }

          .wdp-video-wrapper-module__videoWrapper {
	        padding: 0 !important;
            height: calc(100vh - 104px) !important;
          }

          ${USE_FULL_WIDTH_LAYOUT ? `.video-page-container-module__container { max-width: none !important; }` : ''}
        `;

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

})();