Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion public/_locales
1 change: 1 addition & 0 deletions src/components/options/CategoryChooserComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export function CategoryChooserComponent() {
name: `${chrome.i18n.getMessage("NewConfiguration")} ${Object.keys(Config.local.skipProfiles).length}`,
categorySelections: [],
showAutogeneratedChapters: null,
showCreatorChapters: null,
autoSkipOnMusicVideos: null,
skipNonMusicOnlyOnYoutubeMusic: null,
muteSegments: null,
Expand Down
5 changes: 5 additions & 0 deletions src/components/options/CategorySkipOptionsComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,11 @@ function getExtraOptions(category: string): ToggleOption[] {
label: chrome.i18n.getMessage("showAutogeneratedChapters"),
type: "toggle",
dontDisable: true
}, {
configKey: "showCreatorChapters",
label: chrome.i18n.getMessage("showCreatorChapters"),
type: "toggle",
dontDisable: true
}];
case "music_offtopic":
return [{
Expand Down
4 changes: 4 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ interface SBConfig {
showCategoryWithoutPermission: boolean;
showSegmentNameInChapterBar: boolean;
showAutogeneratedChapters: boolean;
showCreatorChapters: boolean;
useVirtualTime: boolean;
showSegmentFailedToFetchWarning: boolean;
allowScrollingToEdit: boolean;
Expand Down Expand Up @@ -145,6 +146,7 @@ export interface CustomConfiguration {
name: string;
categorySelections: CategorySelection[];
showAutogeneratedChapters: boolean | null;
showCreatorChapters: boolean | null;
autoSkipOnMusicVideos: boolean | null;
skipNonMusicOnlyOnYoutubeMusic: boolean | null;
muteSegments: boolean | null;
Expand Down Expand Up @@ -239,6 +241,7 @@ function migrateOldSyncFormats(config: SBConfig, local: SBStorage) {
option: CategorySkipOption.ShowOverlay
})),
showAutogeneratedChapters: null,
showCreatorChapters: null,
autoSkipOnMusicVideos: null,
skipNonMusicOnlyOnYoutubeMusic: null,
muteSegments: null,
Expand Down Expand Up @@ -430,6 +433,7 @@ const syncDefaults = {
showCategoryWithoutPermission: false,
showSegmentNameInChapterBar: true,
showAutogeneratedChapters: true,
showCreatorChapters: true,
useVirtualTime: true,
showSegmentFailedToFetchWarning: true,
allowScrollingToEdit: true,
Expand Down
6 changes: 5 additions & 1 deletion src/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1327,6 +1327,8 @@ function importExistingChapters(wait: boolean) {
function handleExistingChaptersChannelChange() {
if (existingChaptersImported && hasAutogeneratedChapters() && !getSkipProfileBool("showAutogeneratedChapters")) {
sponsorTimes = sponsorTimes.filter((segment) => segment.source !== SponsorSourceType.Autogenerated);
} else if (existingChaptersImported && !getSkipProfileBool("showCreatorChapters")) {
sponsorTimes = sponsorTimes.filter((segment) => segment.source !== SponsorSourceType.YouTube);
}
}

Expand Down Expand Up @@ -1427,7 +1429,9 @@ function updatePreviewBar(): void {
const previewBarSegments: PreviewBarSegment[] = [];
if (sponsorTimes) {
sponsorTimes.forEach((segment) => {
if (segment.hidden !== SponsorHideType.Visible || getCategorySelection(segment).option === CategorySkipOption.Disabled) return;
if (segment.hidden !== SponsorHideType.Visible
|| (getCategorySelection(segment).option === CategorySkipOption.Disabled
&& ![SponsorSourceType.YouTube, SponsorSourceType.Autogenerated].includes(segment.source))) return;

previewBarSegments.push({
segment: segment.segment as [number, number],
Expand Down
15 changes: 10 additions & 5 deletions src/js-components/previewBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ class PreviewBar {
}

const hasAYouTubeChapterRemoved = this.hasYouTubeChapters
|| (!getSkipProfileBool("showAutogeneratedChapters") && hasAutogeneratedChapters());
|| (!getSkipProfileBool("showAutogeneratedChapters") && hasAutogeneratedChapters())
|| !getSkipProfileBool("showCreatorChapters");
if (hasAYouTubeChapterRemoved) {
// Hide original tooltip if some chapter has been filtered out
originalTooltip.style.display = "none";
Expand Down Expand Up @@ -463,7 +464,8 @@ class PreviewBar {
|| (!Config.config.renderSegmentsAsChapters
&& segments.every((segment) => segment.actionType !== ActionType.Chapter
|| [SponsorSourceType.YouTube, SponsorSourceType.Autogenerated].includes(segment.source))))
&& !(hasAutogeneratedChapters() && !getSkipProfileBool("showAutogeneratedChapters"))) {
&& !(hasAutogeneratedChapters() && !getSkipProfileBool("showAutogeneratedChapters"))
&& getSkipProfileBool("showCreatorChapters")) {

if (this.customChaptersBar) this.customChaptersBar.style.display = "none";
this.originalChapterBar.style.removeProperty("display");
Expand All @@ -490,7 +492,8 @@ class PreviewBar {
this.chapterGroups = this.unfilteredChapterGroups;
}

if (this.chapterGroups.length === 0 && !getSkipProfileBool("showAutogeneratedChapters") && hasAutogeneratedChapters()) {
if (this.chapterGroups.length === 0
&& ((!getSkipProfileBool("showAutogeneratedChapters") && hasAutogeneratedChapters()) || !getSkipProfileBool("showCreatorChapters"))) {
// Add placeholder chapter group for whole video
this.chapterGroups = [{
segment: [0, this.videoDuration],
Expand Down Expand Up @@ -892,7 +895,8 @@ class PreviewBar {
if (!Config.config.showSegmentNameInChapterBar
|| Config.config.disableSkipping
|| ((!segments || segments.length <= 0) && submittingSegments?.length <= 0
&& (getSkipProfileBool("showAutogeneratedChapters") || !hasAutogeneratedChapters()))) {
&& (getSkipProfileBool("showAutogeneratedChapters") || !hasAutogeneratedChapters())
&& getSkipProfileBool("showCreatorChapters"))) {
const chaptersContainer = this.getChaptersContainer();
if (chaptersContainer) {
chaptersContainer.querySelector(".sponsorChapterText")?.remove();
Expand Down Expand Up @@ -995,7 +999,8 @@ class PreviewBar {
} else {
this.chapterVote.setVisibility(false);
}
} else if (!getSkipProfileBool("showAutogeneratedChapters") && hasAutogeneratedChapters()) {
} else if ((!getSkipProfileBool("showAutogeneratedChapters") && hasAutogeneratedChapters())
|| !getSkipProfileBool("showCreatorChapters")) {
// Keep original hidden
chaptersContainer.querySelector(".sponsorChapterText")?.remove();
const chapterTitle = chaptersContainer.querySelector(".ytp-chapter-title-content") as HTMLDivElement;
Expand Down
5 changes: 3 additions & 2 deletions src/utils/pageUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ export function getExistingChapters(currentVideoID: VideoID, duration: number):
if (title?.textContent?.includes("Key moment")) return [];

const autogenerated = hasAutogeneratedChapters();
if (!getSkipProfileBool("showAutogeneratedChapters") && autogenerated) return [];
if ((!getSkipProfileBool("showAutogeneratedChapters") && autogenerated)
|| !getSkipProfileBool("showCreatorChapters")) return [];

const chapters: SponsorTime[] = [];
// .ytp-timed-markers-container indicates that key-moments are present, which should not be divided
Expand All @@ -75,7 +76,7 @@ export function getExistingChapters(currentVideoID: VideoID, duration: number):
const links = chaptersBox.querySelectorAll("ytd-macro-markers-list-item-renderer > a");
for (const link of links) {
const timeElement = link.querySelector("#time") as HTMLElement;
const description = link.querySelector("#details h4") as HTMLElement;
const description = link.querySelector("#details h3") as HTMLElement;
if (timeElement && description?.innerText?.length > 0 && link.getAttribute("href")?.includes(currentVideoID)) {
const time = getFormattedTimeToSeconds(timeElement.innerText.replace(/\./g, ":"));
if (time === null) return [];
Expand Down
3 changes: 2 additions & 1 deletion src/utils/skipProfiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export function getSkipProfile(): CustomConfiguration | null {

type SkipProfileBoolKey =
"showAutogeneratedChapters"
| "showCreatorChapters"
| "autoSkipOnMusicVideos"
| "skipNonMusicOnlyOnYoutubeMusic"
| "muteSegments"
Expand All @@ -74,7 +75,7 @@ export function getSkipProfileNum(key: "minDuration"): number {

function getSkipProfileValue<T>(key: keyof CustomConfiguration): T {
const profile = getSkipProfile();
if (profile && profile[key] !== null) {
if (profile && profile[key] !== null && profile[key] !== undefined) {
return profile[key] as T;
}

Expand Down
Loading