Skip to content

Commit

Permalink
const action redefine
Browse files Browse the repository at this point in the history
Dreamlinerm committed Jan 14, 2025
1 parent 424a912 commit cd2a8e7
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -10,6 +10,8 @@ lerna-debug.log*
node_modules
dist
dist-ssr
!dist/firefox/.gitkeep
!dist/chrome/.gitkeep
*.local

# Editor directories and files
14 changes: 6 additions & 8 deletions src/background/index.ts
Original file line number Diff line number Diff line change
@@ -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) {

0 comments on commit cd2a8e7

Please sign in to comment.