mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2026-01-29 13:50:50 +03:00
Made render segments as chapters only affect non chapter segments
This commit is contained in:
@@ -78,13 +78,13 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div data-type="toggle" data-sync="renderAsChapters">
|
<div data-type="toggle" data-sync="renderSegmentsAsChapters">
|
||||||
<div class="switch-container">
|
<div class="switch-container">
|
||||||
<label class="switch">
|
<label class="switch">
|
||||||
<input id="renderAsChapters" type="checkbox" checked>
|
<input id="renderSegmentsAsChapters" type="checkbox" checked>
|
||||||
<span class="slider round"></span>
|
<span class="slider round"></span>
|
||||||
</label>
|
</label>
|
||||||
<label class="switch-label" for="renderAsChapters">
|
<label class="switch-label" for="renderSegmentsAsChapters">
|
||||||
__MSG_renderAsChapters__
|
__MSG_renderAsChapters__
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ interface SBConfig {
|
|||||||
/* Contains unsubmitted segments that the user has created. */
|
/* Contains unsubmitted segments that the user has created. */
|
||||||
unsubmittedSegments: Record<string, SponsorTime[]>,
|
unsubmittedSegments: Record<string, SponsorTime[]>,
|
||||||
defaultCategory: Category,
|
defaultCategory: Category,
|
||||||
renderAsChapters: boolean,
|
renderSegmentsAsChapters: boolean,
|
||||||
whitelistedChannels: string[],
|
whitelistedChannels: string[],
|
||||||
forceChannelCheck: boolean,
|
forceChannelCheck: boolean,
|
||||||
minutesSaved: number,
|
minutesSaved: number,
|
||||||
@@ -132,7 +132,7 @@ const Config: SBObject = {
|
|||||||
isVip: false,
|
isVip: false,
|
||||||
unsubmittedSegments: {},
|
unsubmittedSegments: {},
|
||||||
defaultCategory: "chooseACategory" as Category,
|
defaultCategory: "chooseACategory" as Category,
|
||||||
renderAsChapters: true,
|
renderSegmentsAsChapters: true,
|
||||||
whitelistedChannels: [],
|
whitelistedChannels: [],
|
||||||
forceChannelCheck: false,
|
forceChannelCheck: false,
|
||||||
minutesSaved: 0,
|
minutesSaved: 0,
|
||||||
|
|||||||
@@ -958,7 +958,11 @@ async function sponsorsLookup(keepOldSubmissions = true) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function importExistingChapters(wait: boolean) {
|
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)) {
|
&& (sponsorTimes?.length > 0 || sponsorTimesSubmitting.length > 0)) {
|
||||||
GenericUtils.wait(() => video && getExistingChapters(sponsorVideoID, video.duration),
|
GenericUtils.wait(() => video && getExistingChapters(sponsorVideoID, video.duration),
|
||||||
wait ? 5000 : 0, 100, (c) => c?.length > 0).then((chapters) => {
|
wait ? 5000 : 0, 100, (c) => c?.length > 0).then((chapters) => {
|
||||||
|
|||||||
@@ -220,7 +220,8 @@ class PreviewBar {
|
|||||||
this.createChaptersBar(segments.sort((a, b) => a.segment[0] - b.segment[0]));
|
this.createChaptersBar(segments.sort((a, b) => a.segment[0] - b.segment[0]));
|
||||||
|
|
||||||
const chapterChevron = document.querySelector(".ytp-chapter-title-chevron") as HTMLElement;
|
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");
|
chapterChevron.style.removeProperty("display");
|
||||||
} else {
|
} else {
|
||||||
chapterChevron.style.display = "none";
|
chapterChevron.style.display = "none";
|
||||||
@@ -243,8 +244,7 @@ class PreviewBar {
|
|||||||
bar.style.position = "absolute";
|
bar.style.position = "absolute";
|
||||||
const duration = Math.min(segment[1], this.videoDuration) - segment[0];
|
const duration = Math.min(segment[1], this.videoDuration) - segment[0];
|
||||||
if (duration > 0) {
|
if (duration > 0) {
|
||||||
bar.style.width = `calc(${this.timeToPercentage(segment[1] - segment[0])}${
|
bar.style.width = `calc(${this.timeToPercentage(segment[1] - segment[0])}${this.chapterFilter(barSegment) ? ' - 2px' : ''})`;
|
||||||
Config.config.renderAsChapters && this.chapterFilter(barSegment) ? ' - 2px' : ''})`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const time = segment[1] ? Math.min(this.videoDuration, segment[0]) : segment[0];
|
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;
|
const chapterBar = document.querySelector(".ytp-chapters-container:not(.sponsorBlockChapterBar)") as HTMLElement;
|
||||||
if (!progressBar || !chapterBar || chapterBar.childElementCount <= 0) return;
|
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";
|
if (this.customChaptersBar) this.customChaptersBar.style.display = "none";
|
||||||
chapterBar.style.removeProperty("display");
|
chapterBar.style.removeProperty("display");
|
||||||
return;
|
return;
|
||||||
@@ -649,7 +649,8 @@ class PreviewBar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private chapterFilter(segment: PreviewBarSegment): boolean {
|
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);
|
&& this.chapterGroupFilter(segment);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -440,8 +440,4 @@ export default class Utils {
|
|||||||
|
|
||||||
Config.forceLocalUpdate("downvotedSegments");
|
Config.forceLocalUpdate("downvotedSegments");
|
||||||
}
|
}
|
||||||
|
|
||||||
chaptersEnabled(): boolean {
|
|
||||||
return Config.config.renderAsChapters && !!this.getCategorySelection("chapter");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user