mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-10 13:37:04 +03:00
Fix cases with multiple segments starting at the exact same time
This commit is contained in:
@@ -569,6 +569,18 @@ function startSponsorSchedule(includeIntersectingSegments = false, currentTime?:
|
|||||||
openNotice: skipInfo.openNotice
|
openNotice: skipInfo.openNotice
|
||||||
});
|
});
|
||||||
|
|
||||||
|
for (const extra of skipInfo.extraIndexes) {
|
||||||
|
const extraSkip = skipInfo.array[extra];
|
||||||
|
if (shouldSkip(extraSkip)) {
|
||||||
|
skipToTime({
|
||||||
|
v: video,
|
||||||
|
skipTime: [extraSkip.scheduledTime, extraSkip.segment[1]],
|
||||||
|
skippingSegments: [extraSkip],
|
||||||
|
openNotice: skipInfo.openNotice
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (utils.getCategorySelection(currentSkip.category)?.option === CategorySkipOption.ManualSkip
|
if (utils.getCategorySelection(currentSkip.category)?.option === CategorySkipOption.ManualSkip
|
||||||
|| currentSkip.actionType === ActionType.Mute) {
|
|| currentSkip.actionType === ActionType.Mute) {
|
||||||
forcedSkipTime = skipTime[0] + 0.001;
|
forcedSkipTime = skipTime[0] + 0.001;
|
||||||
@@ -1192,13 +1204,30 @@ async function whitelistCheck() {
|
|||||||
* Returns info about the next upcoming sponsor skip
|
* Returns info about the next upcoming sponsor skip
|
||||||
*/
|
*/
|
||||||
function getNextSkipIndex(currentTime: number, includeIntersectingSegments: boolean, includeNonIntersectingSegments: boolean):
|
function getNextSkipIndex(currentTime: number, includeIntersectingSegments: boolean, includeNonIntersectingSegments: boolean):
|
||||||
{array: ScheduledTime[], index: number, endIndex: number, openNotice: boolean} {
|
{array: ScheduledTime[], index: number, endIndex: number, extraIndexes: number[], openNotice: boolean} {
|
||||||
|
|
||||||
|
const autoSkipSorter = (segment: ScheduledTime) => {
|
||||||
|
const skipOption = utils.getCategorySelection(segment.category)?.option;
|
||||||
|
if (skipOption === CategorySkipOption.AutoSkip
|
||||||
|
&& segment.actionType === ActionType.Skip) {
|
||||||
|
return 0;
|
||||||
|
} else if (skipOption !== CategorySkipOption.ShowOverlay) {
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const { includedTimes: submittedArray, scheduledTimes: sponsorStartTimes } =
|
const { includedTimes: submittedArray, scheduledTimes: sponsorStartTimes } =
|
||||||
getStartTimes(sponsorTimes, includeIntersectingSegments, includeNonIntersectingSegments);
|
getStartTimes(sponsorTimes, includeIntersectingSegments, includeNonIntersectingSegments);
|
||||||
const { scheduledTimes: sponsorStartTimesAfterCurrentTime } = getStartTimes(sponsorTimes, includeIntersectingSegments, includeNonIntersectingSegments, currentTime, true, true);
|
const { scheduledTimes: sponsorStartTimesAfterCurrentTime } = getStartTimes(sponsorTimes, includeIntersectingSegments, includeNonIntersectingSegments, currentTime, true, true);
|
||||||
|
|
||||||
const minSponsorTimeIndex = sponsorStartTimes.indexOf(Math.min(...sponsorStartTimesAfterCurrentTime));
|
const minSponsorTimeIndexes = GenericUtils.indexesOf(sponsorStartTimes, Math.min(...sponsorStartTimesAfterCurrentTime));
|
||||||
|
const minSponsorTimeIndex = minSponsorTimeIndexes.sort(
|
||||||
|
(a, b) => ((autoSkipSorter(submittedArray[a]) - autoSkipSorter(submittedArray[b]))
|
||||||
|
|| (submittedArray[a].segment[1] - submittedArray[a].segment[0]) - (submittedArray[b].segment[1] - submittedArray[b].segment[0])))[0] ?? -1;
|
||||||
|
const extraIndexes = minSponsorTimeIndexes.filter((i) => i === minSponsorTimeIndex || autoSkipSorter(submittedArray[i]) !== 0);
|
||||||
|
|
||||||
const endTimeIndex = getLatestEndTimeIndex(submittedArray, minSponsorTimeIndex);
|
const endTimeIndex = getLatestEndTimeIndex(submittedArray, minSponsorTimeIndex);
|
||||||
|
|
||||||
const { includedTimes: unsubmittedArray, scheduledTimes: unsubmittedSponsorStartTimes } =
|
const { includedTimes: unsubmittedArray, scheduledTimes: unsubmittedSponsorStartTimes } =
|
||||||
@@ -1214,6 +1243,7 @@ function getNextSkipIndex(currentTime: number, includeIntersectingSegments: bool
|
|||||||
array: submittedArray,
|
array: submittedArray,
|
||||||
index: minSponsorTimeIndex,
|
index: minSponsorTimeIndex,
|
||||||
endIndex: endTimeIndex,
|
endIndex: endTimeIndex,
|
||||||
|
extraIndexes, // Segments at same time that need seperate notices
|
||||||
openNotice: true
|
openNotice: true
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
@@ -1221,6 +1251,7 @@ function getNextSkipIndex(currentTime: number, includeIntersectingSegments: bool
|
|||||||
array: unsubmittedArray,
|
array: unsubmittedArray,
|
||||||
index: minUnsubmittedSponsorTimeIndex,
|
index: minUnsubmittedSponsorTimeIndex,
|
||||||
endIndex: previewEndTimeIndex,
|
endIndex: previewEndTimeIndex,
|
||||||
|
extraIndexes: [], // No manual things for unsubmitted
|
||||||
openNotice: false
|
openNotice: false
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,8 +64,17 @@ function hexToRgb(hex: string): {r: number, g: number, b: number} {
|
|||||||
} : null;
|
} : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List of all indexes that have the specified value
|
||||||
|
* https://stackoverflow.com/a/54954694/1985387
|
||||||
|
*/
|
||||||
|
function indexesOf<T>(array: T[], value: T): number[] {
|
||||||
|
return array.map((v, i) => v === value ? i : -1).filter(i => i !== -1);
|
||||||
|
}
|
||||||
|
|
||||||
export const GenericUtils = {
|
export const GenericUtils = {
|
||||||
wait,
|
wait,
|
||||||
getErrorMessage,
|
getErrorMessage,
|
||||||
getLuminance
|
getLuminance,
|
||||||
|
indexesOf
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user