Speed up for Youtube

Press right key to speed up, NoStop

  1. // ==UserScript==
  2. // @name Speed up for Youtube
  3. // @description Press right key to speed up, NoStop
  4. // @version 1.05
  5. // @author Harry
  6. // @match https://*.youtube.com/*
  7. // @match https://*.zoom.us/*
  8. // @match https://*.ixigua.com/*
  9. // @match https://*.mgtv.com/*
  10. // @match https://v.qq.com/*
  11. // @match http://www.zjstv.com/*
  12. // @match http://*.cctv.com
  13. // @icon https://www.youtube.com/s/desktop/fc7b0168/img/favicon.ico
  14. // @connect googlevideo.com
  15. // @license MIT
  16. // @namespace https://gf.qytechs.cn/users/662979
  17. // ==/UserScript==
  18. (function () {
  19. 'use strict';
  20. let count = 0
  21. let page_video
  22. let speedupKey = 39
  23. let history_rate = 1
  24. const tryPageVideo = () => Array.prototype.find.call(document.getElementsByTagName('video'), e => e.currentTime > 0.1)
  25. const getPageVideo = () => {
  26. return new Promise(resolve => {
  27. const timer = setInterval(() => {
  28. const page_video = tryPageVideo()
  29. console.log(page_video.playbackRate);
  30. if (page_video) {
  31. clearInterval(timer)
  32. resolve(page_video)
  33. }
  34. }, 500);
  35. })
  36. };
  37.  
  38. const checkPageVideo = async () => {
  39. if (page_video.currentTime <= 0) {
  40. page_video = await getPageVideo()
  41. if (page_video.currentTime <= 0) {
  42. return false
  43. }
  44. }
  45.  
  46. return true
  47. }
  48.  
  49. const relativeEvent = {
  50. _stopper: e => e.stopPropagation(),
  51. }
  52.  
  53. const downEvent_right = async e => {
  54. if (e.keyCode !== speedupKey) return
  55. e.stopPropagation()
  56. count++
  57.  
  58. if (count === 2 && await checkPageVideo()) {
  59. relativeEvent.shouldPrevent && relativeEvent.prevent()
  60. history_rate = page_video.playbackRate
  61. page_video.playbackRate = 3
  62. console.log(page_video.playbackRate)
  63. console.log('speed up for 3x times')
  64. }
  65. }
  66. const upEvent_right = async e => {
  67. if (e.keyCode !== speedupKey) return
  68. e.stopPropagation()
  69.  
  70. if (count >= 2 && page_video.playbackRate > 1) {
  71. page_video.playbackRate = history_rate
  72. console.log('cancel speed up')
  73. relativeEvent.shouldPrevent && relativeEvent.allow()
  74. }else{
  75. page_video.currentTime += 5
  76. }
  77.  
  78. count = 0
  79. }
  80. const init = async () => {
  81. page_video = await getPageVideo()
  82. document.body.addEventListener('keydown', downEvent_right, true)
  83. document.body.parentElement.addEventListener('keyup', upEvent_right, true)
  84. }
  85.  
  86. init()
  87. Object.defineProperties(document, { 'hidden': {value: false}, 'webkitHidden': {value: false}, 'visibilityState': {value: 'visible'}, 'webkitVisibilityState': {value: 'visible'} });
  88. setInterval(function(){
  89. document.dispatchEvent( new KeyboardEvent( 'keyup', { bubbles: true, cancelable: true, keyCode: 143, which: 143 } ) );
  90. }, 60000);
  91. })();

QingJ © 2025

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