百度云盘视频连续播放减少等待(已修复 2021.5)

通过预加载减少等待时间,自动连续播放,考研党的福音

  1. // ==UserScript==
  2. // @name 百度云盘视频连续播放减少等待(已修复 2021.5)
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.3
  5. // @description 通过预加载减少等待时间,自动连续播放,考研党的福音
  6. // @author kakasearch
  7. // @match https://pan.baidu.com/play/video
  8. // @icon https://www.google.com/s2/favicons?domain=baidu.com
  9. // @grant GM_openInTab
  10. // @grant GM_getTab
  11. // @grant GM_saveTab
  12. // @grant unsafeWindow
  13. // @grant GM_getValue
  14. // @grant GM_setValue
  15. // @grant window.focus
  16.  
  17. // ==/UserScript==
  18. //消除interval
  19. (function() {
  20. 'use strict';
  21. let window=unsafeWindow
  22. let getVideo = function(){
  23. //下次百度云更新,直接改這裏
  24. return window.videoPlayer.getPlayers().html5player
  25. }
  26. let main = ()=>{
  27.  
  28. //abort open next url in background tab
  29.  
  30. if(GM_getValue('next')== window.location.href){
  31. GM_setValue('next','')
  32. let play = setInterval(function(){
  33. try{
  34. let werbung = document.querySelector("#video-root").shadowRoot.querySelector("#werbung-info-container > div.werbung-progress-bar-wrapper > div.werbung-progress-text")
  35. if(getVideo()&&werbung&&Number(/\d+/.exec(werbung.innerText)[0])>=99){
  36. //load done
  37. clearInterval(play)
  38. let canPlay = GM_getValue('pan_play')
  39. if(! canPlay){
  40. getVideo().on('play', getVideo().pause())
  41. let pause =setInterval(()=>{
  42. if(! getVideo().paused()){
  43. getVideo().el_.onload = ()=>{console.log('load')}
  44. console.log('pause')
  45. getVideo().pause()
  46. getVideo().on('play', getVideo().pause())
  47. }
  48. },1000)
  49. setTimeout(()=>{clearInterval(pause)},10000)
  50. window.addEventListener('keydown',clearInterval(pause))
  51. window.addEventListener('click',clearInterval(pause))
  52. }
  53. //wait closed
  54. let play_listener = setInterval(()=>{
  55. canPlay = GM_getValue('pan_play')
  56. if(canPlay){
  57. if(GM_getValue('first') == window.location.href){
  58. window.focus()}
  59. if(getVideo().paused()){
  60. console.log('play')
  61. getVideo().play()
  62. }else{
  63. GM_setValue('pan_play',false)
  64. clearInterval(play_listener)
  65. main()
  66. }
  67. }
  68. },1000)
  69.  
  70. }
  71. }catch{
  72. // click retry button
  73. let retry = setInterval(function(){
  74. if(document.querySelector("#video-wrap > div > span > a")){
  75. document.querySelector("#video-wrap > div > span > a").click()
  76. }
  77. },1000)
  78. setTimeout(()=>{clearInterval(retry)},10000)
  79. }
  80.  
  81. // if('重试'in ''){}///////////////////////////////
  82. },1000)
  83.  
  84. }else{
  85. // open nexturl in background
  86. let url =window.location.href.split('%2')
  87. let next_name = document.querySelector(".video-item.currentplay").nextElementSibling.children[0].children[1].innerText
  88. url =url.slice(0,url.length-1)
  89. url.push('F'+encodeURI(next_name) + '&t=-1')
  90. let next_url =url.join('%2')
  91. GM_setValue('pan_play',false)
  92. GM_setValue('next',next_url)
  93. GM_setValue('first',next_url)
  94. setTimeout(GM_openInTab(next_url,true),1000)
  95.  
  96. //close tab when video end
  97. let tiao= 1
  98. let tmp = setInterval(function(){
  99. if(getVideo()){
  100.  
  101. let player = getVideo()
  102. let duration = player.el_.firstElementChild.duration
  103. let currentTime=player.el_.firstElementChild.currentTime
  104. if(currentTime >(duration-2) && tiao){
  105. GM_setValue('pan_play',true)
  106. if(getVideo()){
  107. getVideo().pause()
  108. }
  109. clearInterval(tmp)
  110. window.close()
  111. tiao= 0
  112. }
  113. }else{tiao=1}
  114. },1000)
  115. }
  116.  
  117.  
  118.  
  119. }
  120.  
  121. setTimeout(function(){
  122. main()
  123. },3000)
  124.  
  125.  
  126. // Your code here...
  127. })();