aboutsummaryrefslogtreecommitdiff
path: root/ext/js/background/script-manager.js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/js/background/script-manager.js')
-rw-r--r--ext/js/background/script-manager.js28
1 files changed, 18 insertions, 10 deletions
diff --git a/ext/js/background/script-manager.js b/ext/js/background/script-manager.js
index 84213452..ea1702e9 100644
--- a/ext/js/background/script-manager.js
+++ b/ext/js/background/script-manager.js
@@ -60,16 +60,7 @@ export function injectStylesheet(type, content, tabId, frameId, allFrames) {
* @returns {Promise<boolean>} `true` if a script is registered, `false` otherwise.
*/
export async function isContentScriptRegistered(id) {
- const scripts = await new Promise((resolve, reject) => {
- chrome.scripting.getRegisteredContentScripts({ids: [id]}, (result) => {
- const e = chrome.runtime.lastError;
- if (e) {
- reject(new Error(e.message));
- } else {
- resolve(result);
- }
- });
- });
+ const scripts = await getRegisteredContentScripts([id]);
for (const script of scripts) {
if (script.id === id) {
return true;
@@ -155,3 +146,20 @@ function createContentScriptRegistrationOptions(details, id) {
}
return options;
}
+
+/**
+ * @param {string[]} ids
+ * @returns {Promise<chrome.scripting.RegisteredContentScript[]>}
+ */
+function getRegisteredContentScripts(ids) {
+ return new Promise((resolve, reject) => {
+ chrome.scripting.getRegisteredContentScripts({ids}, (result) => {
+ const e = chrome.runtime.lastError;
+ if (e) {
+ reject(new Error(e.message));
+ } else {
+ resolve(result);
+ }
+ });
+ });
+}