Rutube Enhancer

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

  1. // ==UserScript==
  2. // @name Rutube Enhancer
  3. // @description Скрипт, добавляющий некоторые фишки для рутуба
  4. // @namespace http://tampermonkey.net/
  5. // @version 0.0.7
  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. // Включает макет страницы на всю ширину
  24. const USE_FULL_WIDTH_LAYOUT = 1;
  25.  
  26. if (ENABLE_STYLES_FIX) {
  27. injectStyles();
  28. }
  29.  
  30. window.addEventListener('keydown', handleKeyDown, true);
  31.  
  32. function stopEvent(e) {
  33. e.preventDefault();
  34. e.stopImmediatePropagation();
  35. }
  36.  
  37. function handleKeyDown(e) {
  38. const vid = document.querySelector('video');
  39. const key = e.code;
  40.  
  41. if (key === 'ArrowLeft') {
  42. stopEvent(e);
  43.  
  44. vid.currentTime -= SEEK_SECONDS;
  45.  
  46. if (vid.currentTime < 0) {
  47. vid.pause();
  48. vid.currentTime = 0;
  49. }
  50. } else if (key === 'ArrowRight') {
  51. stopEvent(e);
  52.  
  53. vid.currentTime += SEEK_SECONDS;
  54.  
  55. if (vid.currentTime > vid.duration) {
  56. vid.pause();
  57. vid.currentTime = 0;
  58. }
  59. } else if (key === 'Space') {
  60. stopEvent(e);
  61.  
  62. if (vid.paused || vid.ended) {
  63. vid.play();
  64. } else {
  65. vid.pause();
  66. }
  67. }
  68. }
  69.  
  70. function injectStyles() {
  71. const styles = `
  72. .wdp-video-adfox-module__container {
  73. display: none !important;
  74. }
  75.  
  76. .wdp-video-wrapper-module__videoWrapper {
  77. padding: 0 !important;
  78. height: calc(100vh - 104px) !important;
  79. }
  80.  
  81. ${USE_FULL_WIDTH_LAYOUT ? `.video-page-container-module__container { max-width: none !important; }` : ''}
  82. `;
  83.  
  84. document.head.insertAdjacentHTML("beforeend", `<style type="text/css" id="rutubeEnchacedStyles">${styles}</style>`)
  85. }
  86.  
  87. })();