From 5b136f2da8f394c885eb4391a62f8cc30687bd84 Mon Sep 17 00:00:00 2001 From: Ajay Date: Sat, 3 Sep 2022 00:32:20 -0400 Subject: [PATCH] Fix crashes on invidious --- src/content.ts | 3 ++- src/js-components/previewBar.ts | 16 ++++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/content.ts b/src/content.ts index 0aa6e64d..40ea6705 100644 --- a/src/content.ts +++ b/src/content.ts @@ -2275,7 +2275,8 @@ function addPageListeners(): void { // inject into document const docScript = document.createElement("script"); docScript.src = chrome.runtime.getURL("js/document.js"); - (document.head || document.documentElement).appendChild(docScript); + // Not injected on invidious + (document.head || document.documentElement)?.appendChild(docScript); document.addEventListener("yt-navigate-start", resetValues); document.addEventListener("yt-navigate-finish", refreshListners); diff --git a/src/js-components/previewBar.ts b/src/js-components/previewBar.ts index 70f54300..56542daa 100644 --- a/src/js-components/previewBar.ts +++ b/src/js-components/previewBar.ts @@ -223,8 +223,10 @@ class PreviewBar { if (!this.segments) return; this.originalChapterBar = document.querySelector(".ytp-chapters-container:not(.sponsorBlockChapterBar)") as HTMLElement; - this.originalChapterBarBlocks = this.originalChapterBar.querySelectorAll(":scope > div") as NodeListOf - this.existingChapters = this.segments.filter((s) => s.source === SponsorSourceType.YouTube).sort((a, b) => a.segment[0] - b.segment[0]) + if (this.originalChapterBar) { + this.originalChapterBarBlocks = this.originalChapterBar.querySelectorAll(":scope > div") as NodeListOf + this.existingChapters = this.segments.filter((s) => s.source === SponsorSourceType.YouTube).sort((a, b) => a.segment[0] - b.segment[0]); + } const sortedSegments = this.segments.sort(({ segment: a }, { segment: b }) => { // Sort longer segments before short segments to make shorter segments render later @@ -239,11 +241,13 @@ class PreviewBar { this.createChaptersBar(this.segments.sort((a, b) => a.segment[0] - b.segment[0])); const chapterChevron = this.getChapterChevron(); - if (this.segments.some((segment) => segment.actionType !== ActionType.Chapter + if (chapterChevron) { + if (this.segments.some((segment) => segment.actionType !== ActionType.Chapter && segment.source === SponsorSourceType.YouTube)) { - chapterChevron.style.removeProperty("display"); - } else { - chapterChevron.style.display = "none"; + chapterChevron.style.removeProperty("display"); + } else { + chapterChevron.style.display = "none"; + } } }