HTML5 Video Playback Speed Control Keyboard Shortcut

Add keyboard shortcuts to decrease (CTRL+,), increase (CTRL+.), and reset (CTRL+;) HTML5 video playback rate. Available playback speeds are between 0.25 to 2.0 inclusive in 0.25 increments. Speed of 1.0 is used when resetting playback speed. Note: the video playback speed menu selection on YouTube will not be affected.

目前为 2017-09-12 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name HTML5 Video Playback Speed Control Keyboard Shortcut
  3. // @namespace HTML5VideoPlaybackSpeedControlKeyboardShortcut
  4. // @description Add keyboard shortcuts to decrease (CTRL+,), increase (CTRL+.), and reset (CTRL+;) HTML5 video playback rate. Available playback speeds are between 0.25 to 2.0 inclusive in 0.25 increments. Speed of 1.0 is used when resetting playback speed. Note: the video playback speed menu selection on YouTube will not be affected.
  5. // @version 1.0.2
  6. // @author jcunews
  7. // @include http://*/*
  8. // @include https://*/*
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. addEventListener("keydown", function(ev) {
  13. var ele = document.querySelector("VIDEO"), rate;
  14. if (ele && ev.ctrlKey) {
  15. rate = rate = ele.playbackRate;
  16. if ((ev.key === ",") || (ev.keyIdentifier === "U+00BC")) {
  17. rate -= 0.25;
  18. if (rate < 0.25) rate = 0.25;
  19. } else if ((ev.key === ".") || (ev.keyIdentifier === "U+00BE")) {
  20. rate += 0.25;
  21. if (rate > 2) rate = 2;
  22. } else if ((ev.key === ";") || (ev.keyIdentifier === "U+00BA")) {
  23. rate = 1;
  24. }
  25. rate = Math.trunc(rate * 4) / 4;
  26. ele.playbackRate = rate;
  27. }
  28. });