Rutube custom seek time

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

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

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