Youtube playback rate shortcut

Press [ and ] to slow down/speed up the video, and shift+[ to reset the playback rate

当前为 2020-06-17 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Youtube playback rate shortcut
  3. // @namespace Violentmonkey Scripts
  4. // @match *://youtube.com/*
  5. // @match *://*.youtube.com/*
  6. // @grant none
  7. // @run-at document-idle
  8. // @version 1.0
  9. // @author qsniyg
  10. // @description Press [ and ] to slow down/speed up the video, and shift+[ to reset the playback rate
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. var playback_increment = 0.25;
  15.  
  16. var set_playback = function(diff) {
  17. var video_el = document.querySelector("video.video-stream.html5-main-video");
  18. if (video_el) {
  19. if (diff === 0)
  20. video_el.playbackRate = 1;
  21. else {
  22. var new_pr = video_el.playbackRate + diff * playback_increment;
  23. if (new_pr > 0)
  24. video_el.playbackRate = new_pr;
  25. }
  26. }
  27. }
  28.  
  29. document.addEventListener("keydown", function(e) {
  30. if (e.target && e.target.tagName === "INPUT" || e.target.tagName === "TEXTAREA")
  31. return;
  32. if (e.key === "[" && !e.shiftKey) {
  33. set_playback(-1);
  34. } else if (e.key === "]") {
  35. set_playback(1);
  36. } else if (e.shiftKey && (e.key === "[" || e.key === "{")) {
  37. set_playback(0);
  38. }
  39. });
  40. })();