mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-11 05:57:07 +03:00
Slightly improve firefox skipping
This commit is contained in:
@@ -671,10 +671,11 @@ async function startSponsorSchedule(includeIntersectingSegments = false, current
|
|||||||
skippingFunction(currentTime);
|
skippingFunction(currentTime);
|
||||||
} else {
|
} else {
|
||||||
let delayTime = timeUntilSponsor * 1000 * (1 / getVideo().playbackRate);
|
let delayTime = timeUntilSponsor * 1000 * (1 / getVideo().playbackRate);
|
||||||
if (delayTime < 300) {
|
if (delayTime < (isFirefoxOrSafari() && !isSafari() ? 750 : 300)) {
|
||||||
let forceStartIntervalTime: number | null = null;
|
let forceStartIntervalTime: number | null = null;
|
||||||
if (isFirefoxOrSafari() && !isSafari() && delayTime > 100) {
|
if (isFirefoxOrSafari() && !isSafari() && delayTime > 300) {
|
||||||
forceStartIntervalTime = await waitForNextTimeChange();
|
forceStartIntervalTime = await waitForNextTimeChange();
|
||||||
|
console.log("start", forceStartIntervalTime, performance.now())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use interval instead of timeout near the end to combat imprecise video time
|
// Use interval instead of timeout near the end to combat imprecise video time
|
||||||
@@ -708,11 +709,11 @@ async function startSponsorSchedule(includeIntersectingSegments = false, current
|
|||||||
|
|
||||||
skippingFunction(Math.max(getVideo().currentTime, startVideoTime + getVideo().playbackRate * Math.max(delayTime, intervalDuration) / 1000));
|
skippingFunction(Math.max(getVideo().currentTime, startVideoTime + getVideo().playbackRate * Math.max(delayTime, intervalDuration) / 1000));
|
||||||
}
|
}
|
||||||
}, 1);
|
}, 0);
|
||||||
} else {
|
} else {
|
||||||
logDebug(`Starting timeout to skip ${getVideo().currentTime} to skip at ${skipTime[0]}`);
|
logDebug(`Starting timeout to skip ${getVideo().currentTime} to skip at ${skipTime[0]}`);
|
||||||
|
|
||||||
const offset = (isFirefoxOrSafari() && !isSafari() ? 300 : 150);
|
const offset = (isFirefoxOrSafari() && !isSafari() ? 600 : 150);
|
||||||
// Schedule for right before to be more precise than normal timeout
|
// Schedule for right before to be more precise than normal timeout
|
||||||
currentSkipSchedule = setTimeout(skippingFunction, Math.max(0, delayTime - offset));
|
currentSkipSchedule = setTimeout(skippingFunction, Math.max(0, delayTime - offset));
|
||||||
}
|
}
|
||||||
@@ -724,23 +725,8 @@ async function startSponsorSchedule(includeIntersectingSegments = false, current
|
|||||||
* the video time has changed
|
* the video time has changed
|
||||||
*/
|
*/
|
||||||
function waitForNextTimeChange(): Promise<DOMHighResTimeStamp | null> {
|
function waitForNextTimeChange(): Promise<DOMHighResTimeStamp | null> {
|
||||||
const startVideoTime = getVideo().currentTime;
|
|
||||||
let tries = 0;
|
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
const callback = (timestamp: DOMHighResTimeStamp) => {
|
getVideo().addEventListener("timeupdate", () => resolve(performance.now()), { once: true });
|
||||||
tries++;
|
|
||||||
if (startVideoTime !== getVideo().currentTime) {
|
|
||||||
resolve(timestamp);
|
|
||||||
return;
|
|
||||||
} else if (tries > 4) {
|
|
||||||
// Give up
|
|
||||||
resolve(null);
|
|
||||||
} else {
|
|
||||||
requestAnimationFrame(callback);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
requestAnimationFrame(callback);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user