From fbf303e9ba6e9aadf190241e9bcdcc5f12f94813 Mon Sep 17 00:00:00 2001 From: typeling1578 Date: Sat, 7 Oct 2023 14:01:44 +0900 Subject: [PATCH] Make it work with Chromium --- addonSettings.mjs | 8 ++++---- fetchPlus.mjs | 4 ++++ l10n.js | 4 ++++ options.mjs | 4 ++++ popup.mjs | 4 ++++ 5 files changed, 20 insertions(+), 4 deletions(-) diff --git a/addonSettings.mjs b/addonSettings.mjs index 448f8e6..92ea39e 100644 --- a/addonSettings.mjs +++ b/addonSettings.mjs @@ -19,16 +19,16 @@ export default class { if (this.initialized) return; this.initialized = true; - this.local = await browser.storage.local.get(); - this.sync = await browser.storage.sync.get(); + this.local = await new Promise(resolve => browser.storage.local.get(null, (items) => resolve(items))); + this.sync = await new Promise(resolve => browser.storage.sync.get(null, (items) => resolve(items))); try { - this.managed = await browser.storage.managed.get(); + this.managed = await new Promise(resolve => browser.storage.managed.get(null, (items) => resolve(items))); } catch (e) {} browser.storage.onChanged.addListener(async (changes, areaName) => { if (!["local", "sync"].includes(areaName)) return; - this[areaName] = await browser.storage[areaName].get(); + this[areaName] = await new Promise(resolve => browser.storage[areaName].get(null, (items) => resolve(items))); for (const listener of this._listeners) { if (listener.type == areaName) { listener.callback(areaName, changes, this[areaName]); diff --git a/fetchPlus.mjs b/fetchPlus.mjs index f65f459..09e476e 100644 --- a/fetchPlus.mjs +++ b/fetchPlus.mjs @@ -1,5 +1,9 @@ import generateRandomString from "./generateRandomString.mjs"; +if (!window.browser) { + window.browser = chrome; +} + export default async function(url, options = {}) { const requestId = generateRandomString(12); diff --git a/l10n.js b/l10n.js index 1f5a226..79dcbae 100644 --- a/l10n.js +++ b/l10n.js @@ -1,3 +1,7 @@ +if (!window.browser) { + window.browser = chrome; +} + for (const elem of document.querySelectorAll(".i18n-text")) { elem.innerText = browser.i18n.getMessage(elem.getAttribute("data-i18n-id")); } diff --git a/options.mjs b/options.mjs index 446ae6b..01bfc82 100644 --- a/options.mjs +++ b/options.mjs @@ -1,5 +1,9 @@ import addonSettings from "./addonSettings.mjs"; +if (!window.browser) { + window.browser = chrome; +} + const settings = new addonSettings(); await settings.init(); diff --git a/popup.mjs b/popup.mjs index e0968f3..4d19a81 100644 --- a/popup.mjs +++ b/popup.mjs @@ -1,5 +1,9 @@ import addonSettings from "./addonSettings.mjs"; +if (!window.browser) { + window.browser = chrome; +} + const settings = new addonSettings(); await settings.init();