mirror of
https://github.com/movie-web/extension.git
synced 2025-09-13 17:03:25 +00:00
firefox support (kinda with manual permission set)
This commit is contained in:
3
src/utils/extension.ts
Normal file
3
src/utils/extension.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export const isChrome = () => {
|
||||
return chrome.runtime.getURL('').startsWith('chrome-extension://');
|
||||
};
|
@@ -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) {
|
||||
|
Reference in New Issue
Block a user