Rutube custom seek time

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

当前为 2024-11-09 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

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

})();