aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAjay <[email protected]>2022-10-11 17:59:46 -0400
committerAjay <[email protected]>2022-10-11 17:59:46 -0400
commit4729268083969af387cb9f302b4b8bc069bc840c (patch)
tree72d4a2087caf4155108dbb70e2ef66d1ec2e67c9
parent85e3d3bc1842c69de179eca529b4084b73f365b3 (diff)
downloadSponsorBlock-4729268083969af387cb9f302b4b8bc069bc840c.tar.gz
SponsorBlock-4729268083969af387cb9f302b4b8bc069bc840c.zip
Reimport chapters if they are found to have changed
-rw-r--r--src/content.ts2
-rw-r--r--src/js-components/previewBar.ts11
-rw-r--r--test/previewBar.test.ts2
3 files changed, 12 insertions, 3 deletions
diff --git a/src/content.ts b/src/content.ts
index 4cc55e6e..2c65e4d6 100644
--- a/src/content.ts
+++ b/src/content.ts
@@ -511,7 +511,7 @@ function createPreviewBar(): void {
if (el) {
const chapterVote = new ChapterVote(voteAsync);
- previewBar = new PreviewBar(el, onMobileYouTube, onInvidious, chapterVote);
+ previewBar = new PreviewBar(el, onMobileYouTube, onInvidious, chapterVote, () => importExistingChapters(false));
updatePreviewBar();
diff --git a/src/js-components/previewBar.ts b/src/js-components/previewBar.ts
index 46042c8c..84ebb155 100644
--- a/src/js-components/previewBar.ts
+++ b/src/js-components/previewBar.ts
@@ -46,6 +46,8 @@ class PreviewBar {
segments: PreviewBarSegment[] = [];
existingChapters: PreviewBarSegment[] = [];
videoDuration = 0;
+ updateExistingChapters: () => void;
+ lastChapterUpdate = 0;
// For chapter bar
hoveredSection: HTMLElement;
@@ -58,7 +60,7 @@ class PreviewBar {
unfilteredChapterGroups: ChapterGroup[];
chapterGroups: ChapterGroup[];
- constructor(parent: HTMLElement, onMobileYouTube: boolean, onInvidious: boolean, chapterVote: ChapterVote, test=false) {
+ constructor(parent: HTMLElement, onMobileYouTube: boolean, onInvidious: boolean, chapterVote: ChapterVote, updateExistingChapters: () => void, test=false) {
if (test) return;
this.container = document.createElement('ul');
this.container.id = 'previewbar';
@@ -67,6 +69,7 @@ class PreviewBar {
this.onMobileYouTube = onMobileYouTube;
this.onInvidious = onInvidious;
this.chapterVote = chapterVote;
+ this.updateExistingChapters = updateExistingChapters;
this.updatePageElements();
this.createElement(parent);
@@ -647,6 +650,12 @@ class PreviewBar {
cursor += sectionWidthDecimal;
}
+
+ if (sections.length !== 0 && sections.length !== this.existingChapters?.length
+ && Date.now() - this.lastChapterUpdate > 3000) {
+ this.lastChapterUpdate = Date.now();
+ this.updateExistingChapters();
+ }
}
}
diff --git a/test/previewBar.test.ts b/test/previewBar.test.ts
index a9083007..fbbbc39b 100644
--- a/test/previewBar.test.ts
+++ b/test/previewBar.test.ts
@@ -3,7 +3,7 @@ import PreviewBar, { PreviewBarSegment } from "../src/js-components/previewBar";
describe("createChapterRenderGroups", () => {
let previewBar: PreviewBar;
beforeEach(() => {
- previewBar = new PreviewBar(null, null, null, null, true);
+ previewBar = new PreviewBar(null, null, null, null, null, true);
})
it("Two unrelated times", () => {