Skip to content

Commit

Permalink
Fix rate change listener not set up properly
Browse files Browse the repository at this point in the history
Fixes #1820
  • Loading branch information
ajayyy committed Aug 22, 2023
1 parent 64ece9c commit 9a18e70
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,16 @@ function setupVideoListeners() {
let startedWaiting = false;
let lastPausedAtZero = true;

const rateChangeListener = () => {
updateVirtualTime();
clearWaitingTime();

startSponsorSchedule();
};
getVideo().addEventListener('ratechange', rateChangeListener);
// Used by videospeed extension (https://github.com/igrigorik/videospeed/pull/740)
getVideo().addEventListener('videoSpeed_ratechange', rateChangeListener);

const playListener = () => {
// If it is not the first event, then the only way to get to 0 is if there is a seek event
// This check makes sure that changing the video resolution doesn't cause the extension to think it
Expand Down Expand Up @@ -868,7 +878,6 @@ function setupVideoListeners() {

startSponsorSchedule();
}

};
getVideo().addEventListener('play', playListener);

Expand Down Expand Up @@ -928,16 +937,6 @@ function setupVideoListeners() {
};
getVideo().addEventListener('seeking', seekingListener);

const rateChangeListener = () => {
updateVirtualTime();
clearWaitingTime();

startSponsorSchedule();
};
getVideo().addEventListener('ratechange', () => rateChangeListener);
// Used by videospeed extension (https://github.com/igrigorik/videospeed/pull/740)
getVideo().addEventListener('videoSpeed_ratechange', rateChangeListener);

const stoppedPlayback = () => {
// Reset lastCheckVideoTime
lastCheckVideoTime = -1;
Expand Down

0 comments on commit 9a18e70

Please sign in to comment.