From da1a535de784540ee10166a75a3eb8537073838c Mon Sep 17 00:00:00 2001 From: Ajay Date: Sat, 7 Jun 2025 01:01:52 -0400 Subject: [PATCH] Add channel id and name attribute for advanced skip options --- maze-utils | 2 +- src/content.ts | 20 +++++++++++++------- src/utils/segmentData.ts | 6 ++---- src/utils/skipRule.ts | 30 +++++++++++++++++++----------- 4 files changed, 35 insertions(+), 23 deletions(-) diff --git a/maze-utils b/maze-utils index 5d5e0b09..4c79311d 160000 --- a/maze-utils +++ b/maze-utils @@ -1 +1 @@ -Subproject commit 5d5e0b096b67f138122d0c6142505210bfe52120 +Subproject commit 4c79311de097be3f2800b79a588a65fe2e8057a4 diff --git a/src/content.ts b/src/content.ts index d7b5e12b..1d0c511e 100644 --- a/src/content.ts +++ b/src/content.ts @@ -222,7 +222,7 @@ function messageListener(request: Message, sender: unknown, sendResponse: (respo sendResponse({ found: sponsorDataFound, status: lastResponseStatus, - sponsorTimes: sponsorTimes, + sponsorTimes: sponsorTimes.filter((segment) => getCategorySelection(segment).option !== CategorySkipOption.Disabled), time: getCurrentTime() ?? 0, onMobileYouTube: isOnMobileYouTube(), videoID: getVideoID(), @@ -1252,24 +1252,27 @@ async function sponsorsLookup(keepOldSubmissions = true, ignoreCache = false) { } } + notifyPopupOfSegments(); importExistingChapters(true); + if (Config.config.isVip) { + lockedCategoriesLookup(); + } +} + +function notifyPopupOfSegments(): void { // notify popup of segment changes chrome.runtime.sendMessage({ message: "infoUpdated", found: sponsorDataFound, status: lastResponseStatus, - sponsorTimes: sponsorTimes, + sponsorTimes: sponsorTimes.filter((segment) => getCategorySelection(segment).option !== CategorySkipOption.Disabled), time: getCurrentTime() ?? 0, onMobileYouTube: isOnMobileYouTube(), videoID: getVideoID(), loopedChapter: loopedChapter?.UUID, channelWhitelisted }); - - if (Config.config.isVip) { - lockedCategoriesLookup(); - } } function importExistingChapters(wait: boolean) { @@ -1403,7 +1406,7 @@ function updatePreviewBar(): void { const previewBarSegments: PreviewBarSegment[] = []; if (sponsorTimes) { sponsorTimes.forEach((segment) => { - if (segment.hidden !== SponsorHideType.Visible) return; + if (segment.hidden !== SponsorHideType.Visible || getCategorySelection(segment).option === CategorySkipOption.Disabled) return; previewBarSegments.push({ segment: segment.segment as [number, number], @@ -1457,6 +1460,9 @@ async function channelIDChange(channelIDInfo: ChannelIDInfo) { // check if the start of segments were missed if (Config.config.forceChannelCheck && sponsorTimes?.length > 0) startSkipScheduleCheckingForStartSponsors(); + + updatePreviewBar(); + notifyPopupOfSegments(); } function videoElementChange(newVideo: boolean, video: HTMLVideoElement): void { diff --git a/src/utils/segmentData.ts b/src/utils/segmentData.ts index 38cf4848..bc42fb39 100644 --- a/src/utils/segmentData.ts +++ b/src/utils/segmentData.ts @@ -2,11 +2,10 @@ import { DataCache } from "../../maze-utils/src/cache"; import { getHash, HashedValue } from "../../maze-utils/src/hash"; import Config, { } from "../config"; import * as CompileConfig from "../../config.json"; -import { ActionType, ActionTypes, CategorySkipOption, SponsorSourceType, SponsorTime, VideoID } from "../types"; +import { ActionType, ActionTypes, SponsorSourceType, SponsorTime, VideoID } from "../types"; import { getHashParams } from "./pageUtils"; import { asyncRequestToServer } from "./requests"; import { extensionUserAgent } from "../../maze-utils/src"; -import { getCategorySelection } from "./skipRule"; const segmentDataCache = new DataCache(() => { return { @@ -66,8 +65,7 @@ async function fetchSegmentsForVideo(videoID: VideoID): Promise const receivedSegments: SponsorTime[] = JSON.parse(response.responseText) ?.filter((video) => video.videoID === videoID) ?.map((video) => video.segments)?.[0] - ?.filter((segment) => enabledActionTypes.includes(segment.actionType) - && getCategorySelection(segment).option !== CategorySkipOption.Disabled) + ?.filter((segment) => enabledActionTypes.includes(segment.actionType)) ?.map((segment) => ({ ...segment, source: SponsorSourceType.Server diff --git a/src/utils/skipRule.ts b/src/utils/skipRule.ts index 1450ac63..50fa7da0 100644 --- a/src/utils/skipRule.ts +++ b/src/utils/skipRule.ts @@ -1,4 +1,4 @@ -import { getVideoDuration } from "../../maze-utils/src/video"; +import { getChannelIDInfo, getVideoDuration } from "../../maze-utils/src/video"; import Config from "../config"; import { CategorySelection, CategorySkipOption, SponsorSourceType, SponsorTime } from "../types"; import { VideoLabelsCacheData } from "./videoLabels"; @@ -8,16 +8,18 @@ export interface Permission { } export enum SkipRuleAttribute { - StartTime = "startTime", - EndTime = "endTime", - Duration = "duration", - StartTimePercent = "startTimePercent", - EndTimePercent = "endTimePercent", - DurationPercent = "durationPercent", + StartTime = "time.start", + EndTime = "time.end", + Duration = "time.duration", + StartTimePercent = "time.startPercent", + EndTimePercent = "time.endPercent", + DurationPercent = "time.durationPercent", Category = "category", ActionType = "actionType", - Description = "description", - Source = "source" + Description = "chapter.name", + Source = "chapter.source", + ChannelID = "channel.id", + ChannelName = "channel.name" } export enum SkipRuleOperator { @@ -105,9 +107,15 @@ function getSkipRuleValue(segment: SponsorTime | VideoLabelsCacheData, rule: Adv return "autogenerated"; case SponsorSourceType.Server: return "server"; + default: + return undefined; } - - break; + case SkipRuleAttribute.ChannelID: + getChannelIDInfo() + return getChannelIDInfo().id; + case SkipRuleAttribute.ChannelName: + getChannelIDInfo() + return getChannelIDInfo().author; default: return undefined; }