Popup is fixed to the page it has opened
This commit is contained in:
parent
b98be445ae
commit
0a696ad54e
1 changed files with 42 additions and 21 deletions
|
@ -18,7 +18,27 @@ class Page_Popup extends Page {
|
||||||
|
|
||||||
async background() {
|
async background() {
|
||||||
// Wait until a change in the session storage.
|
// Wait until a change in the session storage.
|
||||||
|
observe(async (changes) => {
|
||||||
|
this.update();
|
||||||
|
this.switch();
|
||||||
|
// First, update site data but retain the URL.
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Update the data used by the page.
|
||||||
|
|
||||||
|
@param {boolean} override override the current data.
|
||||||
|
*/
|
||||||
|
async update(override = false) {
|
||||||
|
// Set the reference website when overriding or unset.
|
||||||
|
(override || !this[`ref`]) ? this[`ref`] = await session.read([`last`, `URL`]) : false;
|
||||||
|
|
||||||
|
// Update all other data.
|
||||||
|
(this[`ref`]) ? this[`data`] = await session.read([`last`]) : false;
|
||||||
|
|
||||||
|
// Merge objects
|
||||||
|
(this[`data`] && this[`ref`]) ? this[`data`] = Object.assign(this[`data`], await session.read([`sites`, this[`ref`]])) : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
async loading() {
|
async loading() {
|
||||||
|
@ -32,26 +52,26 @@ class Page_Popup extends Page {
|
||||||
"error": "error.htm"
|
"error": "error.htm"
|
||||||
}
|
}
|
||||||
|
|
||||||
// This will be rewritten to only get the active tab. It should not change whenever the user clicks another tab; it's assumed that he will open the pop-up seperately over there.
|
// Prepare all the necessary data.
|
||||||
// Get the last edited site.
|
await this.update();
|
||||||
let SITE = {};
|
|
||||||
SITE = await session.read([`last`], -1);
|
// Make sure that the website has been selected!
|
||||||
SITE.details = (SITE.url) ? await session.read([`sites`, SITE.url]) : null;
|
if (this[`ref`]) {
|
||||||
|
// Set the relative chrome URLs
|
||||||
// Set the relative chrome URLs
|
(Object.keys(PAGES)).forEach(PAGE => {
|
||||||
(Object.keys(PAGES)).forEach(PAGE => {
|
PAGES[PAGE] = chrome.runtime.getURL(`pages/popup/${PAGES[PAGE]}`);
|
||||||
PAGES[PAGE] = chrome.runtime.getURL(`pages/popup/${PAGES[PAGE]}`);
|
});
|
||||||
});
|
|
||||||
|
// Check if the site is available.
|
||||||
// Check if the site is available.
|
if ((this[`ref`] && this[`data`]) ? (!this[`data`][`done`]) : true) {
|
||||||
if (SITE.url ? (!SITE.done) : true) {
|
this.elements[`frame`].src = PAGES[`loading`];
|
||||||
this.elements[`frame`].src = PAGES[`loading`];
|
} else if (this[`data`][`error`]) {
|
||||||
} else if (SITE.details.error) {
|
// Set the iframe src to display the error.
|
||||||
// Set the iframe src to display the error.
|
this.elements[`frame`].src = PAGES[`error`];
|
||||||
this.elements[`frame`].src = PAGES[`error`];
|
} else {
|
||||||
} else {
|
// Set the iframe src to display the results.
|
||||||
// Set the iframe src to display the results.
|
this.elements[`frame`].src = PAGES[`results`];
|
||||||
this.elements[`frame`].src = PAGES[`results`];
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,6 +79,7 @@ class Page_Popup extends Page {
|
||||||
this.elements = {};
|
this.elements = {};
|
||||||
this.elements[`frame`] = document.querySelectorAll(`iframe.viewer`);
|
this.elements[`frame`] = document.querySelectorAll(`iframe.viewer`);
|
||||||
|
|
||||||
|
|
||||||
// Check if the frame is available.
|
// Check if the frame is available.
|
||||||
if (this.elements[`frame`].length) {
|
if (this.elements[`frame`].length) {
|
||||||
await this.switch();
|
await this.switch();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue