mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-09 04:57:09 +03:00
Fix chapter bar showing as empty sometimes
This commit is contained in:
@@ -227,7 +227,19 @@ class PreviewBar {
|
||||
|
||||
this.customChaptersBar?.remove();
|
||||
|
||||
if (segments?.length <= 0) {
|
||||
// Merge overlapping chapters
|
||||
const mergedSegments = segments?.filter((segment) => this.chapterFilter(segment))
|
||||
.reduce((acc, curr) => {
|
||||
if (acc.length === 0 || curr.segment[0] > acc[acc.length - 1].segment[1]) {
|
||||
acc.push(curr);
|
||||
} else {
|
||||
acc[acc.length - 1].segment[1] = Math.max(acc[acc.length - 1].segment[1], curr.segment[1]);
|
||||
}
|
||||
|
||||
return acc;
|
||||
}, [] as PreviewBarSegment[]);
|
||||
|
||||
if (mergedSegments?.length <= 0) {
|
||||
chapterBar.style.removeProperty("display");
|
||||
return;
|
||||
}
|
||||
@@ -241,18 +253,6 @@ class PreviewBar {
|
||||
this.customChaptersBar = newChapterBar;
|
||||
this.chaptersBarSegments = segments;
|
||||
|
||||
// Merge overlapping chapters
|
||||
const mergedSegments = segments.filter((segment) => this.chapterFilter(segment))
|
||||
.reduce((acc, curr) => {
|
||||
if (acc.length === 0 || curr.segment[0] > acc[acc.length - 1].segment[1]) {
|
||||
acc.push(curr);
|
||||
} else {
|
||||
acc[acc.length - 1].segment[1] = Math.max(acc[acc.length - 1].segment[1], curr.segment[1]);
|
||||
}
|
||||
|
||||
return acc;
|
||||
}, [] as PreviewBarSegment[]);
|
||||
|
||||
// Modify it to have sections for each segment
|
||||
for (let i = 0; i < mergedSegments.length; i++) {
|
||||
const segment = mergedSegments[i];
|
||||
|
||||
Reference in New Issue
Block a user