mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-10 05:27:03 +03:00
Added duration change listener check to prevent mid-video zero second skips.
Sometimes the video gets reset to zero seconds for a few milliseconds, this should not trigger a skip. Resolves https://github.com/ajayyy/SponsorBlock/issues/183
This commit is contained in:
@@ -37,6 +37,8 @@ var lastPreviewBarUpdate;
|
||||
|
||||
//whether the duration listener listening for the duration changes of the video has been setup yet
|
||||
var durationListenerSetUp = false;
|
||||
// Timestamp of the last duration change
|
||||
var lastDurationChange = 0;
|
||||
|
||||
//the channel this video is about
|
||||
var channelURL;
|
||||
@@ -403,8 +405,17 @@ function createPreviewBar(): void {
|
||||
}
|
||||
}
|
||||
|
||||
function sponsorsLookup(id: string, channelIDPromise?) {
|
||||
/**
|
||||
* Triggered every time the video duration changes.
|
||||
* This happens when the resolution changes or at random time to clear memory.
|
||||
*/
|
||||
function durationChangeListener() {
|
||||
lastDurationChange = Date.now();
|
||||
|
||||
updatePreviewBar();
|
||||
}
|
||||
|
||||
function sponsorsLookup(id: string, channelIDPromise?) {
|
||||
video = document.querySelector('video') // Youtube video player
|
||||
//there is no video here
|
||||
if (video == null) {
|
||||
@@ -416,7 +427,7 @@ function sponsorsLookup(id: string, channelIDPromise?) {
|
||||
durationListenerSetUp = true;
|
||||
|
||||
//wait until it is loaded
|
||||
video.addEventListener('durationchange', updatePreviewBar);
|
||||
video.addEventListener('durationchange', durationChangeListener);
|
||||
}
|
||||
|
||||
if (channelIDPromise !== undefined) {
|
||||
@@ -671,6 +682,9 @@ function sponsorCheck() {
|
||||
return;
|
||||
}
|
||||
|
||||
// Don't skip right after duration change (the time resets to zero) 400ms
|
||||
if (Date.now() - lastDurationChange < 400000 && lastTime > 1) return;
|
||||
|
||||
let skipHappened = false;
|
||||
|
||||
if (sponsorTimes != null) {
|
||||
|
||||
Reference in New Issue
Block a user