diff options
author | Ajay <[email protected]> | 2023-08-22 15:23:04 -0400 |
---|---|---|
committer | Ajay <[email protected]> | 2023-08-22 15:23:04 -0400 |
commit | b3efa1f787a7e160704bf8d044e1beaac3b873f7 (patch) | |
tree | 8a36dce2f489e431499a669e6522497e776e80ef | |
parent | 9a18e70e34ea067ca15b6f776d39ae61bafab323 (diff) | |
download | SponsorBlock-b3efa1f787a7e160704bf8d044e1beaac3b873f7.tar.gz SponsorBlock-b3efa1f787a7e160704bf8d044e1beaac3b873f7.zip |
Add compatibility with video speed controller extension
-rw-r--r-- | src/content.ts | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/content.ts b/src/content.ts index 46eeda10..460aaa0f 100644 --- a/src/content.ts +++ b/src/content.ts @@ -819,6 +819,8 @@ function incorrectVideoCheck(videoID?: string, sponsorTime?: SponsorTime): boole } } +let playbackRateCheckInterval: NodeJS.Timeout | null = null; +let lastPlaybackSpeed = 1; let setupVideoListenersFirstTime = true; function setupVideoListeners() { //wait until it is loaded @@ -907,6 +909,27 @@ function setupVideoListeners() { startSponsorSchedule(); } + + if (playbackRateCheckInterval) clearInterval(playbackRateCheckInterval); + lastPlaybackSpeed = getVideo().playbackRate; + + // Video speed controller compatibility + // That extension makes rate change events not propagate + if (document.body.classList.contains("vsc-initialized")) { + playbackRateCheckInterval = setInterval(() => { + if ((!getVideoID() || getVideo().paused) && playbackRateCheckInterval) { + // Video is gone, stop checking + clearInterval(playbackRateCheckInterval); + return; + } + + if (getVideo().playbackRate !== lastPlaybackSpeed) { + lastPlaybackSpeed = getVideo().playbackRate; + + rateChangeListener(); + } + }, 2000); + } }; getVideo().addEventListener('playing', playingListener); @@ -942,6 +965,8 @@ function setupVideoListeners() { lastCheckVideoTime = -1; lastCheckTime = 0; + if (playbackRateCheckInterval) clearInterval(playbackRateCheckInterval); + lastKnownVideoTime.videoTime = null; lastKnownVideoTime.preciseTime = null; updateWaitingTime(); @@ -973,6 +998,8 @@ function setupVideoListeners() { getVideo().removeEventListener('videoSpeed_ratechange', rateChangeListener); getVideo().removeEventListener('pause', pauseListener); getVideo().removeEventListener('waiting', waitingListener); + + if (playbackRateCheckInterval) clearInterval(playbackRateCheckInterval); }); } } |