fix: add global context type
This commit is contained in:
@@ -14,7 +14,29 @@ function _browser() {
|
||||
|
||||
export const browser = _browser();
|
||||
|
||||
export const isBg = () => globalThis?.ContextType === "BACKGROUND";
|
||||
export const getContext = () => {
|
||||
const context = globalThis.__KISS_CONTEXT__;
|
||||
if (context) return context;
|
||||
|
||||
// if (typeof window === "undefined" || typeof document === "undefined") {
|
||||
// return "background";
|
||||
// }
|
||||
|
||||
// const extensionOrigin = browser.runtime.getURL("");
|
||||
// if (!window.location.href.startsWith(extensionOrigin)) {
|
||||
// return "content";
|
||||
// }
|
||||
|
||||
// const pathname = window.location.pathname;
|
||||
// if (pathname.includes("popup")) return "popup";
|
||||
// if (pathname.includes("options")) return "options";
|
||||
// if (pathname.includes("sidepanel")) return "sidepanel";
|
||||
// if (pathname.includes("background")) return "background";
|
||||
|
||||
return "undefined";
|
||||
};
|
||||
|
||||
export const isBg = () => getContext() === "background";
|
||||
|
||||
export const isBuiltinAIAvailable =
|
||||
"LanguageDetector" in globalThis && "Translator" in globalThis;
|
||||
|
||||
Reference in New Issue
Block a user