mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-15 07:57:09 +03:00
Add advanced skip options
This commit is contained in:
@@ -51,7 +51,7 @@ import { asyncRequestToServer } from "./utils/requests";
|
||||
import { isMobileControlsOpen } from "./utils/mobileUtils";
|
||||
import { defaultPreviewTime } from "./utils/constants";
|
||||
import { onVideoPage } from "../maze-utils/src/pageInfo";
|
||||
import { getSegmentsForVideo } from "./utils/segmentData";
|
||||
import { getCategoryDefaultSelection, getCategorySelection, getSegmentsForVideo } from "./utils/segmentData";
|
||||
|
||||
cleanPage();
|
||||
|
||||
@@ -299,7 +299,6 @@ function messageListener(request: Message, sender: unknown, sendResponse: (respo
|
||||
break;
|
||||
}
|
||||
loopedChapter = {...utils.getSponsorTimeFromUUID(sponsorTimes, request.UUID)};
|
||||
loopedChapter.actionType = ActionType.Skip;
|
||||
loopedChapter.segment = [loopedChapter.segment[1], loopedChapter.segment[0]];
|
||||
break;
|
||||
case "importSegments": {
|
||||
@@ -312,7 +311,7 @@ function messageListener(request: Message, sender: unknown, sendResponse: (respo
|
||||
&& s.description === segment.description)) {
|
||||
const hasChaptersPermission = (Config.config.showCategoryWithoutPermission
|
||||
|| Config.config.permissions["chapter"]);
|
||||
if (segment.category === "chapter" && (!utils.getCategorySelection("chapter") || !hasChaptersPermission)) {
|
||||
if (segment.category === "chapter" && (!getCategoryDefaultSelection("chapter") || !hasChaptersPermission)) {
|
||||
segment.category = "chooseACategory" as Category;
|
||||
segment.actionType = ActionType.Skip;
|
||||
segment.description = "";
|
||||
@@ -734,7 +733,7 @@ async function startSponsorSchedule(includeIntersectingSegments = false, current
|
||||
}
|
||||
}
|
||||
|
||||
if (utils.getCategorySelection(currentSkip.category)?.option === CategorySkipOption.ManualSkip
|
||||
if (getCategorySelection(currentSkip)?.option === CategorySkipOption.ManualSkip
|
||||
|| currentSkip.actionType === ActionType.Mute) {
|
||||
forcedSkipTime = skipTime[0] + 0.001;
|
||||
} else {
|
||||
@@ -1355,7 +1354,7 @@ function startSkipScheduleCheckingForStartSponsors() {
|
||||
&& time.actionType === ActionType.Poi && time.hidden === SponsorHideType.Visible)
|
||||
.sort((a, b) => b.segment[0] - a.segment[0]);
|
||||
for (const time of poiSegments) {
|
||||
const skipOption = utils.getCategorySelection(time.category)?.option;
|
||||
const skipOption = getCategorySelection(time)?.option;
|
||||
if (skipOption !== CategorySkipOption.ShowOverlay) {
|
||||
skipToTime({
|
||||
v: getVideo(),
|
||||
@@ -1504,12 +1503,12 @@ function getNextSkipIndex(currentTime: number, includeIntersectingSegments: bool
|
||||
{array: ScheduledTime[]; index: number; endIndex: number; extraIndexes: number[]; openNotice: boolean} {
|
||||
|
||||
const autoSkipSorter = (segment: ScheduledTime) => {
|
||||
const skipOption = utils.getCategorySelection(segment.category)?.option;
|
||||
const skipOption = getCategorySelection(segment)?.option;
|
||||
if (segment.hidden !== SponsorHideType.Visible) {
|
||||
// Hidden segments sometimes end up here if another segment is at the same time, use them last
|
||||
return 3;
|
||||
} else if ((skipOption === CategorySkipOption.AutoSkip || shouldAutoSkip(segment))
|
||||
&& segment.actionType === ActionType.Skip) {
|
||||
&& (segment.actionType === ActionType.Skip || segment.actionType === ActionType.Chapter)) {
|
||||
return 0;
|
||||
} else if (skipOption !== CategorySkipOption.ShowOverlay) {
|
||||
return 1;
|
||||
@@ -1728,6 +1727,7 @@ function skipToTime({v, skipTime, skippingSegments, openNotice, forceAutoSkip, u
|
||||
&& getCurrentTime() !== skipTime[1]) {
|
||||
switch(skippingSegments[0].actionType) {
|
||||
case ActionType.Poi:
|
||||
case ActionType.Chapter:
|
||||
case ActionType.Skip: {
|
||||
// Fix for looped videos not working when skipping to the end #426
|
||||
// for some reason you also can't skip to 1 second before the end
|
||||
@@ -1850,7 +1850,7 @@ function unskipSponsorTime(segment: SponsorTime, unskipTime: number = null, forc
|
||||
videoMuted = false;
|
||||
}
|
||||
|
||||
if (forceSeek || segment.actionType === ActionType.Skip || voteNotice) {
|
||||
if (forceSeek || segment.actionType === ActionType.Skip || segment.actionType === ActionType.Chapter || voteNotice) {
|
||||
//add a tiny bit of time to make sure it is not skipped again
|
||||
setCurrentTime(unskipTime ?? segment.segment[0] + 0.001);
|
||||
}
|
||||
@@ -1921,7 +1921,7 @@ function shouldAutoSkip(segment: SponsorTime): boolean {
|
||||
}
|
||||
|
||||
return (!Config.config.manualSkipOnFullVideo || !sponsorTimes?.some((s) => s.category === segment.category && s.actionType === ActionType.Full))
|
||||
&& (utils.getCategorySelection(segment.category)?.option === CategorySkipOption.AutoSkip ||
|
||||
&& (getCategorySelection(segment)?.option === CategorySkipOption.AutoSkip ||
|
||||
(Config.config.autoSkipOnMusicVideos && canSkipNonMusic && sponsorTimes?.some((s) => s.category === "music_offtopic")
|
||||
&& segment.actionType === ActionType.Skip)
|
||||
|| sponsorTimesSubmitting.some((s) => s.segment === segment.segment))
|
||||
@@ -1930,15 +1930,14 @@ function shouldAutoSkip(segment: SponsorTime): boolean {
|
||||
|
||||
function shouldSkip(segment: SponsorTime): boolean {
|
||||
return (segment.actionType !== ActionType.Full
|
||||
&& segment.source !== SponsorSourceType.YouTube
|
||||
&& utils.getCategorySelection(segment.category)?.option !== CategorySkipOption.ShowOverlay)
|
||||
&& getCategorySelection(segment)?.option > CategorySkipOption.ShowOverlay)
|
||||
|| (Config.config.autoSkipOnMusicVideos && sponsorTimes?.some((s) => s.category === "music_offtopic")
|
||||
&& segment.actionType === ActionType.Skip)
|
||||
|| isLoopedChapter(segment);
|
||||
}
|
||||
|
||||
function isLoopedChapter(segment: SponsorTime) :boolean{
|
||||
return !!segment && !!loopedChapter && segment.actionType === ActionType.Skip && segment.segment[1] != undefined
|
||||
function isLoopedChapter(segment: SponsorTime): boolean{
|
||||
return !!segment && !!loopedChapter && segment.segment[1] != undefined
|
||||
&& segment.segment[0] === loopedChapter.segment[0] && segment.segment[1] === loopedChapter.segment[1];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user