aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/content.ts
diff options
context:
space:
mode:
authorAjay <[email protected]>2023-07-28 16:30:28 -0400
committerAjay <[email protected]>2023-07-28 16:30:28 -0400
commit40695456032c420e25663c025a6901eba50a0361 (patch)
tree437ce4ef7299ec33e47fb937b30fd175721cf8c0 /src/content.ts
parentdb9fc11f13693b9f5911ce0ae3c4787e2219ace0 (diff)
downloadSponsorBlock-40695456032c420e25663c025a6901eba50a0361.tar.gz
SponsorBlock-40695456032c420e25663c025a6901eba50a0361.zip
Support live updates on firefox
Diffstat (limited to 'src/content.ts')
-rw-r--r--src/content.ts49
1 files changed, 33 insertions, 16 deletions
diff --git a/src/content.ts b/src/content.ts
index 28c87aad..555401e2 100644
--- a/src/content.ts
+++ b/src/content.ts
@@ -45,6 +45,9 @@ import * as documentScript from "../dist/js/document.js";
import { Tooltip } from "./render/Tooltip";
import { isDeArrowInstalled } from "./utils/crossExtension";
import { runCompatibilityChecks } from "./utils/compatibility";
+import { cleanPage } from "./utils/pageCleaner";
+
+cleanPage();
const utils = new Utils();
@@ -1356,18 +1359,20 @@ async function channelIDChange(channelIDInfo: ChannelIDInfo) {
}
function videoElementChange(newVideo: boolean): void {
- if (newVideo) {
- setupVideoListeners();
- setupSkipButtonControlBar();
- setupCategoryPill();
- }
-
- checkPreviewbarState();
-
- // Incase the page is still transitioning, check again in a few seconds
- setTimeout(checkPreviewbarState, 100);
- setTimeout(checkPreviewbarState, 1000);
- setTimeout(checkPreviewbarState, 5000);
+ waitFor(() => Config.isReady()).then(() => {
+ if (newVideo) {
+ setupVideoListeners();
+ setupSkipButtonControlBar();
+ setupCategoryPill();
+ }
+
+ checkPreviewbarState();
+
+ // Incase the page is still transitioning, check again in a few seconds
+ setTimeout(checkPreviewbarState, 100);
+ setTimeout(checkPreviewbarState, 1000);
+ setTimeout(checkPreviewbarState, 5000);
+ })
}
function checkPreviewbarState(): void {
@@ -2331,11 +2336,17 @@ function previousChapter(): void {
function addHotkeyListener(): void {
document.addEventListener("keydown", hotkeyListener);
- document.addEventListener("DOMContentLoaded", () => {
+ const onLoad = () => {
// Allow us to stop propagation to YouTube by being deeper
document.removeEventListener("keydown", hotkeyListener);
document.body.addEventListener("keydown", hotkeyListener);
- });
+ };
+
+ if (document.readyState === "complete") {
+ onLoad();
+ } else {
+ document.addEventListener("DOMContentLoaded", onLoad);
+ }
}
function hotkeyListener(e: KeyboardEvent): void {
@@ -2392,7 +2403,7 @@ function hotkeyListener(e: KeyboardEvent): void {
*/
function addCSS() {
if (!isFirefoxOrSafari() && Config.config.invidiousInstances.includes(new URL(document.URL).hostname)) {
- window.addEventListener("DOMContentLoaded", () => {
+ const onLoad = () => {
const head = document.getElementsByTagName("head")[0];
for (const file of utils.css) {
@@ -2404,7 +2415,13 @@ function addCSS() {
head.appendChild(fileref);
}
- });
+ };
+
+ if (document.readyState === "complete") {
+ onLoad();
+ } else {
+ document.addEventListener("DOMContentLoaded", onLoad);
+ }
}
}