aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAjay <[email protected]>2022-09-16 01:49:50 -0400
committerAjay <[email protected]>2022-09-16 01:49:50 -0400
commit56611598b2f498d4a675ab7cee6075408f5a88a8 (patch)
tree710c267621d66d94608ae0db8513db6524c1c8af
parent23e0666569fc31c0f9ff1857ed9bfbae7ab02032 (diff)
downloadSponsorBlock-56611598b2f498d4a675ab7cee6075408f5a88a8.tar.gz
SponsorBlock-56611598b2f498d4a675ab7cee6075408f5a88a8.zip
Fix filtered chapter group generation
-rw-r--r--src/js-components/previewBar.ts33
1 files changed, 20 insertions, 13 deletions
diff --git a/src/js-components/previewBar.ts b/src/js-components/previewBar.ts
index f4c3cf9c..308e066f 100644
--- a/src/js-components/previewBar.ts
+++ b/src/js-components/previewBar.ts
@@ -313,19 +313,6 @@ class PreviewBar {
// Merge overlapping chapters
this.unfilteredChapterGroups = this.createChapterRenderGroups(segments);
- const filteredSegments = segments?.filter((segment) => this.chapterFilter(segment));
- if (filteredSegments && filteredSegments.length !== segments.length) {
- this.chapterGroups = this.createChapterRenderGroups(filteredSegments).filter((segment) => this.chapterGroupFilter(segment));
-
- // Fix missing sections due to filtered segments
- for (let i = 1; i < this.chapterGroups.length; i++) {
- if (this.chapterGroups[i].segment[0] !== this.chapterGroups[i - 1].segment[1]) {
- this.chapterGroups[i - 1].segment[1] = this.chapterGroups[i].segment[0]
- }
- }
- } else {
- this.chapterGroups = this.unfilteredChapterGroups;
- }
if (segments.every((segments) => segments.source === SponsorSourceType.YouTube)
|| (!Config.config.renderSegmentsAsChapters
@@ -337,6 +324,26 @@ class PreviewBar {
return;
}
+ const filteredSegments = segments?.filter((segment) => this.chapterFilter(segment));
+ if (filteredSegments) {
+ let groups = this.unfilteredChapterGroups;
+ if (filteredSegments.length !== segments.length) {
+ groups = this.createChapterRenderGroups(filteredSegments);
+ }
+ this.chapterGroups = groups.filter((segment) => this.chapterGroupFilter(segment));
+
+ if (groups.length !== this.chapterGroups.length) {
+ // Fix missing sections due to filtered segments
+ for (let i = 1; i < this.chapterGroups.length; i++) {
+ if (this.chapterGroups[i].segment[0] !== this.chapterGroups[i - 1].segment[1]) {
+ this.chapterGroups[i - 1].segment[1] = this.chapterGroups[i].segment[0]
+ }
+ }
+ }
+ } else {
+ this.chapterGroups = this.unfilteredChapterGroups;
+ }
+
// Create it from cloning
let createFromScratch = false;
if (!this.customChaptersBar || !this.progressBar.contains(this.customChaptersBar)) {