Start the next episode directly (#205)
This commit is contained in:
parent
805405e00a
commit
c7ed471d54
@ -237,7 +237,7 @@ introSkipper.throttle = function (func, limit) {
|
||||
};
|
||||
}
|
||||
/** Seeks to the end of the intro. */
|
||||
introSkipper.doSkip = introSkipper.throttle(function (e) {
|
||||
introSkipper.doSkip = introSkipper.throttle(async function () {
|
||||
introSkipper.d("Skipping intro");
|
||||
introSkipper.d(introSkipper.skipSegments);
|
||||
const segment = introSkipper.getCurrentSegment(introSkipper.videoPlayer.currentTime);
|
||||
@ -245,16 +245,34 @@ introSkipper.doSkip = introSkipper.throttle(function (e) {
|
||||
console.warn("[intro skipper] doSkip() called without an active segment");
|
||||
return;
|
||||
}
|
||||
const seekToSegmentEnd = () => new Promise((resolve) => {
|
||||
const onSeeked = () => {
|
||||
setTimeout(() => {
|
||||
introSkipper.allowEnter = true;
|
||||
resolve();
|
||||
}, 50); // Wait 50ms after seek completes
|
||||
};
|
||||
introSkipper.videoPlayer.addEventListener('seeked', onSeeked, { once: true });
|
||||
introSkipper.videoPlayer.currentTime = segment.IntroEnd;
|
||||
});
|
||||
// Disable keydown events
|
||||
introSkipper.allowEnter = false;
|
||||
introSkipper.videoPlayer.currentTime = segment.IntroEnd;
|
||||
// Listen for the seeked event to re-enable keydown events
|
||||
const onSeeked = async () => {
|
||||
await new Promise(resolve => setTimeout(resolve, 50)); // Wait 50ms
|
||||
introSkipper.allowEnter = true;
|
||||
introSkipper.videoPlayer.removeEventListener('seeked', onSeeked);
|
||||
};
|
||||
introSkipper.videoPlayer.addEventListener('seeked', onSeeked);
|
||||
// Check if the segment is "Credits" and skipping would leave less than 3 seconds of video
|
||||
if (segment.SegmentType === "Credits" && introSkipper.videoPlayer.duration - segment.IntroEnd < 3) {
|
||||
// Simulate 'N' key press to go to the next episode
|
||||
document.dispatchEvent(new KeyboardEvent('keydown', { key: 'N', shiftKey: true, bubbles: true }));
|
||||
// Check if the next episode actually starts loading
|
||||
const nextEpisodeLoaded = await Promise.race([
|
||||
new Promise(resolve => introSkipper.videoPlayer.addEventListener('loadstart', () => resolve(true), { once: true })),
|
||||
new Promise(resolve => setTimeout(() => resolve(false), 100))
|
||||
]);
|
||||
// If the next episode didn't load, just seek to the end of the current segment
|
||||
if (!nextEpisodeLoaded) await seekToSegmentEnd();
|
||||
else introSkipper.allowEnter = true;
|
||||
return;
|
||||
}
|
||||
// Default behavior: seek to the end of the current segment
|
||||
await seekToSegmentEnd();
|
||||
}, 3000);
|
||||
/** Tests if an element with the provided selector exists. */
|
||||
introSkipper.testElement = function (selector) { return document.querySelector(selector); }
|
||||
|
Loading…
x
Reference in New Issue
Block a user