fix: add global context type

This commit is contained in:
Gabe
2025-11-22 01:36:03 +08:00
parent 0705e8a65a
commit fa6f68fec3
7 changed files with 36 additions and 5 deletions

View File

@@ -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;