From 2b24bf17b09c23f6785c28a888a69502b0967daf Mon Sep 17 00:00:00 2001 From: buzz-lightsnack-2007 <73412182+buzz-lightsnack-2007@users.noreply.github.com> Date: Tue, 16 Apr 2024 20:21:20 +0800 Subject: [PATCH 1/3] import modules properly --- scripts/logging.js | 3 --- scripts/net.js | 23 +++++++++++------------ 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/scripts/logging.js b/scripts/logging.js index 3ca0bb4..1b24d6c 100644 --- a/scripts/logging.js +++ b/scripts/logging.js @@ -70,9 +70,6 @@ export default class logging { @param {boolean} critical the critical nature */ static async error(ERROR_CODE, ERROR_MESSAGE, ERROR_STACK, critical = true) { - // Import the templating. - const texts = (await import(chrome.runtime.getURL("/scripts/strings/read.js"))).default; - // Display the error message. console.error(texts.localized(`error_msg`, false, [ERROR_CODE, ERROR_MESSAGE, ERROR_STACK])); if (critical) { diff --git a/scripts/net.js b/scripts/net.js index 6e8f33a..77e6729 100644 --- a/scripts/net.js +++ b/scripts/net.js @@ -2,21 +2,20 @@ This script provides network utilities. */ -/* -Download a file from the network or locally. +import texts from "/scripts/strings/read.js"; +import logging from "/scripts/logging.js"; -@param {string} URL the URL to download -@param {string} TYPE the expected TYPE of file -@param {boolean} VERIFY_ONLY whether to verify the file only, not return its content -@param {boolean} STRICT strictly follow the file type provided -@returns {Promise} the downloaded file -*/ export default class net { - static async download(URL, TYPE, VERIFY_ONLY = false, STRICT = false) { - const texts = (await import(chrome.runtime.getURL(`/scripts/strings/read.js`))) - .default; - const logging = (await import(chrome.runtime.getURL(`/scripts/logging.js`))).default; + /* + Download a file from the network or locally. + @param {string} URL the URL to download + @param {string} TYPE the expected TYPE of file + @param {boolean} VERIFY_ONLY whether to verify the file only, not return its content + @param {boolean} STRICT strictly follow the file type provided + @returns {Promise} the downloaded file + */ + static async download(URL, TYPE, VERIFY_ONLY = false, STRICT = false) { let CONNECT, DATA; try { From 7a6033ec8cf62e42017480d5cdb693023950bc03 Mon Sep 17 00:00:00 2001 From: buzz-lightsnack-2007 <73412182+buzz-lightsnack-2007@users.noreply.github.com> Date: Tue, 16 Apr 2024 20:23:03 +0800 Subject: [PATCH 2/3] make sure to get the 0th URL item --- scripts/product.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/product.js b/scripts/product.js index da27b17..561d808 100644 --- a/scripts/product.js +++ b/scripts/product.js @@ -25,7 +25,7 @@ export default class product { /* Remove uneeded data or formatting from the URL and the data. */ let clean = (URL) => { // Remove the protocol from the URL. - return(URL.replace(/(^\w+:|^)\/\//, ``).split(`?`)); + return((URL.replace(/(^\w+:|^)\/\//, ``).split(`?`))[0]); } // Set this product's details as part of the object's properties. @@ -67,7 +67,7 @@ export default class product { if (!this.#snip) {throw new ReferenceError((new texts(`error_msg_notattached`)).localized)}; // Save the data to the storage. - secretariat.write([`sites`, this.URL, `data`], this.#snip, 1); + await secretariat.write([`sites`, this.URL, `data`], this.#snip, 1); // Write the analysis data to the storage. (this[`analysis`]) ? secretariat.write([`sites`, this.URL, `analysis`], this.analysis, 1): false; From 61082a0c6715e90f7fb51e50ab8eb5781e0e3a12 Mon Sep 17 00:00:00 2001 From: buzz-lightsnack-2007 <73412182+buzz-lightsnack-2007@users.noreply.github.com> Date: Tue, 16 Apr 2024 20:23:18 +0800 Subject: [PATCH 3/3] For faster processing, use DOMContentLoaded instead --- scripts/external/watch.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/external/watch.js b/scripts/external/watch.js index f490fd6..2f1c1df 100644 --- a/scripts/external/watch.js +++ b/scripts/external/watch.js @@ -34,7 +34,7 @@ let main = (async () => { // Begin only when the page is fully loaded. - window.addEventListener(`load`, (event) => { + window.addEventListener(`DOMContentLoaded`, (event) => { // Begin processing. let PROC = new processor(matches);