auto-next-episode

auto play next episode

当前为 2023-06-05 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name auto-next-episode
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.0.3
  5. // @description auto play next episode
  6. // @author zqcccc
  7. // @match https://ddys.art/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=ddys.art
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. var videoElement = getVideoElement()
  17.  
  18. function getVideoElement() {
  19. return document.querySelector('video')
  20. }
  21. function getPlayBtn() {
  22. return document.querySelector('button[title="Resume"]') || document.querySelector('button[title="播放视频"]')
  23. }
  24. function videoEndHandle() {
  25. var nextEpisodeBtn = document.querySelector('button[title="下一集"]')
  26. nextEpisodeBtn.click()
  27. this.removeEventListener('ended', videoEndHandle)
  28. var checkTimer = setInterval(()=>{
  29. var playBtn = getPlayBtn()
  30. if (playBtn) {
  31. playBtn.click()
  32. clearInterval(checkTimer)
  33. var newVideoElement = getVideoElement()
  34. newVideoElement.addEventListener('ended', videoEndHandle)
  35. setTimeout(()=>checkIfVideoPlaying(newVideoElement), 2000)
  36. }
  37. }
  38. , 1000)
  39. }
  40.  
  41. function checkIfVideoPlaying(videoElement, hasCheckedTimes=0) {
  42. if (hasCheckedTimes > 10) {
  43. window.location.reload()
  44. } else if (videoElement.paused) {
  45. const btn = getPlayBtn()
  46. btn?.click()
  47. setTimeout(()=>checkIfVideoPlaying(videoElement, hasCheckedTimes + 1), 2000)
  48. }
  49. }
  50.  
  51. videoElement.addEventListener('ended', videoEndHandle)
  52.  
  53. checkIfVideoPlaying(videoElement)
  54.  
  55. })();