From d696692a235deb94890a9402383d9e858a8a7c0d Mon Sep 17 00:00:00 2001 From: VampireChicken12 Date: Mon, 13 Nov 2023 19:26:40 -0500 Subject: [PATCH] fix: Firefox wasn't recieving change events --- src/@types/index.ts | 1 + src/pages/content/index.tsx | 3 ++- src/pages/inject/index.tsx | 12 ++++++------ 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/@types/index.ts b/src/@types/index.ts index 270ff866..dfd7940c 100644 --- a/src/@types/index.ts +++ b/src/@types/index.ts @@ -103,6 +103,7 @@ export type RequestDataMessage = Prettify< >; export type ContentSendOnlyMessageMappings = { setRememberedVolume: SendDataMessage<"send_data", "content", "setRememberedVolume", { shortsPageVolume?: number; watchPageVolume?: number }>; + pageLoaded: SendDataMessage<"send_data", "content", "pageLoaded", undefined>; }; export type ExtensionSendOnlyMessageMappings = { volumeBoostChange: DataResponseMessage<"volumeBoostChange", { volumeBoostEnabled: boolean; volumeBoostAmount?: number }>; diff --git a/src/pages/content/index.tsx b/src/pages/content/index.tsx index da643e2b..0d89893f 100644 --- a/src/pages/content/index.tsx +++ b/src/pages/content/index.tsx @@ -11,7 +11,7 @@ import adjustVolumeOnScrollWheel from "@/src/features/scrollWheelVolumeControl"; import { promptUserToResumeVideo, setupVideoHistory } from "@/src/features/videoHistory"; import volumeBoost from "@/src/features/volumeBoost"; import eventManager from "@/utils/EventManager"; -import { browserColorLog, formatError, waitForSpecificMessage } from "@/utils/utilities"; +import { browserColorLog, formatError, sendContentOnlyMessage, waitForSpecificMessage } from "@/utils/utilities"; import type { ExtensionSendOnlyMessageMappings, Messages, YouTubePlayerDiv } from "@/src/@types"; import { enableHideScrollBar } from "@/src/features/hideScrollBar"; @@ -275,6 +275,7 @@ window.onload = async function () { } } }); + sendContentOnlyMessage("pageLoaded", undefined); }; window.onbeforeunload = function () { eventManager.removeAllEventListeners(); diff --git a/src/pages/inject/index.tsx b/src/pages/inject/index.tsx index 0c05baa1..1ea20760 100644 --- a/src/pages/inject/index.tsx +++ b/src/pages/inject/index.tsx @@ -31,12 +31,6 @@ document.documentElement.appendChild(script); }); sendExtensionMessage("options", "data_response", { options }); })(); -window.onload = () => { - chrome.storage.onChanged.addListener(storageListeners); -}; -window.onunload = () => { - chrome.storage.onChanged.removeListener(storageListeners); -}; /** * Listens for the "yte-message-from-youtube" event and handles incoming messages from the YouTube page. @@ -126,6 +120,12 @@ document.addEventListener("yte-message-from-youtube", async () => { }); break; } + case "pageLoaded": { + chrome.storage.onChanged.addListener(storageListeners); + window.onunload = () => { + chrome.storage.onChanged.removeListener(storageListeners); + }; + } } }); const storageListeners = async (changes: StorageChanges, areaName: string) => {