Video Shortcuts

Speed up, slow down, advance, rewind, loop any HTML5 video on any site with quick shortcuts!

当前为 2020-04-07 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Video Shortcuts
  3. // @name:de Video-Verknüpfungen
  4. // @name:en Video Shortcuts
  5. // @name:es Video Shortcuts
  6. // @name:it Video Shortcuts
  7. // @name:ja Video Shortcuts
  8. // @name:fr Video Shortcuts
  9. // @name:ko Video Shortcuts
  10. // @name:pl Video Shortcuts
  11. // @name:ru Video Shortcuts
  12. // @name:zh 影片捷径
  13. // @namespace videoShortcuts
  14. // @version 0.1
  15. // @description Speed up, slow down, advance, rewind, loop any HTML5 video on any site with quick shortcuts!
  16. // @description:de Beschleunigen, verlangsamen, vorrücken, zurückspulen, jedes HTML5-Video auf jeder Site mit schnellen Verknüpfungen schleifen!
  17. // @description:en Speed up, slow down, advance, rewind, loop any HTML5 video on any site with quick shortcuts!
  18. // @description:es ¡Acelere, reduzca la velocidad, avance, retroceda, repita cualquier video HTML5 en cualquier sitio con atajos rápidos!
  19. // @description:it Accelera, rallenta, avanza, riavvolgi, riproduci in loop qualsiasi video HTML5 su qualsiasi sito con tasti rapidi!
  20. // @description:ja クイックショートカットを使用して、サイト上のHTML5ビデオをスピードアップ、スローダウン、アドバンス、巻き戻し、ループします。
  21. // @description:fr Accélérez, ralentissez, avancez, rembobinez, bouclez n'importe quelle vidéo HTML5 sur n'importe quel site avec des raccourcis rapides!
  22. // @description:ko 빠른 바로 가기로 모든 사이트에서 HTML5 비디오의 속도를 높이고, 느리게하고, 진행하고, 되 감고, 반복합니다!
  23. // @description:pl Przyspiesz, zwalniaj, przewijaj, przewijaj do tyłu, zapętlaj dowolny film HTML5 na dowolnej stronie dzięki szybkim skrótom!
  24. // @description:ru Ускоряйте, замедляйте, перематывайте вперед и назад, зацикливайте любое видео HTML5 на любом сайте с помощью быстрых клавиш!
  25. // @description:zh 加快,放慢速度,快进,快退,循环播放任何站点上的HTML5视频,并提供快速快捷键!
  26. // @author Blank
  27. // @match *://*/*
  28. // @run-at document-idle
  29. // @grant none
  30. // @compatible chrome
  31. // @compatible firefox
  32. // @compatible safari
  33. // @compatible opera
  34. // ==/UserScript==
  35.  
  36.  
  37. // shortcuts:
  38. // - speed - 0.25 (speedDelta const)
  39. // = speed + 0.25 (speedDelta const)
  40. // \ speed = 1
  41. // ] advance 10s (timeDelta const)
  42. // [ rewind 10s (timeDelta const)
  43. // ` toggle loop (loop is OFF by default)
  44.  
  45. (function main() {
  46. 'use strict';
  47.  
  48. const log = (...args) => console.log(`${GM.info.script.name}:`, ...args);
  49. log('start');
  50.  
  51. const speedDelta = 0.25;
  52. const timeDelta = 10;
  53.  
  54. const addWithLimits = (a, b, min, max) => {
  55. if (a + b > max) return max;
  56. if (a + b < min) return min;
  57. return a + b;
  58. };
  59.  
  60. window.addEventListener('message', (e) => {
  61. if (e.data === 'pleasePauseVideo') {
  62. document.querySelectorAll('video').forEach((video) => video.pause());
  63. }
  64. });
  65.  
  66. document.addEventListener('keydown', (e) => {
  67. switch (e.keyCode) {
  68. case 187: // = speed+
  69. document.querySelectorAll('video').forEach((video) => {
  70. video.playbackRate = addWithLimits(video.playbackRate, speedDelta, 0, 16);
  71. log(`${video.playbackRate}x`);
  72. });
  73. break;
  74. case 189: // - speed-
  75. document.querySelectorAll('video').forEach((video) => {
  76. video.playbackRate = addWithLimits(video.playbackRate, -speedDelta, 0, 16);
  77. log(`${video.playbackRate}x`);
  78. });
  79. break;
  80. case 220: // \ speed reset
  81. document.querySelectorAll('video').forEach((video) => {
  82. video.playbackRate = 1;
  83. log(`${video.playbackRate}x`);
  84. });
  85. break;
  86. case 219: // [ rewind
  87. document.querySelectorAll('video').forEach((video) => {
  88. video.currentTime = addWithLimits(video.currentTime, -timeDelta, 0, video.duration);
  89. log(`rewind ${-timeDelta}s, currentTime: ${video.currentTime}s`);
  90. });
  91. break;
  92. case 221: // ] advance
  93. document.querySelectorAll('video').forEach((video) => {
  94. if (video.currentTime < video.duration) {
  95. video.currentTime = addWithLimits(video.currentTime, timeDelta, 0, video.duration);
  96. log(`advance ${timeDelta}s, currentTime: ${video.currentTime}s`);
  97. }
  98. });
  99. break;
  100. case 192: // ` toggle loop
  101. document.querySelectorAll('video').forEach((video) => {
  102. video.loop = !video.loop;
  103. log(`loop ${video.loop}`);
  104. });
  105. break;
  106. default:
  107. }
  108. }, { capture: true, passive: true });
  109. }());