only get the local chrome URL of the current page

This commit is contained in:
buzz-lightsnack-2007 2024-05-13 16:01:30 +08:00
parent 082f423332
commit 7d20170c25

View file

@ -47,6 +47,9 @@ class Page_Popup extends Page {
: ((this[`status`]) : ((this[`status`])
? this[`status`] ? this[`status`]
: {}); : {});
// Confirm completion by returning the status.
return (this[`status`]);
} }
async loading() { async loading() {
@ -54,7 +57,7 @@ class Page_Popup extends Page {
this[`elements`][`loader`] = new Loader(); this[`elements`][`loader`] = new Loader();
} }
async switch() { switch() {
if (this.elements[`frame`]) { if (this.elements[`frame`]) {
let PAGES = { let PAGES = {
"results": "results.htm", "results": "results.htm",
@ -63,27 +66,18 @@ class Page_Popup extends Page {
} }
// Prepare all the necessary data. // Prepare all the necessary data.
await this.update(); this.update().then(() => {
// Make sure that the website has been selected!
// Make sure that the website has been selected! if (this[`ref`]) {
if (this[`ref`]) { let PAGE = chrome.runtime.getURL(`pages/popup/`.concat(PAGES[(this[`status`][`done`] <= -1 || this[`status`][`error`]) ? `error` : ((this[`status`][`done`] >= 1) ? `results` : `loading`)]));
// Set the relative chrome URLs
(Object.keys(PAGES)).forEach(PAGE => { // Replace the iframe src with the new page.
PAGES[PAGE] = chrome.runtime.getURL(`pages/popup/${PAGES[PAGE]}`); (this.elements[`frame`].src != PAGE) ? this.elements[`frame`].src = PAGE : false;
});
// The results page has its own container.
let PAGE = PAGES[(((this[`status`] && (typeof this[`status`]).includes(`obj`)) ? (this[`status`][`done`] >= 1) : false) this.elements[`container`].classList[(PAGE.includes(`results`)) ? `remove` : `add`](`container`);
? ((this[`status`][`error`] && this[`status`][`error`] != {}) };
? `error` });
: `results`)
: `loading`)];
// Replace the iframe src with the new page.
(this.elements[`frame`].src != PAGE) ? this.elements[`frame`].src = PAGE : false;
// The results page has its own container.
this.elements[`container`].classList[(PAGE.includes(`results`)) ? `remove` : `add`](`container`);
};
} }
// Also set the loader. // Also set the loader.