html5 video speed controller (vlc like) modified by Sapioit

Simple html5 video speed control with 's', 'd', and 'r'. 's': decrease by 0.25, 'd': increase by 0.25, 'r': back to 1.0x

  1. // ==UserScript==
  2. // @name html5 video speed controller (vlc like) modified by Sapioit
  3. // @namespace github.com/sky-bro
  4. // @version 1.1.0.0
  5. // @description Simple html5 video speed control with 's', 'd', and 'r'. 's': decrease by 0.25, 'd': increase by 0.25, 'r': back to 1.0x
  6. // @author https://sky-bro.github.io https://sapioit.com
  7. // @match https://www.youtube.com/*
  8. // @match https://www.bilibili.com/*
  9. // @match *://*.zhihuishu.com/*
  10. // @license GPL-2.0-only; http://www.gnu.org/licenses/gpl-2.0.txt
  11. // @grant none
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16. function setPlaybackRate(player, rate) {
  17. if (rate < 0.1) rate = 0.1;
  18. else if (rate > 40) rate = 40;
  19. player.playbackRate = rate;
  20. console.log("playing in %sx", (rate).toFixed(1));
  21. }
  22.  
  23. window.addEventListener('keypress', function(event) {
  24. var player = document.querySelector("video");
  25. // console.log(event);
  26. var curRate = Number(player.playbackRate);
  27. // vlc actually uses '[' and ']', but they are used by vimium
  28. if (event.key == "s") {
  29. console.log("s pressed");
  30. setPlaybackRate(player, curRate - 0.25);
  31. } else if(event.key == "d") {
  32. console.log("d pressed");
  33. setPlaybackRate(player, curRate + 0.25);
  34. } else if(event.key == "r") {
  35. console.log("r pressed");
  36. setPlaybackRate(player, 1);
  37. }
  38. });
  39. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址