From 174bdd5ee822859dcd89600619af427c3e21038e Mon Sep 17 00:00:00 2001
From: buzz-lightsnack-2007
<73412182+buzz-lightsnack-2007@users.noreply.github.com>
Date: Thu, 23 May 2024 22:11:55 +0800
Subject: [PATCH] show different groups of navbar elements during different
pages
---
src/pages/popup.htm | 4 +++-
src/scripts/pages/popup.js | 18 ++++++++++++++++--
src/scripts/platform/processor.js | 22 ++++++++++++++--------
3 files changed, 33 insertions(+), 11 deletions(-)
diff --git a/src/pages/popup.htm b/src/pages/popup.htm
index 3239aef..c3c3eed 100644
--- a/src/pages/popup.htm
+++ b/src/pages/popup.htm
@@ -7,12 +7,14 @@
diff --git a/src/scripts/pages/popup.js b/src/scripts/pages/popup.js
index 32b8900..9324db7 100644
--- a/src/scripts/pages/popup.js
+++ b/src/scripts/pages/popup.js
@@ -65,6 +65,13 @@ class Page_Popup extends Page {
"OOBE": "hello.htm",
"error": "error.htm"
};
+ // Set the width and the height.
+ const PAGES_DIMENSIONS = {
+ "loading": {"width": "200pt", "height": "100pt"},
+ "error": {"width": "250pt", "height": "300pt"},
+ "results": {"width": "250pt", "height": "225pt"},
+ "OOBE": {"width": "350pt", "height": "300pt"},
+ };
// Prepare all the necessary data.
this.update().then(() => {
@@ -86,8 +93,15 @@ class Page_Popup extends Page {
this.elements[`container`].classList[([`results`, `OOBE`].includes(SELECTION)) ? `remove` : `add`](`container`);
// Set the title bar content.
- this[`window`][`navigation bar`][([`OOBE`].includes(SELECTION)) ? `hide` : `show`](`header`, `results`);
- this[`window`][`navigation bar`][([`OOBE`].includes(SELECTION)) ? `show` : `hide`](`header`, `OOBE`);
+ this[`window`][`navigation bar`][([`OOBE`, `loading`].includes(SELECTION)) ? `hide` : `show`](`header`, `result`);
+ [`loading`, `OOBE`].forEach((NAME) => {
+ this[`window`][`navigation bar`][(NAME == SELECTION) ? `show` : `hide`](`header`, NAME);
+ });
+
+ // Set the dimensions of the body.
+ Object.keys(PAGES_DIMENSIONS[SELECTION]).forEach((DIMENSION) => {
+ document.body.style[DIMENSION] = PAGES_DIMENSIONS[SELECTION][DIMENSION];
+ });
};
});
}
diff --git a/src/scripts/platform/processor.js b/src/scripts/platform/processor.js
index 2329038..226d6f0 100644
--- a/src/scripts/platform/processor.js
+++ b/src/scripts/platform/processor.js
@@ -13,6 +13,7 @@ import gemini from "/scripts/AI/gemini.js";
export default class processor {
#filter;
#analyzer;
+ status = {};
async scrape (fields, options) {
this.product.details = new scraper (((fields) ? fields : this.targets), options);
@@ -96,12 +97,19 @@ export default class processor {
RUN = true;
} else {
new logging(texts.localized(`AIkey_message_waiting_title`), texts.localized(`AIkey_message_waiting_body`));
- new background(async () => {
- if ((!RUN) ? (await global.read([`settings`,`analysis`,`api`,`key`])) : false) {
- await main();
- RUN = true;
- }
- });
+ if (!this.status.wait) {
+ this.status.background = new background(async () => {
+ this.status.wait = true; // lock the process
+ if ((!RUN) ? (await global.read([`settings`,`analysis`,`api`,`key`])) : false) {
+ await main();
+ RUN = true;
+
+ // Cancel the background process.
+ this.status.background.cancel();
+ this.status.wait = false; // unlock the process
+ }
+ });
+ }
}
}
@@ -155,8 +163,6 @@ export default class processor {
this.product = new product();
this.targets = this.#filter[`data`];
-
- this.status = {};
((((typeof options).includes(`obj`)) ? Object.hasOwn(options, `automatic`) : false) ? options[`automatic`] : true) ? this.run() : false;
}