forked from sourcegraph/sourcegraph-public-snapshot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontext.ts
More file actions
43 lines (34 loc) · 1023 Bytes
/
context.ts
File metadata and controls
43 lines (34 loc) · 1023 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
enum AppEnv {
Extension,
Page,
}
enum ScriptEnv {
Content,
Background,
Options,
}
interface AppContext {
appEnv: AppEnv
scriptEnv: ScriptEnv
}
function getContext(): AppContext {
const appEnv = window.SG_ENV === 'EXTENSION' ? AppEnv.Extension : AppEnv.Page
let scriptEnv: ScriptEnv = ScriptEnv.Content
if (appEnv === AppEnv.Extension) {
if (window.location.pathname.includes('options.html')) {
scriptEnv = ScriptEnv.Options
} else if (globalThis.browser && browser.runtime.getBackgroundPage) {
scriptEnv = ScriptEnv.Background
}
}
return {
appEnv,
scriptEnv,
}
}
const ctx = getContext()
export const isBackground = ctx.scriptEnv === ScriptEnv.Background
export const isOptions = ctx.scriptEnv === ScriptEnv.Options
export const isExtension = ctx.appEnv === AppEnv.Extension
export const isInPage = !isExtension
export const isPhabricator = Boolean(document.querySelector('.phabricator-wordmark'))