adnbn 0.0.30 → 0.0.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/index.cjs +93 -8
- package/dist/browser/index.cjs.map +1 -1
- package/dist/browser/index.d.mts +19 -2
- package/dist/browser/index.d.ts +19 -2
- package/dist/browser/index.js +82 -8
- package/dist/browser/index.js.map +1 -1
- package/dist/cli/index.cjs +294 -3265
- package/dist/cli/index.cjs.map +1 -1
- package/dist/client/index.cjs +58 -0
- package/dist/client/index.cjs.map +1 -0
- package/dist/client/index.d.mts +6 -0
- package/dist/client/index.d.ts +6 -0
- package/dist/client/index.js +56 -0
- package/dist/client/index.js.map +1 -0
- package/dist/command-ZfDymEyz.d.mts +76 -0
- package/dist/command-ZfDymEyz.d.ts +76 -0
- package/dist/index.cjs +9 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +11 -207
- package/dist/index.d.ts +11 -207
- package/dist/index.js +8 -2
- package/dist/index.js.map +1 -1
- package/dist/manifest-4vEG2PA3.d.mts +140 -0
- package/dist/manifest-D52-CONc.d.ts +140 -0
- package/package.json +15 -12
package/dist/browser/index.cjs
CHANGED
|
@@ -6,24 +6,34 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
|
6
6
|
|
|
7
7
|
var _isUndefined__default = /*#__PURE__*/_interopDefault(_isUndefined);
|
|
8
8
|
|
|
9
|
+
// src/browser/runtime.ts
|
|
10
|
+
|
|
11
|
+
// src/core/env.ts
|
|
12
|
+
var getEnv = (key, defaults) => {
|
|
13
|
+
const env = process.env;
|
|
14
|
+
return env[key] ?? defaults;
|
|
15
|
+
};
|
|
16
|
+
|
|
9
17
|
// src/browser/env.ts
|
|
10
18
|
var browser = () => {
|
|
11
19
|
return chrome;
|
|
12
20
|
};
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
var
|
|
17
|
-
|
|
18
|
-
return () => commands.onCommand.removeListener(callback);
|
|
21
|
+
var getBrowser = () => {
|
|
22
|
+
return getEnv("BROWSER", "chrome" /* Chrome */);
|
|
23
|
+
};
|
|
24
|
+
var isBrowser = (browser2) => {
|
|
25
|
+
return getBrowser() === browser2;
|
|
19
26
|
};
|
|
27
|
+
|
|
28
|
+
// src/browser/runtime.ts
|
|
20
29
|
var runtime = browser().runtime;
|
|
21
30
|
var backgroundPaths = [
|
|
22
31
|
"/_generated_background_page.html"
|
|
23
32
|
];
|
|
24
33
|
var getUrl = (path) => runtime.getURL(path);
|
|
25
34
|
var getManifest = () => runtime.getManifest();
|
|
26
|
-
var
|
|
35
|
+
var getManifestVersion = () => getManifest().manifest_version;
|
|
36
|
+
var isManifestVersion3 = () => getManifestVersion() === 3;
|
|
27
37
|
var getId = () => runtime.id;
|
|
28
38
|
var isBackground = () => {
|
|
29
39
|
if (!getId()) {
|
|
@@ -38,13 +48,88 @@ var isBackground = () => {
|
|
|
38
48
|
}
|
|
39
49
|
return !_isUndefined__default.default(window) && backgroundPaths.includes(location.pathname);
|
|
40
50
|
};
|
|
51
|
+
var throwRuntimeError = () => {
|
|
52
|
+
const error = runtime.lastError;
|
|
53
|
+
if (error) {
|
|
54
|
+
throw new Error(error.message);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
// src/browser/action.ts
|
|
59
|
+
var getAction = () => isManifestVersion3() ? browser().action : browser().browserAction;
|
|
60
|
+
var setActionBadgeText = (tabId, text) => new Promise((resolve, reject) => {
|
|
61
|
+
const details = { text: text.toString(), tabId };
|
|
62
|
+
getAction().setBadgeText(details, () => {
|
|
63
|
+
try {
|
|
64
|
+
throwRuntimeError();
|
|
65
|
+
resolve();
|
|
66
|
+
} catch (e) {
|
|
67
|
+
reject(e);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
var clearActionBadgeText = (tabId) => setActionBadgeText(tabId, "");
|
|
72
|
+
var setActionBadgeBgColor = (tabId, color) => new Promise((resolve, reject) => {
|
|
73
|
+
const details = { color, tabId };
|
|
74
|
+
getAction().setBadgeBackgroundColor(details, () => {
|
|
75
|
+
try {
|
|
76
|
+
throwRuntimeError();
|
|
77
|
+
resolve();
|
|
78
|
+
} catch (e) {
|
|
79
|
+
reject(e);
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
var setActionBadgeTextColor = async (tabId, color) => {
|
|
84
|
+
if (!isManifestVersion3()) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
const action = getAction();
|
|
88
|
+
await action.setBadgeTextColor({ color, tabId });
|
|
89
|
+
};
|
|
90
|
+
var setActionIcon = (tabId, icon) => new Promise((resolve, reject) => {
|
|
91
|
+
getAction().setIcon({ tabId, path: icon }, () => {
|
|
92
|
+
try {
|
|
93
|
+
throwRuntimeError();
|
|
94
|
+
resolve();
|
|
95
|
+
} catch (e) {
|
|
96
|
+
reject(e);
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
var getActionDefaultPopup = () => {
|
|
101
|
+
const manifest = getManifest();
|
|
102
|
+
return isManifestVersion3() ? manifest.action.default_popup : manifest.browser_action.default_popup;
|
|
103
|
+
};
|
|
104
|
+
var onActionClicked = (callback) => {
|
|
105
|
+
getAction().onClicked.addListener(callback);
|
|
106
|
+
return () => getAction().onClicked.removeListener(callback);
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
// src/browser/command.ts
|
|
110
|
+
var commands = browser().commands;
|
|
111
|
+
var onCommand = (callback) => {
|
|
112
|
+
commands.onCommand.addListener(callback);
|
|
113
|
+
return () => commands.onCommand.removeListener(callback);
|
|
114
|
+
};
|
|
41
115
|
|
|
42
116
|
exports.browser = browser;
|
|
117
|
+
exports.clearActionBadgeText = clearActionBadgeText;
|
|
118
|
+
exports.getActionDefaultPopup = getActionDefaultPopup;
|
|
119
|
+
exports.getBrowser = getBrowser;
|
|
43
120
|
exports.getId = getId;
|
|
44
121
|
exports.getManifest = getManifest;
|
|
122
|
+
exports.getManifestVersion = getManifestVersion;
|
|
45
123
|
exports.getUrl = getUrl;
|
|
46
|
-
exports.getVersion = getVersion;
|
|
47
124
|
exports.isBackground = isBackground;
|
|
125
|
+
exports.isBrowser = isBrowser;
|
|
126
|
+
exports.isManifestVersion3 = isManifestVersion3;
|
|
127
|
+
exports.onActionClicked = onActionClicked;
|
|
48
128
|
exports.onCommand = onCommand;
|
|
129
|
+
exports.setActionBadgeBgColor = setActionBadgeBgColor;
|
|
130
|
+
exports.setActionBadgeText = setActionBadgeText;
|
|
131
|
+
exports.setActionBadgeTextColor = setActionBadgeTextColor;
|
|
132
|
+
exports.setActionIcon = setActionIcon;
|
|
133
|
+
exports.throwRuntimeError = throwRuntimeError;
|
|
49
134
|
//# sourceMappingURL=index.cjs.map
|
|
50
135
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/
|
|
1
|
+
{"version":3,"sources":["../../src/core/env.ts","../../src/browser/env.ts","../../src/browser/runtime.ts","../../src/browser/action.ts","../../src/browser/command.ts"],"names":["browser","_isUndefined"],"mappings":";;;;;;;;;;;AAGO,IAAM,MAAA,GAGT,CAAC,GAAA,EAAa,QAAsB,KAAA;AACpC,EAAA,MAAM,MAAM,OAAQ,CAAA,GAAA;AAEpB,EAAQ,OAAA,GAAA,CAAI,GAAG,CAAK,IAAA,QAAA;AACxB,CAAA;;;ACPO,IAAM,UAAU,MAAqB;AACxC,EAAO,OAAA,MAAA;AACX;AAEO,IAAM,aAAa,MAAe;AACrC,EAAA,OAAO,OAAO,SAAyB,EAAA,QAAA,cAAA;AAC3C;AAEa,IAAA,SAAA,GAAY,CAACA,QAA8B,KAAA;AACpD,EAAA,OAAO,YAAiBA,KAAAA,QAAAA;AAC5B;;;ACNA,IAAM,OAAA,GAAU,SAAU,CAAA,OAAA;AAE1B,IAAM,eAAkB,GAAA;AAAA,EACpB;AACJ,CAAA;AAEO,IAAM,MAAS,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,CAAA,aAAA,GAAgB,SAAS,cAAe,CAAA,aAAA;AAC1F;AAEa,IAAA,eAAA,GAAkB,CAAC,QAAoF,KAAA;AAChH,EAAU,SAAA,EAAA,CAAE,SAAU,CAAA,WAAA,CAAY,QAAQ,CAAA;AAE1C,EAAA,OAAO,MAAM,SAAA,EAAY,CAAA,SAAA,CAAU,eAAe,QAAQ,CAAA;AAC9D;;;AC3EA,IAAM,QAAA,GAAW,SAAU,CAAA,QAAA;AAEd,IAAA,SAAA,GAAY,CAAC,QAAsF,KAAA;AAC5G,EAAS,QAAA,CAAA,SAAA,CAAU,YAAY,QAAQ,CAAA;AAEvC,EAAA,OAAO,MAAM,QAAA,CAAS,SAAU,CAAA,cAAA,CAAe,QAAQ,CAAA;AAC3D","file":"index.cjs","sourcesContent":["import {Browser} from \"@typing/browser\";\nimport {ManifestVersion} from \"@typing/manifest\";\n\nexport const getEnv: {\n <T extends string>(key: string): T | undefined;\n <T extends string, D>(key: string, defaults: D): T | D;\n} = (key: string, defaults?: string) => {\n const env = process.env;\n\n return (env[key] ?? defaults) as any;\n};\n\nexport const getBrowser = (): Browser => {\n const browser = getEnv<Browser>('BROWSER');\n\n if (browser === undefined) {\n throw new Error('Browser is not defined');\n }\n\n return browser;\n}\n\nexport const getManifestVersion = (): ManifestVersion => {\n const manifestVersion = getEnv('MANIFEST_VERSION', '3');\n\n return parseInt(manifestVersion) as ManifestVersion;\n}","import {Browser} from \"@typing/browser\";\nimport {getEnv} from \"@core/env\";\n\nexport const browser = (): typeof chrome => {\n return chrome;\n}\n\nexport const getBrowser = (): Browser => {\n return getEnv('BROWSER', Browser.Chrome);\n}\n\nexport const isBrowser = (browser: Browser): boolean => {\n return getBrowser() === browser;\n}","import _isUndefined from \"lodash/isUndefined\";\n\nimport {browser} from \"./env\";\nimport {ManifestVersion} from \"@typing/manifest\";\n\ntype Manifest = chrome.runtime.Manifest;\n\nconst runtime = browser().runtime;\n\nconst backgroundPaths = [\n '/_generated_background_page.html',\n];\n\nexport const getUrl = (path: string) => runtime.getURL(path);\n\nexport const getManifest = (): Manifest => runtime.getManifest();\n\nexport const getManifestVersion = (): ManifestVersion => getManifest().manifest_version;\n\nexport const isManifestVersion3 = (): boolean => getManifestVersion() === 3;\n\nexport const getId = (): string => runtime.id;\n\nexport const isBackground = (): boolean => {\n if (!getId()) {\n return false;\n }\n\n const manifest = getManifest();\n\n if (!manifest.background) {\n return false;\n }\n\n if (manifest.manifest_version === 3) {\n return _isUndefined(window);\n }\n\n return !_isUndefined(window) && backgroundPaths.includes(location.pathname);\n}\n\nexport const throwRuntimeError = (): void => {\n const error = runtime.lastError;\n\n if (error) {\n throw new Error(error.message);\n }\n}","import {getManifest, isManifestVersion3, throwRuntimeError} from \"./runtime\";\nimport {browser} from \"./env\";\n\ntype BadgeBackgroundColorDetails = chrome.browserAction.BadgeBackgroundColorDetails;\ntype BadgeTextDetails = chrome.action.BadgeTextDetails;\ntype BrowserAction = typeof chrome.action;\n\nconst getAction = () => isManifestVersion3() ? browser().action : browser().browserAction;\n\nexport const setActionBadgeText = (tabId: number, text: string | number) => new Promise<void>((resolve, reject) => {\n const details: BadgeTextDetails = {text: text.toString(), tabId};\n\n getAction().setBadgeText(details, () => {\n try {\n throwRuntimeError();\n\n resolve();\n } catch (e) {\n reject(e);\n }\n });\n});\n\nexport const clearActionBadgeText = (tabId: number): Promise<void> => setActionBadgeText(tabId, '');\n\nexport const setActionBadgeBgColor = (tabId: number, color: BadgeBackgroundColorDetails['color']) => new Promise<void>((resolve, reject) => {\n const details: BadgeBackgroundColorDetails = {color, tabId};\n\n getAction().setBadgeBackgroundColor(details, () => {\n try {\n throwRuntimeError();\n\n resolve();\n } catch (e) {\n reject(e);\n }\n });\n});\n\nexport const setActionBadgeTextColor = async (\n tabId: number,\n color: BadgeBackgroundColorDetails['color']\n): Promise<void> => {\n if (!isManifestVersion3()) {\n return;\n }\n\n const action = getAction() as BrowserAction;\n\n await action.setBadgeTextColor({color, tabId});\n};\n\nexport const setActionIcon = (\n tabId: number,\n icon: string | Record<string, string>\n): Promise<void> => new Promise<void>((resolve, reject) => {\n getAction().setIcon({tabId, path: icon}, () => {\n try {\n throwRuntimeError();\n\n resolve();\n } catch (e) {\n reject(e);\n }\n });\n});\n\nexport const getActionDefaultPopup = (): string => {\n const manifest = getManifest();\n\n return isManifestVersion3() ? manifest.action.default_popup : manifest.browser_action.default_popup;\n}\n\nexport const onActionClicked = (callback: Parameters<typeof chrome.action.onClicked.addListener>[0]): () => void => {\n getAction().onClicked.addListener(callback);\n\n return () => getAction().onClicked.removeListener(callback);\n}","import {browser} from \"./env\";\n\nconst commands = browser().commands;\n\nexport const onCommand = (callback: Parameters<typeof chrome.commands.onCommand.addListener>[0]): () => void => {\n commands.onCommand.addListener(callback);\n\n return () => commands.onCommand.removeListener(callback);\n}"]}
|
package/dist/browser/index.d.mts
CHANGED
|
@@ -1,12 +1,29 @@
|
|
|
1
|
+
import { B as Browser } from '../command-ZfDymEyz.mjs';
|
|
2
|
+
import { a as ManifestVersion } from '../manifest-4vEG2PA3.mjs';
|
|
3
|
+
import 'utility-types';
|
|
4
|
+
|
|
5
|
+
type BadgeBackgroundColorDetails = chrome.browserAction.BadgeBackgroundColorDetails;
|
|
6
|
+
declare const setActionBadgeText: (tabId: number, text: string | number) => Promise<void>;
|
|
7
|
+
declare const clearActionBadgeText: (tabId: number) => Promise<void>;
|
|
8
|
+
declare const setActionBadgeBgColor: (tabId: number, color: BadgeBackgroundColorDetails["color"]) => Promise<void>;
|
|
9
|
+
declare const setActionBadgeTextColor: (tabId: number, color: BadgeBackgroundColorDetails["color"]) => Promise<void>;
|
|
10
|
+
declare const setActionIcon: (tabId: number, icon: string | Record<string, string>) => Promise<void>;
|
|
11
|
+
declare const getActionDefaultPopup: () => string;
|
|
12
|
+
declare const onActionClicked: (callback: Parameters<typeof chrome.action.onClicked.addListener>[0]) => () => void;
|
|
13
|
+
|
|
1
14
|
declare const onCommand: (callback: Parameters<typeof chrome.commands.onCommand.addListener>[0]) => () => void;
|
|
2
15
|
|
|
3
16
|
declare const browser: () => typeof chrome;
|
|
17
|
+
declare const getBrowser: () => Browser;
|
|
18
|
+
declare const isBrowser: (browser: Browser) => boolean;
|
|
4
19
|
|
|
5
20
|
type Manifest = chrome.runtime.Manifest;
|
|
6
21
|
declare const getUrl: (path: string) => string;
|
|
7
22
|
declare const getManifest: () => Manifest;
|
|
8
|
-
declare const
|
|
23
|
+
declare const getManifestVersion: () => ManifestVersion;
|
|
24
|
+
declare const isManifestVersion3: () => boolean;
|
|
9
25
|
declare const getId: () => string;
|
|
10
26
|
declare const isBackground: () => boolean;
|
|
27
|
+
declare const throwRuntimeError: () => void;
|
|
11
28
|
|
|
12
|
-
export { browser, getId, getManifest,
|
|
29
|
+
export { browser, clearActionBadgeText, getActionDefaultPopup, getBrowser, getId, getManifest, getManifestVersion, getUrl, isBackground, isBrowser, isManifestVersion3, onActionClicked, onCommand, setActionBadgeBgColor, setActionBadgeText, setActionBadgeTextColor, setActionIcon, throwRuntimeError };
|
package/dist/browser/index.d.ts
CHANGED
|
@@ -1,12 +1,29 @@
|
|
|
1
|
+
import { B as Browser } from '../command-ZfDymEyz.js';
|
|
2
|
+
import { a as ManifestVersion } from '../manifest-D52-CONc.js';
|
|
3
|
+
import 'utility-types';
|
|
4
|
+
|
|
5
|
+
type BadgeBackgroundColorDetails = chrome.browserAction.BadgeBackgroundColorDetails;
|
|
6
|
+
declare const setActionBadgeText: (tabId: number, text: string | number) => Promise<void>;
|
|
7
|
+
declare const clearActionBadgeText: (tabId: number) => Promise<void>;
|
|
8
|
+
declare const setActionBadgeBgColor: (tabId: number, color: BadgeBackgroundColorDetails["color"]) => Promise<void>;
|
|
9
|
+
declare const setActionBadgeTextColor: (tabId: number, color: BadgeBackgroundColorDetails["color"]) => Promise<void>;
|
|
10
|
+
declare const setActionIcon: (tabId: number, icon: string | Record<string, string>) => Promise<void>;
|
|
11
|
+
declare const getActionDefaultPopup: () => string;
|
|
12
|
+
declare const onActionClicked: (callback: Parameters<typeof chrome.action.onClicked.addListener>[0]) => () => void;
|
|
13
|
+
|
|
1
14
|
declare const onCommand: (callback: Parameters<typeof chrome.commands.onCommand.addListener>[0]) => () => void;
|
|
2
15
|
|
|
3
16
|
declare const browser: () => typeof chrome;
|
|
17
|
+
declare const getBrowser: () => Browser;
|
|
18
|
+
declare const isBrowser: (browser: Browser) => boolean;
|
|
4
19
|
|
|
5
20
|
type Manifest = chrome.runtime.Manifest;
|
|
6
21
|
declare const getUrl: (path: string) => string;
|
|
7
22
|
declare const getManifest: () => Manifest;
|
|
8
|
-
declare const
|
|
23
|
+
declare const getManifestVersion: () => ManifestVersion;
|
|
24
|
+
declare const isManifestVersion3: () => boolean;
|
|
9
25
|
declare const getId: () => string;
|
|
10
26
|
declare const isBackground: () => boolean;
|
|
27
|
+
declare const throwRuntimeError: () => void;
|
|
11
28
|
|
|
12
|
-
export { browser, getId, getManifest,
|
|
29
|
+
export { browser, clearActionBadgeText, getActionDefaultPopup, getBrowser, getId, getManifest, getManifestVersion, getUrl, isBackground, isBrowser, isManifestVersion3, onActionClicked, onCommand, setActionBadgeBgColor, setActionBadgeText, setActionBadgeTextColor, setActionIcon, throwRuntimeError };
|
package/dist/browser/index.js
CHANGED
|
@@ -1,23 +1,33 @@
|
|
|
1
1
|
import _isUndefined from 'lodash/isUndefined';
|
|
2
2
|
|
|
3
|
+
// src/browser/runtime.ts
|
|
4
|
+
|
|
5
|
+
// src/core/env.ts
|
|
6
|
+
var getEnv = (key, defaults) => {
|
|
7
|
+
const env = process.env;
|
|
8
|
+
return env[key] ?? defaults;
|
|
9
|
+
};
|
|
10
|
+
|
|
3
11
|
// src/browser/env.ts
|
|
4
12
|
var browser = () => {
|
|
5
13
|
return chrome;
|
|
6
14
|
};
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
return () => commands.onCommand.removeListener(callback);
|
|
15
|
+
var getBrowser = () => {
|
|
16
|
+
return getEnv("BROWSER", "chrome" /* Chrome */);
|
|
17
|
+
};
|
|
18
|
+
var isBrowser = (browser2) => {
|
|
19
|
+
return getBrowser() === browser2;
|
|
13
20
|
};
|
|
21
|
+
|
|
22
|
+
// src/browser/runtime.ts
|
|
14
23
|
var runtime = browser().runtime;
|
|
15
24
|
var backgroundPaths = [
|
|
16
25
|
"/_generated_background_page.html"
|
|
17
26
|
];
|
|
18
27
|
var getUrl = (path) => runtime.getURL(path);
|
|
19
28
|
var getManifest = () => runtime.getManifest();
|
|
20
|
-
var
|
|
29
|
+
var getManifestVersion = () => getManifest().manifest_version;
|
|
30
|
+
var isManifestVersion3 = () => getManifestVersion() === 3;
|
|
21
31
|
var getId = () => runtime.id;
|
|
22
32
|
var isBackground = () => {
|
|
23
33
|
if (!getId()) {
|
|
@@ -32,7 +42,71 @@ var isBackground = () => {
|
|
|
32
42
|
}
|
|
33
43
|
return !_isUndefined(window) && backgroundPaths.includes(location.pathname);
|
|
34
44
|
};
|
|
45
|
+
var throwRuntimeError = () => {
|
|
46
|
+
const error = runtime.lastError;
|
|
47
|
+
if (error) {
|
|
48
|
+
throw new Error(error.message);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
// src/browser/action.ts
|
|
53
|
+
var getAction = () => isManifestVersion3() ? browser().action : browser().browserAction;
|
|
54
|
+
var setActionBadgeText = (tabId, text) => new Promise((resolve, reject) => {
|
|
55
|
+
const details = { text: text.toString(), tabId };
|
|
56
|
+
getAction().setBadgeText(details, () => {
|
|
57
|
+
try {
|
|
58
|
+
throwRuntimeError();
|
|
59
|
+
resolve();
|
|
60
|
+
} catch (e) {
|
|
61
|
+
reject(e);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
var clearActionBadgeText = (tabId) => setActionBadgeText(tabId, "");
|
|
66
|
+
var setActionBadgeBgColor = (tabId, color) => new Promise((resolve, reject) => {
|
|
67
|
+
const details = { color, tabId };
|
|
68
|
+
getAction().setBadgeBackgroundColor(details, () => {
|
|
69
|
+
try {
|
|
70
|
+
throwRuntimeError();
|
|
71
|
+
resolve();
|
|
72
|
+
} catch (e) {
|
|
73
|
+
reject(e);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
var setActionBadgeTextColor = async (tabId, color) => {
|
|
78
|
+
if (!isManifestVersion3()) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
const action = getAction();
|
|
82
|
+
await action.setBadgeTextColor({ color, tabId });
|
|
83
|
+
};
|
|
84
|
+
var setActionIcon = (tabId, icon) => new Promise((resolve, reject) => {
|
|
85
|
+
getAction().setIcon({ tabId, path: icon }, () => {
|
|
86
|
+
try {
|
|
87
|
+
throwRuntimeError();
|
|
88
|
+
resolve();
|
|
89
|
+
} catch (e) {
|
|
90
|
+
reject(e);
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
var getActionDefaultPopup = () => {
|
|
95
|
+
const manifest = getManifest();
|
|
96
|
+
return isManifestVersion3() ? manifest.action.default_popup : manifest.browser_action.default_popup;
|
|
97
|
+
};
|
|
98
|
+
var onActionClicked = (callback) => {
|
|
99
|
+
getAction().onClicked.addListener(callback);
|
|
100
|
+
return () => getAction().onClicked.removeListener(callback);
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
// src/browser/command.ts
|
|
104
|
+
var commands = browser().commands;
|
|
105
|
+
var onCommand = (callback) => {
|
|
106
|
+
commands.onCommand.addListener(callback);
|
|
107
|
+
return () => commands.onCommand.removeListener(callback);
|
|
108
|
+
};
|
|
35
109
|
|
|
36
|
-
export { browser, getId, getManifest,
|
|
110
|
+
export { browser, clearActionBadgeText, getActionDefaultPopup, getBrowser, getId, getManifest, getManifestVersion, getUrl, isBackground, isBrowser, isManifestVersion3, onActionClicked, onCommand, setActionBadgeBgColor, setActionBadgeText, setActionBadgeTextColor, setActionIcon, throwRuntimeError };
|
|
37
111
|
//# sourceMappingURL=index.js.map
|
|
38
112
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/
|
|
1
|
+
{"version":3,"sources":["../../src/core/env.ts","../../src/browser/env.ts","../../src/browser/runtime.ts","../../src/browser/action.ts","../../src/browser/command.ts"],"names":["browser"],"mappings":";;;;;AAGO,IAAM,MAAA,GAGT,CAAC,GAAA,EAAa,QAAsB,KAAA;AACpC,EAAA,MAAM,MAAM,OAAQ,CAAA,GAAA;AAEpB,EAAQ,OAAA,GAAA,CAAI,GAAG,CAAK,IAAA,QAAA;AACxB,CAAA;;;ACPO,IAAM,UAAU,MAAqB;AACxC,EAAO,OAAA,MAAA;AACX;AAEO,IAAM,aAAa,MAAe;AACrC,EAAA,OAAO,OAAO,SAAyB,EAAA,QAAA,cAAA;AAC3C;AAEa,IAAA,SAAA,GAAY,CAACA,QAA8B,KAAA;AACpD,EAAA,OAAO,YAAiBA,KAAAA,QAAAA;AAC5B;;;ACNA,IAAM,OAAA,GAAU,SAAU,CAAA,OAAA;AAE1B,IAAM,eAAkB,GAAA;AAAA,EACpB;AACJ,CAAA;AAEO,IAAM,MAAS,GAAA,CAAC,IAAiB,KAAA,OAAA,CAAQ,OAAO,IAAI;AAE9C,IAAA,WAAA,GAAc,MAAgB,OAAA,CAAQ,WAAY;AAElD,IAAA,kBAAA,GAAqB,MAAuB,WAAA,EAAc,CAAA;AAE1D,IAAA,kBAAA,GAAqB,MAAe,kBAAA,EAAyB,KAAA;AAE7D,IAAA,KAAA,GAAQ,MAAc,OAAQ,CAAA;AAEpC,IAAM,eAAe,MAAe;AACvC,EAAI,IAAA,CAAC,OAAS,EAAA;AACV,IAAO,OAAA,KAAA;AAAA;AAGX,EAAA,MAAM,WAAW,WAAY,EAAA;AAE7B,EAAI,IAAA,CAAC,SAAS,UAAY,EAAA;AACtB,IAAO,OAAA,KAAA;AAAA;AAGX,EAAI,IAAA,QAAA,CAAS,qBAAqB,CAAG,EAAA;AACj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\nimport {ManifestVersion} from \"@typing/manifest\";\n\nexport const getEnv: {\n <T extends string>(key: string): T | undefined;\n <T extends string, D>(key: string, defaults: D): T | D;\n} = (key: string, defaults?: string) => {\n const env = process.env;\n\n return (env[key] ?? defaults) as any;\n};\n\nexport const getBrowser = (): Browser => {\n const browser = getEnv<Browser>('BROWSER');\n\n if (browser === undefined) {\n throw new Error('Browser is not defined');\n }\n\n return browser;\n}\n\nexport const getManifestVersion = (): ManifestVersion => {\n const manifestVersion = getEnv('MANIFEST_VERSION', '3');\n\n return parseInt(manifestVersion) as ManifestVersion;\n}","import {Browser} from \"@typing/browser\";\nimport {getEnv} from \"@core/env\";\n\nexport const browser = (): typeof chrome => {\n return chrome;\n}\n\nexport const getBrowser = (): Browser => {\n return getEnv('BROWSER', Browser.Chrome);\n}\n\nexport const isBrowser = (browser: Browser): boolean => {\n return getBrowser() === browser;\n}","import _isUndefined from \"lodash/isUndefined\";\n\nimport {browser} from \"./env\";\nimport {ManifestVersion} from \"@typing/manifest\";\n\ntype Manifest = chrome.runtime.Manifest;\n\nconst runtime = browser().runtime;\n\nconst backgroundPaths = [\n '/_generated_background_page.html',\n];\n\nexport const getUrl = (path: string) => runtime.getURL(path);\n\nexport const getManifest = (): Manifest => runtime.getManifest();\n\nexport const getManifestVersion = (): ManifestVersion => getManifest().manifest_version;\n\nexport const isManifestVersion3 = (): boolean => getManifestVersion() === 3;\n\nexport const getId = (): string => runtime.id;\n\nexport const isBackground = (): boolean => {\n if (!getId()) {\n return false;\n }\n\n const manifest = getManifest();\n\n if (!manifest.background) {\n return false;\n }\n\n if (manifest.manifest_version === 3) {\n return _isUndefined(window);\n }\n\n return !_isUndefined(window) && backgroundPaths.includes(location.pathname);\n}\n\nexport const throwRuntimeError = (): void => {\n const error = runtime.lastError;\n\n if (error) {\n throw new Error(error.message);\n }\n}","import {getManifest, isManifestVersion3, throwRuntimeError} from \"./runtime\";\nimport {browser} from \"./env\";\n\ntype BadgeBackgroundColorDetails = chrome.browserAction.BadgeBackgroundColorDetails;\ntype BadgeTextDetails = chrome.action.BadgeTextDetails;\ntype BrowserAction = typeof chrome.action;\n\nconst getAction = () => isManifestVersion3() ? browser().action : browser().browserAction;\n\nexport const setActionBadgeText = (tabId: number, text: string | number) => new Promise<void>((resolve, reject) => {\n const details: BadgeTextDetails = {text: text.toString(), tabId};\n\n getAction().setBadgeText(details, () => {\n try {\n throwRuntimeError();\n\n resolve();\n } catch (e) {\n reject(e);\n }\n });\n});\n\nexport const clearActionBadgeText = (tabId: number): Promise<void> => setActionBadgeText(tabId, '');\n\nexport const setActionBadgeBgColor = (tabId: number, color: BadgeBackgroundColorDetails['color']) => new Promise<void>((resolve, reject) => {\n const details: BadgeBackgroundColorDetails = {color, tabId};\n\n getAction().setBadgeBackgroundColor(details, () => {\n try {\n throwRuntimeError();\n\n resolve();\n } catch (e) {\n reject(e);\n }\n });\n});\n\nexport const setActionBadgeTextColor = async (\n tabId: number,\n color: BadgeBackgroundColorDetails['color']\n): Promise<void> => {\n if (!isManifestVersion3()) {\n return;\n }\n\n const action = getAction() as BrowserAction;\n\n await action.setBadgeTextColor({color, tabId});\n};\n\nexport const setActionIcon = (\n tabId: number,\n icon: string | Record<string, string>\n): Promise<void> => new Promise<void>((resolve, reject) => {\n getAction().setIcon({tabId, path: icon}, () => {\n try {\n throwRuntimeError();\n\n resolve();\n } catch (e) {\n reject(e);\n }\n });\n});\n\nexport const getActionDefaultPopup = (): string => {\n const manifest = getManifest();\n\n return isManifestVersion3() ? manifest.action.default_popup : manifest.browser_action.default_popup;\n}\n\nexport const onActionClicked = (callback: Parameters<typeof chrome.action.onClicked.addListener>[0]): () => void => {\n getAction().onClicked.addListener(callback);\n\n return () => getAction().onClicked.removeListener(callback);\n}","import {browser} from \"./env\";\n\nconst commands = browser().commands;\n\nexport const onCommand = (callback: Parameters<typeof chrome.commands.onCommand.addListener>[0]): () => void => {\n commands.onCommand.addListener(callback);\n\n return () => commands.onCommand.removeListener(callback);\n}"]}
|