set loader percentage and send manual refresh

This commit is contained in:
buzz-lightsnack-2007 2024-05-08 23:51:48 +08:00
parent 4242ecc799
commit f2b2106bbd

View file

@ -48,18 +48,15 @@ class Page_Popup extends Page {
: ((this[`status`]) : ((this[`status`])
? this[`status`] ? this[`status`]
: {}); : {});
// Call for scraping of data if global data does not indicate automatic scraping or if data doesn't exist.
if (!await global.read([`settings`, `behavior`, `autoRun`]) && DATA[`status`] == null) {
this.send();
}
} }
async loading() { async loading() {
this.loading = new Loader(); this[`elements`] = (this[`elements`]) ? this[`elements`] : {};
this[`elements`][`loader`] = new Loader();
} }
async switch() { async switch() {
if (this.elements[`frame`]) {
let PAGES = { let PAGES = {
"results": "results.htm", "results": "results.htm",
"loading": "load.htm", "loading": "load.htm",
@ -76,7 +73,7 @@ class Page_Popup extends Page {
PAGES[PAGE] = chrome.runtime.getURL(`pages/popup/${PAGES[PAGE]}`); PAGES[PAGE] = chrome.runtime.getURL(`pages/popup/${PAGES[PAGE]}`);
}); });
let PAGE = PAGES[((this[`status`][`done`]) let PAGE = PAGES[(((this[`status`] && (typeof this[`status`]).includes(`obj`)) ? (this[`status`][`done`] >= 1) : false)
? ((this[`status`][`error`] && this[`status`][`error`] != {}) ? ((this[`status`][`error`] && this[`status`][`error`] != {})
? `error` ? `error`
: `results`) : `results`)
@ -85,9 +82,16 @@ class Page_Popup extends Page {
// Replace the iframe src with the new page. // Replace the iframe src with the new page.
this.elements[`frame`].src = PAGE; this.elements[`frame`].src = PAGE;
// The results page has its own container. // The results page has its own container.
this.elements[`container`].classList[(PAGE.includes(`results`)) ? `remove` : `add`](`container`); this.elements[`container`].classList[(PAGE.includes(`results`)) ? `remove` : `add`](`container`);
}; };
}
// Also set the loader.
(this[`elements`][`loader`])
? ((this[`status`] ? (this[`status`][`done`] ? (this[`status`][`done`] <= 1) : false) : false) ? parseFloat(this[`elements`][`loader`].update(this[`status`][`done`])) : false)
: false
}; };
async content() { async content() {
@ -99,21 +103,30 @@ class Page_Popup extends Page {
// Check if the frame is available. // Check if the frame is available.
if (this.elements[`frame`]) { if (this.elements[`frame`]) {
await this.switch(); await this.switch();
this.background();
// Call for scraping of data if global data does not indicate automatic scraping or if data doesn't exist.
if (!await global.read([`settings`, `behavior`, `autoRun`]) && DATA[`status`] == null) {
this.send({"refresh": "automatic"});
}
} else { } else {
this.loading(); this.loading();
} }
}; };
send() { /*
Call for the scraper and analyzer.
*/
send(options) {
// Make sure that it is the correct format.
let OPTIONS = (options && (typeof options).includes(`obj`) && !Array.isArray(options)) ? options : {};
try { try {
// Send a message to the content script. // Send a message to the content script.
Tabs.query(null, 0).then((TAB) => { Tabs.query(null, 0).then((TAB) => {
chrome.tabs.sendMessage(TAB.id, {"refresh": true}); chrome.tabs.sendMessage(TAB.id, OPTIONS);
}); });
} catch(err) { } catch(err) {
logging.error(err.name, err.message, err.stack); logging.error(err.name, err.message, err.stack);
throw (err);
}; };
}; };
@ -133,12 +146,12 @@ class Page_Popup extends Page {
chrome.runtime.openOptionsPage(); chrome.runtime.openOptionsPage();
}) : false; }) : false;
(this[`elements`][`button`][`open,help`]) ? this[`elements`][`button`][`open,help`].addEventListener("click", () => { (this[`elements`][`button`][`open,help`]) ? this[`elements`][`button`][`open,help`].addEventListener(`click`, () => {
new Window(`help.htm`); new Window(`help.htm`);
}) : false; }) : false;
(this[`elements`][`button`][`analysis,reload`]) ? this[`elements`][`button`][`analysis,reload`].addEventListener("click", () => { (this[`elements`][`button`][`analysis,reload`]) ? this[`elements`][`button`][`analysis,reload`].addEventListener(`click`, () => {
this.send(); this.send({"refresh": "manual"});
}) : false; }) : false;
} }
} }