aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAjay Ramachandran <[email protected]>2020-02-18 18:43:45 -0500
committerAjay Ramachandran <[email protected]>2020-02-18 18:43:45 -0500
commitb681f5abd976306b08d312d70fb9c3057e39573f (patch)
tree70a783930e81213122b7a16036c543ed6c539e78
parent5b2a0feccff7299ea5cc3dfd54ddc2c60fa72ce9 (diff)
downloadSponsorBlock-b681f5abd976306b08d312d70fb9c3057e39573f.tar.gz
SponsorBlock-b681f5abd976306b08d312d70fb9c3057e39573f.zip
Added support for preview sponsors in new skipping method.
-rw-r--r--src/content.ts25
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
+ };
+ }
}
/**