Made render segments as chapters only affect non chapter segments

This commit is contained in:
Ajay 2022-07-04 00:43:55 -04:00
parent de85d93602
commit fea90d024e
5 changed files with 16 additions and 15 deletions

View file

@ -78,13 +78,13 @@
</div>
</div>
<div data-type="toggle" data-sync="renderAsChapters">
<div data-type="toggle" data-sync="renderSegmentsAsChapters">
<div class="switch-container">
<label class="switch">
<input id="renderAsChapters" type="checkbox" checked>
<input id="renderSegmentsAsChapters" type="checkbox" checked>
<span class="slider round"></span>
</label>
<label class="switch-label" for="renderAsChapters">
<label class="switch-label" for="renderSegmentsAsChapters">
__MSG_renderAsChapters__
</label>
</div>

View file

@ -9,7 +9,7 @@ interface SBConfig {
/* Contains unsubmitted segments that the user has created. */
unsubmittedSegments: Record<string, SponsorTime[]>,
defaultCategory: Category,
renderAsChapters: boolean,
renderSegmentsAsChapters: boolean,
whitelistedChannels: string[],
forceChannelCheck: boolean,
minutesSaved: number,
@ -132,7 +132,7 @@ const Config: SBObject = {
isVip: false,
unsubmittedSegments: {},
defaultCategory: "chooseACategory" as Category,
renderAsChapters: true,
renderSegmentsAsChapters: true,
whitelistedChannels: [],
forceChannelCheck: false,
minutesSaved: 0,

View file

@ -958,7 +958,11 @@ async function sponsorsLookup(keepOldSubmissions = true) {
}
function importExistingChapters(wait: boolean) {
if (Config.config.renderAsChapters && !existingChaptersImported
const containsChapter = sponsorTimes?.some((segment) => segment.actionType === ActionType.Chapter)
|| sponsorTimesSubmitting.some((segment) => segment.actionType === ActionType.Chapter);
if ((Config.config.renderSegmentsAsChapters || containsChapter)
&& !existingChaptersImported
&& (sponsorTimes?.length > 0 || sponsorTimesSubmitting.length > 0)) {
GenericUtils.wait(() => video && getExistingChapters(sponsorVideoID, video.duration),
wait ? 5000 : 0, 100, (c) => c?.length > 0).then((chapters) => {

View file

@ -220,7 +220,8 @@ class PreviewBar {
this.createChaptersBar(segments.sort((a, b) => a.segment[0] - b.segment[0]));
const chapterChevron = document.querySelector(".ytp-chapter-title-chevron") as HTMLElement;
if (!Config.config.renderAsChapters || segments.some((segment) => segment.source === SponsorSourceType.YouTube)) {
if (!Config.config.renderSegmentsAsChapters
|| segments.some((segment) => segment.source === SponsorSourceType.YouTube)) {
chapterChevron.style.removeProperty("display");
} else {
chapterChevron.style.display = "none";
@ -243,8 +244,7 @@ class PreviewBar {
bar.style.position = "absolute";
const duration = Math.min(segment[1], this.videoDuration) - segment[0];
if (duration > 0) {
bar.style.width = `calc(${this.timeToPercentage(segment[1] - segment[0])}${
Config.config.renderAsChapters && this.chapterFilter(barSegment) ? ' - 2px' : ''})`;
bar.style.width = `calc(${this.timeToPercentage(segment[1] - segment[0])}${this.chapterFilter(barSegment) ? ' - 2px' : ''})`;
}
const time = segment[1] ? Math.min(this.videoDuration, segment[0]) : segment[0];
@ -258,7 +258,7 @@ class PreviewBar {
const chapterBar = document.querySelector(".ytp-chapters-container:not(.sponsorBlockChapterBar)") as HTMLElement;
if (!progressBar || !chapterBar || chapterBar.childElementCount <= 0) return;
if (!Config.config.renderAsChapters) {
if (!Config.config.renderSegmentsAsChapters && segments.every((segment) => segment.actionType !== ActionType.Chapter)) {
if (this.customChaptersBar) this.customChaptersBar.style.display = "none";
chapterBar.style.removeProperty("display");
return;
@ -649,7 +649,8 @@ class PreviewBar {
}
private chapterFilter(segment: PreviewBarSegment): boolean {
return segment.actionType !== ActionType.Poi
return (Config.config.renderSegmentsAsChapters || segment.actionType === ActionType.Chapter)
&& segment.actionType !== ActionType.Poi
&& this.chapterGroupFilter(segment);
}

View file

@ -440,8 +440,4 @@ export default class Utils {
Config.forceLocalUpdate("downvotedSegments");
}
chaptersEnabled(): boolean {
return Config.config.renderAsChapters && !!this.getCategorySelection("chapter");
}
}