mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2024-09-20 13:03:45 +02:00
Use virtual time for determining whether to skip and increase skip buffer
Potentially fix recent issue with skips not triggering
This commit is contained in:
parent
eda7aac5ef
commit
5289e62d43
1 changed files with 15 additions and 10 deletions
|
@ -480,14 +480,7 @@ function startSponsorSchedule(includeIntersectingSegments = false, currentTime?:
|
|||
|
||||
if (!video || video.paused) return;
|
||||
if (currentTime === undefined || currentTime === null) {
|
||||
const virtualTime = lastTimeFromWaitingEvent ?? (lastKnownVideoTime.videoTime ?
|
||||
(performance.now() - lastKnownVideoTime.preciseTime) / 1000 + lastKnownVideoTime.videoTime : null);
|
||||
if ((lastTimeFromWaitingEvent || !utils.isFirefox())
|
||||
&& !isSafari() && virtualTime && Math.abs(virtualTime - video.currentTime) < 0.6){
|
||||
currentTime = virtualTime;
|
||||
} else {
|
||||
currentTime = video.currentTime;
|
||||
}
|
||||
currentTime = getVirtualTime();
|
||||
}
|
||||
lastTimeFromWaitingEvent = null;
|
||||
|
||||
|
@ -541,7 +534,7 @@ function startSponsorSchedule(includeIntersectingSegments = false, currentTime?:
|
|||
let forcedIncludeNonIntersectingSegments = true;
|
||||
|
||||
if (incorrectVideoCheck(videoID, currentSkip)) return;
|
||||
forceVideoTime ||= video.currentTime;
|
||||
forceVideoTime ||= Math.max(video.currentTime, getVirtualTime());
|
||||
|
||||
if (forceVideoTime >= skipTime[0] && forceVideoTime < skipTime[1]) {
|
||||
skipToTime({
|
||||
|
@ -591,11 +584,23 @@ function startSponsorSchedule(includeIntersectingSegments = false, currentTime?:
|
|||
logDebug(`Starting timeout to skip ${video.currentTime} to skip at ${skipTime[0]}`);
|
||||
|
||||
// Schedule for right before to be more precise than normal timeout
|
||||
currentSkipSchedule = setTimeout(skippingFunction, Math.max(0, delayTime - 100));
|
||||
currentSkipSchedule = setTimeout(skippingFunction, Math.max(0, delayTime - 150));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getVirtualTime(): number {
|
||||
const virtualTime = lastTimeFromWaitingEvent ?? (lastKnownVideoTime.videoTime ?
|
||||
(performance.now() - lastKnownVideoTime.preciseTime) / 1000 + lastKnownVideoTime.videoTime : null);
|
||||
|
||||
if ((lastTimeFromWaitingEvent || !utils.isFirefox())
|
||||
&& !isSafari() && virtualTime && Math.abs(virtualTime - video.currentTime) < 0.6) {
|
||||
return virtualTime;
|
||||
} else {
|
||||
return video.currentTime;
|
||||
}
|
||||
}
|
||||
|
||||
function inMuteSegment(currentTime: number): boolean {
|
||||
const checkFunction = (segment) => segment.actionType === ActionType.Mute && segment.segment[0] <= currentTime && segment.segment[1] > currentTime;
|
||||
return sponsorTimes?.some(checkFunction) || sponsorTimesSubmitting.some(checkFunction);
|
||||
|
|
Loading…
Reference in a new issue