make the imports universal

This commit is contained in:
buzz-lightsnack-2007 2024-04-08 23:36:44 +08:00
parent 75156d71da
commit 9a9acf2440

View file

@ -3,6 +3,9 @@ Manage filters.
*/ */
const secretariat = await import(chrome.runtime.getURL("scripts/secretariat.js")); const secretariat = await import(chrome.runtime.getURL("scripts/secretariat.js"));
const net = await import(chrome.runtime.getURL("scripts/net.js"));
const texts = (await import(chrome.runtime.getURL("gui/scripts/read.js"))).default;
const alerts = (await import(chrome.runtime.getURL("gui/scripts/alerts.js"))).default;
export default class filters { export default class filters {
constructor() { constructor() {
@ -24,11 +27,6 @@ export default class filters {
*/ */
async select(URL = window.location.href) { async select(URL = window.location.href) {
this.one = await (async () => { this.one = await (async () => {
// Import the secretariat.
const secretariat = await import(
chrome.runtime.getURL("scripts/secretariat.js")
);
// Get the filters. // Get the filters.
let filter = await secretariat.search(`filters`, -1, [`URL`]); let filter = await secretariat.search(`filters`, -1, [`URL`]);
@ -45,17 +43,6 @@ export default class filters {
@return {boolean} the state @return {boolean} the state
*/ */
async update(URL) { async update(URL) {
// Import the updater.
const secretariat = await import(
chrome.runtime.getURL("scripts/secretariat.js")
);
const net = await import(chrome.runtime.getURL("scripts/net.js"));
const texts = (await import(chrome.runtime.getURL("gui/scripts/read.js")))
.default;
const alerts = (
await import(chrome.runtime.getURL("gui/scripts/alerts.js"))
).default;
// Apparently, JS doesn't have a native queueing system, but it might best work here. // Apparently, JS doesn't have a native queueing system, but it might best work here.
class Queue { class Queue {
constructor() { constructor() {
@ -143,6 +130,7 @@ export default class filters {
@param {string} URL the URL to remove @param {string} URL the URL to remove
*/ */
async remove(URL) { async remove(URL) {
if (URL.includes(`://`)) {
let CHOICE = await secretariat.forget(`filters`, URL); let CHOICE = await secretariat.forget(`filters`, URL);
if (CHOICE) { if (CHOICE) {
console.log(await secretariat.read(null, -1), URL); console.log(await secretariat.read(null, -1), URL);
@ -155,5 +143,11 @@ export default class filters {
} }
return CHOICE; return CHOICE;
} else {
// Inform the user of the download being unnecessary.
alerts.warn(texts.localized(`settings_filters_removal_stop`));
return false;
}
} }
} }