aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorAjay <[email protected]>2022-07-04 00:43:55 -0400
committerAjay <[email protected]>2022-07-04 00:43:55 -0400
commitfea90d024e1bf8cada42b4d37e3b0f6af7f0078b (patch)
tree8bef5b7ac3a2b71672ca63159c881dee0febc6ff /src
parentde85d9360281fef429766ccc7e50cdbdb0a8daae (diff)
downloadSponsorBlock-fea90d024e1bf8cada42b4d37e3b0f6af7f0078b.tar.gz
SponsorBlock-fea90d024e1bf8cada42b4d37e3b0f6af7f0078b.zip
Made render segments as chapters only affect non chapter segments
Diffstat (limited to 'src')
-rw-r--r--src/config.ts4
-rw-r--r--src/content.ts6
-rw-r--r--src/js-components/previewBar.ts11
-rw-r--r--src/utils.ts4
4 files changed, 13 insertions, 12 deletions
diff --git a/src/config.ts b/src/config.ts
index f74edd5e..f1692344 100644
--- a/src/config.ts
+++ b/src/config.ts
@@ -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,
diff --git a/src/content.ts b/src/content.ts
index 09137e0f..cb52983f 100644
--- a/src/content.ts
+++ b/src/content.ts
@@ -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) => {
diff --git a/src/js-components/previewBar.ts b/src/js-components/previewBar.ts
index 9f587b42..b93ba60f 100644
--- a/src/js-components/previewBar.ts
+++ b/src/js-components/previewBar.ts
@@ -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);
}
diff --git a/src/utils.ts b/src/utils.ts
index cda228fe..d7e6fcf8 100644
--- a/src/utils.ts
+++ b/src/utils.ts
@@ -440,8 +440,4 @@ export default class Utils {
Config.forceLocalUpdate("downvotedSegments");
}
-
- chaptersEnabled(): boolean {
- return Config.config.renderAsChapters && !!this.getCategorySelection("chapter");
- }
}