Add autogenerated type for source in advance skip options

This commit is contained in:
Ajay
2025-06-06 23:15:34 -04:00
parent d5ff71b367
commit 72d3f68957
6 changed files with 16 additions and 11 deletions

View File

@@ -141,7 +141,7 @@ function compileConfig(config: string): AdvancedSkipRuleSet[] | null {
return null; // Invalid category value return null; // Invalid category value
} else if (attribute === SkipRuleAttribute.Source } else if (attribute === SkipRuleAttribute.Source
&& operator === SkipRuleOperator.Equal && operator === SkipRuleOperator.Equal
&& !["local", "youtube", "server"].includes(value as string)) { && !["local", "youtube", "autogenerated", "server"].includes(value as string)) {
return null; // Invalid category value return null; // Invalid category value
} }

View File

@@ -299,14 +299,14 @@ class PreviewBar {
set(segments: PreviewBarSegment[], videoDuration: number): void { set(segments: PreviewBarSegment[], videoDuration: number): void {
this.segments = segments ?? []; this.segments = segments ?? [];
this.videoDuration = videoDuration ?? 0; this.videoDuration = videoDuration ?? 0;
this.hasYouTubeChapters = segments.some((segment) => segment.source === SponsorSourceType.YouTube); this.hasYouTubeChapters = segments.some((segment) => [SponsorSourceType.YouTube, SponsorSourceType.Autogenerated].includes(segment.source));
// Remove unnecessary original chapters if submitted replacements exist // Remove unnecessary original chapters if submitted replacements exist
for (const chapter of this.segments.filter((s) => s.actionType === ActionType.Chapter && s.source === SponsorSourceType.Server)) { for (const chapter of this.segments.filter((s) => s.actionType === ActionType.Chapter && s.source === SponsorSourceType.Server)) {
const segmentDuration = chapter.segment[1] - chapter.segment[0]; const segmentDuration = chapter.segment[1] - chapter.segment[0];
const duplicate = this.segments.find((s) => s.actionType === ActionType.Chapter const duplicate = this.segments.find((s) => s.actionType === ActionType.Chapter
&& s.source === SponsorSourceType.YouTube && [SponsorSourceType.YouTube, SponsorSourceType.Autogenerated].includes(s.source)
&& Math.abs(s.segment[0] - chapter.segment[0]) < Math.min(3, segmentDuration / 3) && Math.abs(s.segment[0] - chapter.segment[0]) < Math.min(3, segmentDuration / 3)
&& Math.abs(s.segment[1] - chapter.segment[1]) < Math.min(3, segmentDuration / 3)); && Math.abs(s.segment[1] - chapter.segment[1]) < Math.min(3, segmentDuration / 3));
@@ -354,7 +354,7 @@ class PreviewBar {
this.chapterMargin = 2; this.chapterMargin = 2;
if (this.originalChapterBar) { if (this.originalChapterBar) {
this.originalChapterBarBlocks = this.originalChapterBar.querySelectorAll(":scope > div") as NodeListOf<HTMLElement> this.originalChapterBarBlocks = this.originalChapterBar.querySelectorAll(":scope > div") as NodeListOf<HTMLElement>
this.existingChapters = this.segments.filter((s) => s.source === SponsorSourceType.YouTube).sort((a, b) => a.segment[0] - b.segment[0]); this.existingChapters = this.segments.filter((s) => [SponsorSourceType.YouTube, SponsorSourceType.Autogenerated].includes(s.source)).sort((a, b) => a.segment[0] - b.segment[0]);
if (this.existingChapters?.length > 0) { if (this.existingChapters?.length > 0) {
const margin = parseFloat(this.originalChapterBarBlocks?.[0]?.style?.marginRight?.replace("px", "")); const margin = parseFloat(this.originalChapterBarBlocks?.[0]?.style?.marginRight?.replace("px", ""));
@@ -376,7 +376,7 @@ class PreviewBar {
this.createChaptersBar(this.segments.sort((a, b) => a.segment[0] - b.segment[0])); this.createChaptersBar(this.segments.sort((a, b) => a.segment[0] - b.segment[0]));
if (chapterChevron) { if (chapterChevron) {
if (this.segments.some((segment) => segment.source === SponsorSourceType.YouTube)) { if (this.segments.some((segment) => [SponsorSourceType.YouTube, SponsorSourceType.Autogenerated].includes(segment.source))) {
chapterChevron.style.removeProperty("display"); chapterChevron.style.removeProperty("display");
} else if (this.segments) { } else if (this.segments) {
chapterChevron.style.display = "none"; chapterChevron.style.display = "none";
@@ -438,10 +438,10 @@ class PreviewBar {
this.unfilteredChapterGroups = this.createChapterRenderGroups(segments); this.unfilteredChapterGroups = this.createChapterRenderGroups(segments);
} }
if ((segments.every((segments) => segments.source === SponsorSourceType.YouTube) if ((segments.every((segment) => [SponsorSourceType.YouTube, SponsorSourceType.Autogenerated].includes(segment.source))
|| (!Config.config.renderSegmentsAsChapters || (!Config.config.renderSegmentsAsChapters
&& segments.every((segment) => segment.actionType !== ActionType.Chapter && segments.every((segment) => segment.actionType !== ActionType.Chapter
|| segment.source === SponsorSourceType.YouTube))) || [SponsorSourceType.YouTube, SponsorSourceType.Autogenerated].includes(segment.source))))
&& !(hasAutogeneratedChapters() && !Config.config.showAutogeneratedChapters)) { && !(hasAutogeneratedChapters() && !Config.config.showAutogeneratedChapters)) {
if (this.customChaptersBar) this.customChaptersBar.style.display = "none"; if (this.customChaptersBar) this.customChaptersBar.style.display = "none";

View File

@@ -70,7 +70,8 @@ export type Category = string & { __categoryBrand: unknown };
export enum SponsorSourceType { export enum SponsorSourceType {
Server = undefined, Server = undefined,
Local = 1, Local = 1,
YouTube = 2 YouTube = 2,
Autogenerated = 3
} }
export interface SegmentContainer { export interface SegmentContainer {

View File

@@ -16,7 +16,7 @@ export function exportTimes(segments: SponsorTime[]): string {
let result = ""; let result = "";
for (const segment of segments) { for (const segment of segments) {
if (![ActionType.Full, ActionType.Mute].includes(segment.actionType) if (![ActionType.Full, ActionType.Mute].includes(segment.actionType)
&& segment.source !== SponsorSourceType.YouTube) { && [SponsorSourceType.YouTube, SponsorSourceType.Autogenerated].includes(segment.source)) {
result += exportTime(segment) + "\n"; result += exportTime(segment) + "\n";
} }
} }

View File

@@ -68,7 +68,9 @@ export function getExistingChapters(currentVideoID: VideoID, duration: number):
const chaptersBox = document.querySelector("ytd-macro-markers-list-renderer"); const chaptersBox = document.querySelector("ytd-macro-markers-list-renderer");
const title = chaptersBox?.closest("ytd-engagement-panel-section-list-renderer")?.querySelector("#title-text.ytd-engagement-panel-title-header-renderer"); const title = chaptersBox?.closest("ytd-engagement-panel-section-list-renderer")?.querySelector("#title-text.ytd-engagement-panel-title-header-renderer");
if (title?.textContent?.includes("Key moment")) return []; if (title?.textContent?.includes("Key moment")) return [];
if (!Config.config.showAutogeneratedChapters && hasAutogeneratedChapters()) return [];
const autogenerated = hasAutogeneratedChapters();
if (!Config.config.showAutogeneratedChapters && autogenerated) return [];
const chapters: SponsorTime[] = []; const chapters: SponsorTime[] = [];
// .ytp-timed-markers-container indicates that key-moments are present, which should not be divided // .ytp-timed-markers-container indicates that key-moments are present, which should not be divided
@@ -92,7 +94,7 @@ export function getExistingChapters(currentVideoID: VideoID, duration: number):
category: "chapter" as Category, category: "chapter" as Category,
actionType: ActionType.Chapter, actionType: ActionType.Chapter,
description: description.innerText, description: description.innerText,
source: SponsorSourceType.YouTube, source: autogenerated ? SponsorSourceType.Autogenerated : SponsorSourceType.YouTube,
UUID: null UUID: null
}; };
} }

View File

@@ -139,6 +139,8 @@ function getSkipRuleValue(segment: SponsorTime | VideoLabelsCacheData, rule: Adv
return "local"; return "local";
case SponsorSourceType.YouTube: case SponsorSourceType.YouTube:
return "youtube"; return "youtube";
case SponsorSourceType.Autogenerated:
return "autogenerated";
case SponsorSourceType.Server: case SponsorSourceType.Server:
return "server"; return "server";
} }