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. */
|
/** 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("Skipping intro");
|
||||||
introSkipper.d(introSkipper.skipSegments);
|
introSkipper.d(introSkipper.skipSegments);
|
||||||
const segment = introSkipper.getCurrentSegment(introSkipper.videoPlayer.currentTime);
|
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");
|
console.warn("[intro skipper] doSkip() called without an active segment");
|
||||||
return;
|
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
|
// Disable keydown events
|
||||||
introSkipper.allowEnter = false;
|
introSkipper.allowEnter = false;
|
||||||
introSkipper.videoPlayer.currentTime = segment.IntroEnd;
|
// Check if the segment is "Credits" and skipping would leave less than 3 seconds of video
|
||||||
// Listen for the seeked event to re-enable keydown events
|
if (segment.SegmentType === "Credits" && introSkipper.videoPlayer.duration - segment.IntroEnd < 3) {
|
||||||
const onSeeked = async () => {
|
// Simulate 'N' key press to go to the next episode
|
||||||
await new Promise(resolve => setTimeout(resolve, 50)); // Wait 50ms
|
document.dispatchEvent(new KeyboardEvent('keydown', { key: 'N', shiftKey: true, bubbles: true }));
|
||||||
introSkipper.allowEnter = true;
|
// Check if the next episode actually starts loading
|
||||||
introSkipper.videoPlayer.removeEventListener('seeked', onSeeked);
|
const nextEpisodeLoaded = await Promise.race([
|
||||||
};
|
new Promise(resolve => introSkipper.videoPlayer.addEventListener('loadstart', () => resolve(true), { once: true })),
|
||||||
introSkipper.videoPlayer.addEventListener('seeked', onSeeked);
|
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);
|
}, 3000);
|
||||||
/** Tests if an element with the provided selector exists. */
|
/** Tests if an element with the provided selector exists. */
|
||||||
introSkipper.testElement = function (selector) { return document.querySelector(selector); }
|
introSkipper.testElement = function (selector) { return document.querySelector(selector); }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user