mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-06 19:47:04 +03:00
Add autogenerated type for source in advance skip options
This commit is contained in:
@@ -141,7 +141,7 @@ function compileConfig(config: string): AdvancedSkipRuleSet[] | null {
|
||||
return null; // Invalid category value
|
||||
} else if (attribute === SkipRuleAttribute.Source
|
||||
&& operator === SkipRuleOperator.Equal
|
||||
&& !["local", "youtube", "server"].includes(value as string)) {
|
||||
&& !["local", "youtube", "autogenerated", "server"].includes(value as string)) {
|
||||
return null; // Invalid category value
|
||||
}
|
||||
|
||||
|
||||
@@ -299,14 +299,14 @@ class PreviewBar {
|
||||
set(segments: PreviewBarSegment[], videoDuration: number): void {
|
||||
this.segments = segments ?? [];
|
||||
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
|
||||
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 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[1] - chapter.segment[1]) < Math.min(3, segmentDuration / 3));
|
||||
|
||||
@@ -354,7 +354,7 @@ class PreviewBar {
|
||||
this.chapterMargin = 2;
|
||||
if (this.originalChapterBar) {
|
||||
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) {
|
||||
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]));
|
||||
|
||||
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");
|
||||
} else if (this.segments) {
|
||||
chapterChevron.style.display = "none";
|
||||
@@ -438,10 +438,10 @@ class PreviewBar {
|
||||
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
|
||||
&& segments.every((segment) => segment.actionType !== ActionType.Chapter
|
||||
|| segment.source === SponsorSourceType.YouTube)))
|
||||
|| [SponsorSourceType.YouTube, SponsorSourceType.Autogenerated].includes(segment.source))))
|
||||
&& !(hasAutogeneratedChapters() && !Config.config.showAutogeneratedChapters)) {
|
||||
|
||||
if (this.customChaptersBar) this.customChaptersBar.style.display = "none";
|
||||
|
||||
@@ -70,7 +70,8 @@ export type Category = string & { __categoryBrand: unknown };
|
||||
export enum SponsorSourceType {
|
||||
Server = undefined,
|
||||
Local = 1,
|
||||
YouTube = 2
|
||||
YouTube = 2,
|
||||
Autogenerated = 3
|
||||
}
|
||||
|
||||
export interface SegmentContainer {
|
||||
|
||||
@@ -16,7 +16,7 @@ export function exportTimes(segments: SponsorTime[]): string {
|
||||
let result = "";
|
||||
for (const segment of segments) {
|
||||
if (![ActionType.Full, ActionType.Mute].includes(segment.actionType)
|
||||
&& segment.source !== SponsorSourceType.YouTube) {
|
||||
&& [SponsorSourceType.YouTube, SponsorSourceType.Autogenerated].includes(segment.source)) {
|
||||
result += exportTime(segment) + "\n";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,7 +68,9 @@ export function getExistingChapters(currentVideoID: VideoID, duration: number):
|
||||
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");
|
||||
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[] = [];
|
||||
// .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,
|
||||
actionType: ActionType.Chapter,
|
||||
description: description.innerText,
|
||||
source: SponsorSourceType.YouTube,
|
||||
source: autogenerated ? SponsorSourceType.Autogenerated : SponsorSourceType.YouTube,
|
||||
UUID: null
|
||||
};
|
||||
}
|
||||
|
||||
@@ -139,6 +139,8 @@ function getSkipRuleValue(segment: SponsorTime | VideoLabelsCacheData, rule: Adv
|
||||
return "local";
|
||||
case SponsorSourceType.YouTube:
|
||||
return "youtube";
|
||||
case SponsorSourceType.Autogenerated:
|
||||
return "autogenerated";
|
||||
case SponsorSourceType.Server:
|
||||
return "server";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user