Skip to content

Commit

Permalink
Make it work with Chromium
Browse files Browse the repository at this point in the history
  • Loading branch information
typeling1578 committed Oct 7, 2023
1 parent b2056a9 commit fbf303e
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 4 deletions.
8 changes: 4 additions & 4 deletions addonSettings.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
4 changes: 4 additions & 0 deletions fetchPlus.mjs
Original file line number Diff line number Diff line change
@@ -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);

Expand Down
4 changes: 4 additions & 0 deletions l10n.js
Original file line number Diff line number Diff line change
@@ -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"));
}
Expand Down
4 changes: 4 additions & 0 deletions options.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import addonSettings from "./addonSettings.mjs";

if (!window.browser) {
window.browser = chrome;
}

const settings = new addonSettings();
await settings.init();

Expand Down
4 changes: 4 additions & 0 deletions popup.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import addonSettings from "./addonSettings.mjs";

if (!window.browser) {
window.browser = chrome;
}

const settings = new addonSettings();
await settings.init();

Expand Down

0 comments on commit fbf303e

Please sign in to comment.