firefox support (kinda with manual permission set)

This commit is contained in:
Jorrin
2024-01-11 23:45:11 +01:00
parent 2eae1ede05
commit ef7234a36b
3 changed files with 23 additions and 10 deletions

View File

@@ -1,3 +1,5 @@
import { isChrome } from './extension';
export function queryCurrentDomain(cb: (domain: string | null) => void) {
const handle = (tabUrl: string | null) => {
if (!tabUrl) cb(null);
@@ -5,12 +7,12 @@ export function queryCurrentDomain(cb: (domain: string | null) => void) {
};
const ops = { active: true, currentWindow: true } as const;
if (chrome) chrome.tabs.query(ops).then((tabs) => handle(tabs[0]?.url));
if (isChrome()) chrome.tabs.query(ops).then((tabs) => handle(tabs[0]?.url));
else browser.tabs.query(ops).then((tabs) => handle(tabs[0]?.url));
}
export function listenToTabChanges(cb: () => void) {
if (chrome) {
if (isChrome()) {
chrome.tabs.onActivated.addListener(cb);
chrome.tabs.onUpdated.addListener(cb);
} else if (browser) {
@@ -20,7 +22,7 @@ export function listenToTabChanges(cb: () => void) {
}
export function stopListenToTabChanges(cb: () => void) {
if (chrome) {
if (isChrome()) {
chrome.tabs.onActivated.removeListener(cb);
chrome.tabs.onUpdated.removeListener(cb);
} else if (browser) {