Rutube Enhancer

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

// ==UserScript==
// @name         Rutube Enhancer
// @description  Скрипт, добавляющий некоторые фишки для рутуба
// @namespace    http://tampermonkey.net/
// @version      0.1.0
// @author       4ndefined
// @run-at       document-end
// @match        *://rutube.ru/*
// @match        *://rutube.sport/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=rutube.ru
// @grant        GM.addStyle
// @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,
          .wdp-auth-offer-popup-module__wrapper {
            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; }` : ''}
        `;

        const rutubeSportStyles = `
            /* main header */
            [class*="_headerWrapper_"] {
                padding: var(--rt-spacing-8x) !important;
            }

            /* some ads container */
            [id*="adfox_newspage_top"] {
                display: none;
            }

            /* video container div */
            [class*="_player"][class*="_video"] {
                max-height: calc(100vh - 80px);
            }

            /* preview poster */
            [class*="loader-template-module_wrapper__"] {
                background-size: contain !important;
            }

            /* player containers */
            #app > div > div {
                padding-top: 0 !important;
            }
            #app > div > div > div {
                max-width: none !important;
            }

            /* video title and description */
            main header {
                order: 2;
            }
            main header + div > section {
                margin: 0 !important;
            }
        `;

        GM.addStyle(styles);
        GM.addStyle(rutubeSportStyles);
    }

 })();