mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-09 13:07:05 +03:00
Fix crashes on invidious
This commit is contained in:
@@ -2275,7 +2275,8 @@ function addPageListeners(): void {
|
|||||||
// inject into document
|
// inject into document
|
||||||
const docScript = document.createElement("script");
|
const docScript = document.createElement("script");
|
||||||
docScript.src = chrome.runtime.getURL("js/document.js");
|
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-start", resetValues);
|
||||||
document.addEventListener("yt-navigate-finish", refreshListners);
|
document.addEventListener("yt-navigate-finish", refreshListners);
|
||||||
|
|||||||
@@ -223,8 +223,10 @@ class PreviewBar {
|
|||||||
if (!this.segments) return;
|
if (!this.segments) return;
|
||||||
|
|
||||||
this.originalChapterBar = document.querySelector(".ytp-chapters-container:not(.sponsorBlockChapterBar)") as HTMLElement;
|
this.originalChapterBar = document.querySelector(".ytp-chapters-container:not(.sponsorBlockChapterBar)") as HTMLElement;
|
||||||
this.originalChapterBarBlocks = this.originalChapterBar.querySelectorAll(":scope > div") as NodeListOf<HTMLElement>
|
if (this.originalChapterBar) {
|
||||||
this.existingChapters = this.segments.filter((s) => s.source === SponsorSourceType.YouTube).sort((a, b) => a.segment[0] - b.segment[0])
|
this.originalChapterBarBlocks = this.originalChapterBar.querySelectorAll(":scope > div") as NodeListOf<HTMLElement>
|
||||||
|
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 }) => {
|
const sortedSegments = this.segments.sort(({ segment: a }, { segment: b }) => {
|
||||||
// Sort longer segments before short segments to make shorter segments render later
|
// 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]));
|
this.createChaptersBar(this.segments.sort((a, b) => a.segment[0] - b.segment[0]));
|
||||||
|
|
||||||
const chapterChevron = this.getChapterChevron();
|
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)) {
|
&& segment.source === SponsorSourceType.YouTube)) {
|
||||||
chapterChevron.style.removeProperty("display");
|
chapterChevron.style.removeProperty("display");
|
||||||
} else {
|
} else {
|
||||||
chapterChevron.style.display = "none";
|
chapterChevron.style.display = "none";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user