From cd2a8e750f9acf189831a9c0e562b1534ea88410 Mon Sep 17 00:00:00 2001 From: Marvin Alexander Krebber Date: Tue, 14 Jan 2025 08:51:48 +0100 Subject: [PATCH] const action redefine --- .gitignore | 2 ++ src/background/index.ts | 14 ++++++-------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index ba2c0383..7d01aa7f 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,8 @@ lerna-debug.log* node_modules dist dist-ssr +!dist/firefox/.gitkeep +!dist/chrome/.gitkeep *.local # Editor directories and files diff --git a/src/background/index.ts b/src/background/index.ts index f4a02cb7..7ac45e2f 100644 --- a/src/background/index.ts +++ b/src/background/index.ts @@ -39,22 +39,21 @@ console.log("background loaded") const Badges: { [key: string]: string | number } = {} const isMobile = /Android/i.test(navigator.userAgent) const isFirefox = !!browser?.webRequest -if (isFirefox) browser.browserAction.setBadgeBackgroundColor({ color: "#e60010" }) -else chrome.action.setBadgeBackgroundColor({ color: "#e60010" }) +const action = isFirefox ? browser.browserAction : chrome.action +action.setBadgeBackgroundColor({ color: "#e60010" }) // Increases Badge by 1 async function increaseBadge(tabId: number) { if (Badges?.[tabId] === undefined || typeof Badges[tabId] !== "number") { Badges[tabId] = 0 } Badges[tabId]++ - if (isFirefox) browser.browserAction.setBadgeText({ text: Badges[tabId].toString(), tabId }) - else chrome.action.setBadgeText({ text: Badges[tabId].toString(), tabId }) + console.log("increaseBadge") + action.setBadgeText({ text: Badges[tabId].toString(), tabId }) } // Set Badge to a specific value async function setBadgeText(text: string, tabId: number) { Badges[tabId] = text - if (isFirefox) browser.browserAction.setBadgeText({ text, tabId }) - else chrome.action.setBadgeText({ text, tabId }) + action.setBadgeText({ text, tabId }) } // onMessage @@ -107,8 +106,7 @@ onMessage("resetBadge", async (message: { sender: any }) => { const { sender } = message if (sender?.tabId) { if (Badges[sender.tabId]) delete Badges[sender.tabId] - if (isFirefox) browser.browserAction.setBadgeText({ text: "", tabId: sender.tabId }) - else chrome.action.setBadgeText({ text: "", tabId: sender.tabId }) + action.setBadgeText({ text: "", tabId: sender.tabId }) } }) if (isFirefox && isMobile) {