Skip to content

Commit 4729268

Browse files
committed
Reimport chapters if they are found to have changed
1 parent 85e3d3b commit 4729268

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

src/content.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ function createPreviewBar(): void {
511511

512512
if (el) {
513513
const chapterVote = new ChapterVote(voteAsync);
514-
previewBar = new PreviewBar(el, onMobileYouTube, onInvidious, chapterVote);
514+
previewBar = new PreviewBar(el, onMobileYouTube, onInvidious, chapterVote, () => importExistingChapters(false));
515515

516516
updatePreviewBar();
517517

src/js-components/previewBar.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ class PreviewBar {
4646
segments: PreviewBarSegment[] = [];
4747
existingChapters: PreviewBarSegment[] = [];
4848
videoDuration = 0;
49+
updateExistingChapters: () => void;
50+
lastChapterUpdate = 0;
4951

5052
// For chapter bar
5153
hoveredSection: HTMLElement;
@@ -58,7 +60,7 @@ class PreviewBar {
5860
unfilteredChapterGroups: ChapterGroup[];
5961
chapterGroups: ChapterGroup[];
6062

61-
constructor(parent: HTMLElement, onMobileYouTube: boolean, onInvidious: boolean, chapterVote: ChapterVote, test=false) {
63+
constructor(parent: HTMLElement, onMobileYouTube: boolean, onInvidious: boolean, chapterVote: ChapterVote, updateExistingChapters: () => void, test=false) {
6264
if (test) return;
6365
this.container = document.createElement('ul');
6466
this.container.id = 'previewbar';
@@ -67,6 +69,7 @@ class PreviewBar {
6769
this.onMobileYouTube = onMobileYouTube;
6870
this.onInvidious = onInvidious;
6971
this.chapterVote = chapterVote;
72+
this.updateExistingChapters = updateExistingChapters;
7073

7174
this.updatePageElements();
7275
this.createElement(parent);
@@ -647,6 +650,12 @@ class PreviewBar {
647650

648651
cursor += sectionWidthDecimal;
649652
}
653+
654+
if (sections.length !== 0 && sections.length !== this.existingChapters?.length
655+
&& Date.now() - this.lastChapterUpdate > 3000) {
656+
this.lastChapterUpdate = Date.now();
657+
this.updateExistingChapters();
658+
}
650659
}
651660
}
652661

test/previewBar.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import PreviewBar, { PreviewBarSegment } from "../src/js-components/previewBar";
33
describe("createChapterRenderGroups", () => {
44
let previewBar: PreviewBar;
55
beforeEach(() => {
6-
previewBar = new PreviewBar(null, null, null, null, true);
6+
previewBar = new PreviewBar(null, null, null, null, null, true);
77
})
88

99
it("Two unrelated times", () => {

0 commit comments

Comments
 (0)