diff options
author | Ajay Ramachandran <[email protected]> | 2020-02-18 18:43:45 -0500 |
---|---|---|
committer | Ajay Ramachandran <[email protected]> | 2020-02-18 18:43:45 -0500 |
commit | b681f5abd976306b08d312d70fb9c3057e39573f (patch) | |
tree | 70a783930e81213122b7a16036c543ed6c539e78 | |
parent | 5b2a0feccff7299ea5cc3dfd54ddc2c60fa72ce9 (diff) | |
download | SponsorBlock-b681f5abd976306b08d312d70fb9c3057e39573f.tar.gz SponsorBlock-b681f5abd976306b08d312d70fb9c3057e39573f.zip |
Added support for preview sponsors in new skipping method.
-rw-r--r-- | src/content.ts | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/src/content.ts b/src/content.ts index e13bd07c..8d06bb66 100644 --- a/src/content.ts +++ b/src/content.ts @@ -435,7 +435,7 @@ function cancelSponsorSchedule(): void { function startSponsorSchedule(currentTime?: number): void { cancelSponsorSchedule(); - if (Config.config.disableSkipping) return; + if (Config.config.disableSkipping || sponsorTimes === null) return; if (currentTime === undefined) currentTime = video.currentTime; @@ -737,13 +737,24 @@ function getNextSkipIndex(currentTime: number): {array: number[][], index: numbe let minSponsorTimeIndex = sponsorStartTimes.indexOf(Math.min(...sponsorStartTimesAfterCurrentTime)); - // TOOD: support preview sponsors + let previewSponsorStartTimes = getStartTimes(sponsorTimesSubmitting); + let previewSponsorStartTimesAfterCurrentTime = getStartTimes(sponsorTimesSubmitting, currentTime, false); - return { - array: sponsorTimes, - index: minSponsorTimeIndex, - openNotice: true - }; + let minPreviewSponsorTimeIndex = previewSponsorStartTimes.indexOf(Math.min(...previewSponsorStartTimesAfterCurrentTime)); + + if (minPreviewSponsorTimeIndex == -1 || sponsorStartTimes[minSponsorTimeIndex] < previewSponsorStartTimes[minPreviewSponsorTimeIndex]) { + return { + array: sponsorTimes, + index: minSponsorTimeIndex, + openNotice: true + }; + } else { + return { + array: sponsorTimesSubmitting, + index: minPreviewSponsorTimeIndex, + openNotice: false + }; + } } /** |