Add channel id and name attribute for advanced skip options

This commit is contained in:
Ajay
2025-06-07 01:01:52 -04:00
parent ec1df44cbc
commit da1a535de7
4 changed files with 35 additions and 23 deletions

View File

@@ -222,7 +222,7 @@ function messageListener(request: Message, sender: unknown, sendResponse: (respo
sendResponse({ sendResponse({
found: sponsorDataFound, found: sponsorDataFound,
status: lastResponseStatus, status: lastResponseStatus,
sponsorTimes: sponsorTimes, sponsorTimes: sponsorTimes.filter((segment) => getCategorySelection(segment).option !== CategorySkipOption.Disabled),
time: getCurrentTime() ?? 0, time: getCurrentTime() ?? 0,
onMobileYouTube: isOnMobileYouTube(), onMobileYouTube: isOnMobileYouTube(),
videoID: getVideoID(), videoID: getVideoID(),
@@ -1252,24 +1252,27 @@ async function sponsorsLookup(keepOldSubmissions = true, ignoreCache = false) {
} }
} }
notifyPopupOfSegments();
importExistingChapters(true); importExistingChapters(true);
if (Config.config.isVip) {
lockedCategoriesLookup();
}
}
function notifyPopupOfSegments(): void {
// notify popup of segment changes // notify popup of segment changes
chrome.runtime.sendMessage({ chrome.runtime.sendMessage({
message: "infoUpdated", message: "infoUpdated",
found: sponsorDataFound, found: sponsorDataFound,
status: lastResponseStatus, status: lastResponseStatus,
sponsorTimes: sponsorTimes, sponsorTimes: sponsorTimes.filter((segment) => getCategorySelection(segment).option !== CategorySkipOption.Disabled),
time: getCurrentTime() ?? 0, time: getCurrentTime() ?? 0,
onMobileYouTube: isOnMobileYouTube(), onMobileYouTube: isOnMobileYouTube(),
videoID: getVideoID(), videoID: getVideoID(),
loopedChapter: loopedChapter?.UUID, loopedChapter: loopedChapter?.UUID,
channelWhitelisted channelWhitelisted
}); });
if (Config.config.isVip) {
lockedCategoriesLookup();
}
} }
function importExistingChapters(wait: boolean) { function importExistingChapters(wait: boolean) {
@@ -1403,7 +1406,7 @@ function updatePreviewBar(): void {
const previewBarSegments: PreviewBarSegment[] = []; const previewBarSegments: PreviewBarSegment[] = [];
if (sponsorTimes) { if (sponsorTimes) {
sponsorTimes.forEach((segment) => { sponsorTimes.forEach((segment) => {
if (segment.hidden !== SponsorHideType.Visible) return; if (segment.hidden !== SponsorHideType.Visible || getCategorySelection(segment).option === CategorySkipOption.Disabled) return;
previewBarSegments.push({ previewBarSegments.push({
segment: segment.segment as [number, number], segment: segment.segment as [number, number],
@@ -1457,6 +1460,9 @@ async function channelIDChange(channelIDInfo: ChannelIDInfo) {
// check if the start of segments were missed // check if the start of segments were missed
if (Config.config.forceChannelCheck && sponsorTimes?.length > 0) startSkipScheduleCheckingForStartSponsors(); if (Config.config.forceChannelCheck && sponsorTimes?.length > 0) startSkipScheduleCheckingForStartSponsors();
updatePreviewBar();
notifyPopupOfSegments();
} }
function videoElementChange(newVideo: boolean, video: HTMLVideoElement): void { function videoElementChange(newVideo: boolean, video: HTMLVideoElement): void {

View File

@@ -2,11 +2,10 @@ import { DataCache } from "../../maze-utils/src/cache";
import { getHash, HashedValue } from "../../maze-utils/src/hash"; import { getHash, HashedValue } from "../../maze-utils/src/hash";
import Config, { } from "../config"; import Config, { } from "../config";
import * as CompileConfig from "../../config.json"; 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 { getHashParams } from "./pageUtils";
import { asyncRequestToServer } from "./requests"; import { asyncRequestToServer } from "./requests";
import { extensionUserAgent } from "../../maze-utils/src"; import { extensionUserAgent } from "../../maze-utils/src";
import { getCategorySelection } from "./skipRule";
const segmentDataCache = new DataCache<VideoID, SegmentResponse>(() => { const segmentDataCache = new DataCache<VideoID, SegmentResponse>(() => {
return { return {
@@ -66,8 +65,7 @@ async function fetchSegmentsForVideo(videoID: VideoID): Promise<SegmentResponse>
const receivedSegments: SponsorTime[] = JSON.parse(response.responseText) const receivedSegments: SponsorTime[] = JSON.parse(response.responseText)
?.filter((video) => video.videoID === videoID) ?.filter((video) => video.videoID === videoID)
?.map((video) => video.segments)?.[0] ?.map((video) => video.segments)?.[0]
?.filter((segment) => enabledActionTypes.includes(segment.actionType) ?.filter((segment) => enabledActionTypes.includes(segment.actionType))
&& getCategorySelection(segment).option !== CategorySkipOption.Disabled)
?.map((segment) => ({ ?.map((segment) => ({
...segment, ...segment,
source: SponsorSourceType.Server source: SponsorSourceType.Server

View File

@@ -1,4 +1,4 @@
import { getVideoDuration } from "../../maze-utils/src/video"; import { getChannelIDInfo, getVideoDuration } from "../../maze-utils/src/video";
import Config from "../config"; import Config from "../config";
import { CategorySelection, CategorySkipOption, SponsorSourceType, SponsorTime } from "../types"; import { CategorySelection, CategorySkipOption, SponsorSourceType, SponsorTime } from "../types";
import { VideoLabelsCacheData } from "./videoLabels"; import { VideoLabelsCacheData } from "./videoLabels";
@@ -8,16 +8,18 @@ export interface Permission {
} }
export enum SkipRuleAttribute { export enum SkipRuleAttribute {
StartTime = "startTime", StartTime = "time.start",
EndTime = "endTime", EndTime = "time.end",
Duration = "duration", Duration = "time.duration",
StartTimePercent = "startTimePercent", StartTimePercent = "time.startPercent",
EndTimePercent = "endTimePercent", EndTimePercent = "time.endPercent",
DurationPercent = "durationPercent", DurationPercent = "time.durationPercent",
Category = "category", Category = "category",
ActionType = "actionType", ActionType = "actionType",
Description = "description", Description = "chapter.name",
Source = "source" Source = "chapter.source",
ChannelID = "channel.id",
ChannelName = "channel.name"
} }
export enum SkipRuleOperator { export enum SkipRuleOperator {
@@ -105,9 +107,15 @@ function getSkipRuleValue(segment: SponsorTime | VideoLabelsCacheData, rule: Adv
return "autogenerated"; return "autogenerated";
case SponsorSourceType.Server: case SponsorSourceType.Server:
return "server"; return "server";
default:
return undefined;
} }
case SkipRuleAttribute.ChannelID:
break; getChannelIDInfo()
return getChannelIDInfo().id;
case SkipRuleAttribute.ChannelName:
getChannelIDInfo()
return getChannelIDInfo().author;
default: default:
return undefined; return undefined;
} }