From 8383699a6885348302420938353aa5be0eadb5df Mon Sep 17 00:00:00 2001 From: Ajay Date: Sat, 21 Jan 2023 16:18:25 -0500 Subject: [PATCH] Fix chapter name sometimes disappearing --- src/js-components/previewBar.ts | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/js-components/previewBar.ts b/src/js-components/previewBar.ts index 0afb7f96..9016a4df 100644 --- a/src/js-components/previewBar.ts +++ b/src/js-components/previewBar.ts @@ -814,7 +814,16 @@ class PreviewBar { chapterButton.disabled = false; const chapterTitle = chaptersContainer.querySelector(".ytp-chapter-title-content") as HTMLDivElement; - chapterTitle.innerText = chosenSegment.description || shortCategoryName(chosenSegment.category); + chapterTitle.innerText = ""; + + const chapterCustomText = (chapterTitle.querySelector(".sponsorChapterText") || (() => { + const elem = document.createElement("div"); + chapterTitle.appendChild(elem); + elem.classList.add("sponsorChapterText"); + return elem; + })()) as HTMLDivElement; + chapterCustomText.innerText = chosenSegment.description || shortCategoryName(chosenSegment.category); + if (chosenSegment.actionType !== ActionType.Chapter) { chapterTitle.classList.add("sponsorBlock-segment-title"); } else { @@ -838,7 +847,13 @@ class PreviewBar { this.chapterVote.setVisibility(false); } } else { - chaptersContainer.style.display = "none"; + chaptersContainer.querySelector(".sponsorChapterText")?.remove(); + const chapterTitle = chaptersContainer.querySelector(".ytp-chapter-title-content") as HTMLDivElement; + if (chapterTitle.innerText === "") { + chaptersContainer.style.display = "none"; + } else { + chaptersContainer.style.removeProperty("display"); + } this.chapterVote.setVisibility(false); } }