Rutube custom seek time

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

目前为 2024-11-08 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Rutube custom seek time
  3. // @description Скрипт, задающий время перемотки по нажатию стрелок на клавиатуре
  4. // @namespace http://tampermonkey.net/
  5. // @version 2024-11-08
  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. const video = document.querySelector('[data-testid="video-portal"]');
  21.  
  22. window.addEventListener('keydown', vidCtrl, true);
  23.  
  24. injectStyles();
  25.  
  26. function vidCtrl(e) {
  27. const vid = document.querySelector('video');
  28. const key = e.code;
  29.  
  30. e.stopImmediatePropagation();
  31.  
  32. if (key === 'ArrowLeft') {
  33. vid.currentTime -= SEEK_SECONDS;
  34. if (vid.currentTime < 0) {
  35. vid.pause();
  36. vid.currentTime = 0;
  37. }
  38. } else if (key === 'ArrowRight') {
  39. vid.currentTime += SEEK_SECONDS;
  40. if (vid.currentTime > vid.duration) {
  41. vid.pause();
  42. vid.currentTime = 0;
  43. }
  44. } else if (key === 'Space') {
  45. if (vid.paused || vid.ended) {
  46. vid.play();
  47. } else {
  48. vid.pause();
  49. }
  50. }
  51. }
  52.  
  53. function injectStyles() {
  54. const styles = `
  55. .wdp-video-wrapper-module__videoWrapper {
  56. padding-top: 51.25%;
  57. }
  58. `;
  59.  
  60. document.head.insertAdjacentHTML("beforeend", `<style type="text/css" id="rutubeEnchacedStyles">${styles}</style>`)
  61. }
  62.  
  63. })();