diff options
author | Ajay <[email protected]> | 2022-10-12 23:46:00 -0400 |
---|---|---|
committer | Ajay <[email protected]> | 2022-10-12 23:46:00 -0400 |
commit | 56be762686d6c89fc357527f76f445f49103f7ce (patch) | |
tree | 5fb78cb2112e113bece90c78e866151633854790 | |
parent | 758b6f18dbdd003680be7a3dfd0957dc733c0c97 (diff) | |
download | SponsorBlock-56be762686d6c89fc357527f76f445f49103f7ce.tar.gz SponsorBlock-56be762686d6c89fc357527f76f445f49103f7ce.zip |
Add back virtual time to firefox and fix it with playback speed
-rw-r--r-- | src/content.ts | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/src/content.ts b/src/content.ts index 2c65e4d6..b2ab889a 100644 --- a/src/content.ts +++ b/src/content.ts @@ -712,10 +712,9 @@ function startSponsorSchedule(includeIntersectingSegments = false, currentTime?: function getVirtualTime(): number { const virtualTime = lastTimeFromWaitingEvent ?? (lastKnownVideoTime.videoTime ? - (performance.now() - lastKnownVideoTime.preciseTime) / 1000 + lastKnownVideoTime.videoTime : null); + (performance.now() - lastKnownVideoTime.preciseTime) * video.playbackRate / 1000 + lastKnownVideoTime.videoTime : null); - if ((lastTimeFromWaitingEvent || !utils.isFirefox()) - && !isSafari() && virtualTime && Math.abs(virtualTime - video.currentTime) < 0.6 && video.currentTime !== 0) { + if (!isSafari() && virtualTime && Math.abs(virtualTime - video.currentTime) < 0.6 && video.currentTime !== 0) { return virtualTime; } else { return video.currentTime; @@ -877,9 +876,19 @@ function setupVideoListeners() { } } }); - video.addEventListener('ratechange', () => startSponsorSchedule()); + video.addEventListener('ratechange', () => { + updateVirtualTime(); + lastTimeFromWaitingEvent = null; + + startSponsorSchedule(); + }); // Used by videospeed extension (https://github.com/igrigorik/videospeed/pull/740) - video.addEventListener('videoSpeed_ratechange', () => startSponsorSchedule()); + video.addEventListener('videoSpeed_ratechange', () => { + updateVirtualTime(); + lastTimeFromWaitingEvent = null; + + startSponsorSchedule(); + }); const paused = () => { // Reset lastCheckVideoTime lastCheckVideoTime = -1; |