mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2024-11-12 18:04:20 +01:00
Reimport chapters if they are found to have changed
This commit is contained in:
parent
85e3d3bc18
commit
4729268083
3 changed files with 12 additions and 3 deletions
|
@ -511,7 +511,7 @@ function createPreviewBar(): void {
|
||||||
|
|
||||||
if (el) {
|
if (el) {
|
||||||
const chapterVote = new ChapterVote(voteAsync);
|
const chapterVote = new ChapterVote(voteAsync);
|
||||||
previewBar = new PreviewBar(el, onMobileYouTube, onInvidious, chapterVote);
|
previewBar = new PreviewBar(el, onMobileYouTube, onInvidious, chapterVote, () => importExistingChapters(false));
|
||||||
|
|
||||||
updatePreviewBar();
|
updatePreviewBar();
|
||||||
|
|
||||||
|
|
|
@ -46,6 +46,8 @@ class PreviewBar {
|
||||||
segments: PreviewBarSegment[] = [];
|
segments: PreviewBarSegment[] = [];
|
||||||
existingChapters: PreviewBarSegment[] = [];
|
existingChapters: PreviewBarSegment[] = [];
|
||||||
videoDuration = 0;
|
videoDuration = 0;
|
||||||
|
updateExistingChapters: () => void;
|
||||||
|
lastChapterUpdate = 0;
|
||||||
|
|
||||||
// For chapter bar
|
// For chapter bar
|
||||||
hoveredSection: HTMLElement;
|
hoveredSection: HTMLElement;
|
||||||
|
@ -58,7 +60,7 @@ class PreviewBar {
|
||||||
unfilteredChapterGroups: ChapterGroup[];
|
unfilteredChapterGroups: ChapterGroup[];
|
||||||
chapterGroups: 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;
|
if (test) return;
|
||||||
this.container = document.createElement('ul');
|
this.container = document.createElement('ul');
|
||||||
this.container.id = 'previewbar';
|
this.container.id = 'previewbar';
|
||||||
|
@ -67,6 +69,7 @@ class PreviewBar {
|
||||||
this.onMobileYouTube = onMobileYouTube;
|
this.onMobileYouTube = onMobileYouTube;
|
||||||
this.onInvidious = onInvidious;
|
this.onInvidious = onInvidious;
|
||||||
this.chapterVote = chapterVote;
|
this.chapterVote = chapterVote;
|
||||||
|
this.updateExistingChapters = updateExistingChapters;
|
||||||
|
|
||||||
this.updatePageElements();
|
this.updatePageElements();
|
||||||
this.createElement(parent);
|
this.createElement(parent);
|
||||||
|
@ -647,6 +650,12 @@ class PreviewBar {
|
||||||
|
|
||||||
cursor += sectionWidthDecimal;
|
cursor += sectionWidthDecimal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (sections.length !== 0 && sections.length !== this.existingChapters?.length
|
||||||
|
&& Date.now() - this.lastChapterUpdate > 3000) {
|
||||||
|
this.lastChapterUpdate = Date.now();
|
||||||
|
this.updateExistingChapters();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ import PreviewBar, { PreviewBarSegment } from "../src/js-components/previewBar";
|
||||||
describe("createChapterRenderGroups", () => {
|
describe("createChapterRenderGroups", () => {
|
||||||
let previewBar: PreviewBar;
|
let previewBar: PreviewBar;
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
previewBar = new PreviewBar(null, null, null, null, true);
|
previewBar = new PreviewBar(null, null, null, null, null, true);
|
||||||
})
|
})
|
||||||
|
|
||||||
it("Two unrelated times", () => {
|
it("Two unrelated times", () => {
|
||||||
|
|
Loading…
Reference in a new issue