Fix normal chapter text sometimes disappearing

This commit is contained in:
Ajay
2022-09-18 21:34:45 -04:00
parent d044944946
commit edf0295cdf

View File

@@ -711,7 +711,15 @@ class PreviewBar {
} }
updateChapterText(segments: SponsorTime[], submittingSegments: SponsorTime[], currentTime: number): void { updateChapterText(segments: SponsorTime[], submittingSegments: SponsorTime[], currentTime: number): void {
if (!segments && submittingSegments?.length <= 0) return; if ((!segments || segments.length <= 0) && submittingSegments?.length <= 0) {
const chaptersContainer = this.getChaptersContainer();
const chapterButton = this.getChapterButton(chaptersContainer);
if (chapterButton.classList.contains("ytp-chapter-container-disabled")) {
chaptersContainer.style.display = "none";
}
return;
}
segments ??= []; segments ??= [];
if (submittingSegments?.length > 0) segments = segments.concat(submittingSegments); if (submittingSegments?.length > 0) segments = segments.concat(submittingSegments);
@@ -728,7 +736,7 @@ class PreviewBar {
* Adds the text to the chapters slot if not filled by default * Adds the text to the chapters slot if not filled by default
*/ */
private setActiveSegments(segments: SponsorTime[]): void { private setActiveSegments(segments: SponsorTime[]): void {
const chaptersContainer = document.querySelector(".ytp-chapter-container") as HTMLDivElement; const chaptersContainer = this.getChaptersContainer();
if (chaptersContainer) { if (chaptersContainer) {
if (segments.length > 0) { if (segments.length > 0) {
@@ -744,7 +752,7 @@ class PreviewBar {
} }
})[0]; })[0];
const chapterButton = chaptersContainer.querySelector("button.ytp-chapter-title") as HTMLButtonElement; const chapterButton = this.getChapterButton(chaptersContainer);
chapterButton.classList.remove("ytp-chapter-container-disabled"); chapterButton.classList.remove("ytp-chapter-container-disabled");
chapterButton.disabled = false; chapterButton.disabled = false;
@@ -774,6 +782,15 @@ class PreviewBar {
} }
} }
private getChaptersContainer(): HTMLElement {
return document.querySelector(".ytp-chapter-container") as HTMLElement;
}
private getChapterButton(chaptersContainer: HTMLElement): HTMLButtonElement {
return (chaptersContainer ?? this.getChaptersContainer())
.querySelector("button.ytp-chapter-title") as HTMLButtonElement;
}
remove(): void { remove(): void {
this.container.remove(); this.container.remove();