Rutube custom seek time

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

目前为 2025-03-03 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Rutube custom seek time
  3. // @description Скрипт, задающий время перемотки по нажатию стрелок на клавиатуре
  4. // @namespace http://tampermonkey.net/
  5. // @version 0.0.3
  6. // @author 4ndefined
  7. // @run-at document-end
  8. // @match *://rutube.ru/*
  9. // @icon https://www.google.com/s2/favicons?sz=64&domain=rutube.ru
  10. // @grant none
  11. // @license MIT
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. // Время перемотки в секундах
  18. const SEEK_SECONDS = 5;
  19.  
  20. // Исправление размера видео (вкл = 1, выкл = 0)
  21. const ENABLE_STYLES_FIX = 1;
  22.  
  23. window.addEventListener('keydown', vidCtrl, true);
  24.  
  25. if (ENABLE_STYLES_FIX) {
  26. injectStyles();
  27. }
  28.  
  29. function vidCtrl(e) {
  30. const vid = document.querySelector('video');
  31. const key = e.code;
  32.  
  33. e.preventDefault();
  34. e.stopImmediatePropagation();
  35.  
  36. if (key === 'ArrowLeft') {
  37. vid.currentTime -= SEEK_SECONDS;
  38. if (vid.currentTime < 0) {
  39. vid.pause();
  40. vid.currentTime = 0;
  41. }
  42. } else if (key === 'ArrowRight') {
  43. vid.currentTime += SEEK_SECONDS;
  44. if (vid.currentTime > vid.duration) {
  45. vid.pause();
  46. vid.currentTime = 0;
  47. }
  48. } else if (key === 'Space') {
  49. if (vid.paused || vid.ended) {
  50. vid.play();
  51. } else {
  52. vid.pause();
  53. }
  54. }
  55. }
  56.  
  57. function injectStyles() {
  58. const styles = `
  59. .wdp-video-wrapper-module__videoWrapper {
  60. padding: 0 !important;
  61. height: calc(100vh - 88px);
  62. }
  63. `;
  64.  
  65. document.head.insertAdjacentHTML("beforeend", `<style type="text/css" id="rutubeEnchacedStyles">${styles}</style>`)
  66. }
  67.  
  68. })();