diff --git a/scripts/GUI/builder/windowman.js b/scripts/GUI/builder/windowman.js index 1b7fa9b..ddb73f7 100644 --- a/scripts/GUI/builder/windowman.js +++ b/scripts/GUI/builder/windowman.js @@ -283,7 +283,25 @@ export default class windowman { : false; } + const actions = () => { + let TYPE = `action`; + this.elements[`interactive`][TYPE] = (this.elements[`interactive`][TYPE]) ? this.elements[`interactive`][TYPE] : {}; + + document.querySelector(`[data-${TYPE}]`) + ? document.querySelectorAll(`[data-${TYPE}]`).forEach((ELEMENT) => { + // Store the button. + this.elements[`interactive`][TYPE][ELEMENT.getAttribute(`data-${TYPE}`)] = ((this.elements[`interactive`][TYPE][ELEMENT.getAttribute(`data-${TYPE}`)])) + ? this.elements[`interactive`][TYPE][ELEMENT.getAttribute(`data-${TYPE}`)] + : document.querySelectorAll(`[data-${TYPE}="${ELEMENT.getAttribute(`data-${TYPE}`)}"]`); + + // Remove the property. + (!(TYPE.includes(`store`))) ? ELEMENT.removeAttribute(`data-${TYPE}`) : false; + }) + : false; + } + links(); + actions(); } this[`elements`] = appearance(); @@ -376,6 +394,9 @@ export default class windowman { (this[`elements`][`linked`][`enable`][SOURCE] ? this[`elements`][`linked`][`enable`][SOURCE].length : false) ? this[`elements`][`linked`][`enable`][SOURCE].push(input_element) : this[`elements`][`linked`][`enable`][SOURCE] = [input_element]; + + // Remove the attribute. + input_element.removeAttribute(`data-enable`); } }); }; diff --git a/scripts/pages/error.js b/scripts/pages/error.js index b31b8cc..afdec70 100644 --- a/scripts/pages/error.js +++ b/scripts/pages/error.js @@ -116,21 +116,16 @@ class Page_Error extends Page { Add event listeners to the page. */ events () { - this[`elements`] = (this[`elements`]) ? this[`elements`] : {}; - this[`elements`][`button`] = {}; - - document.querySelectorAll(`[data-action]`).forEach((ELEMENT) => { - let ACTION = ELEMENT.getAttribute(`data-action`); - this[`elements`][`button`][ACTION] = ELEMENT; - - // Remove the data-action attribute. - ELEMENT.removeAttribute(`data-action`); - }) - // Add an event listener to the refresh button. - this[`elements`][`button`][`refresh`].addEventListener(`click`, () => { - this.send(); - }); + (this[`window`][`elements`][`interactive`][`action`] ? this[`window`][`elements`][`interactive`][`action`].length : false) + ? (this[`window`][`elements`][`interactive`][`action`][`refresh`] ? this[`window`][`elements`][`interactive`][`action`][`refresh`].length : false) + ? (this[`window`][`elements`][`interactive`][`action`][`refresh`]).forEach((ELEMENT) => { + ELEMENT.addEventListener(`click`, () => { + this.send(); + }) + }) + : false + : false; }; /* @@ -140,7 +135,7 @@ class Page_Error extends Page { try { // Send a message to the content script. Tabs.query(null, 0).then((TAB) => { - chrome.tabs.sendMessage(TAB.id, {"refresh": "automatic"}); + chrome.tabs.sendMessage(TAB.id, {"refresh": "manual"}); }); } catch(err) { logging.error(err.name, err.message, err.stack); diff --git a/scripts/pages/popup.js b/scripts/pages/popup.js index 04829c9..b364607 100644 --- a/scripts/pages/popup.js +++ b/scripts/pages/popup.js @@ -94,7 +94,7 @@ class Page_Popup extends Page { // Check if the frame is available. if (this.elements[`frame`]) { - await this.switch(); + this.switch(); // 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) { @@ -123,28 +123,19 @@ class Page_Popup extends Page { }; events() { - this[`elements`] = (this[`elements`]) ? this[`elements`] : {}; - this[`elements`][`button`] = {}; + let ACTIONS = {}; + ACTIONS[`open,settings`] = () => {chrome.runtime.openOptionsPage();} + ACTIONS[`open,help`] = () => {new Window(`help.htm`);} + ACTIONS[`analysis,reload`] = () => {this.send({"refresh": "manual"});} - document.querySelectorAll(`[data-action]`).forEach((ELEMENT) => { - let ACTION = ELEMENT.getAttribute(`data-action`).trim(); - this[`elements`][`button`][ACTION] = ELEMENT; - - // Remove the data-action attribute. - ELEMENT.removeAttribute(`data-action`); - }); - - (this[`elements`][`button`][`open,settings`]) ? this[`elements`][`button`][`open,settings`].addEventListener("click", () => { - chrome.runtime.openOptionsPage(); - }) : false; - - (this[`elements`][`button`][`open,help`]) ? this[`elements`][`button`][`open,help`].addEventListener(`click`, () => { - new Window(`help.htm`); - }) : false; - - (this[`elements`][`button`][`analysis,reload`]) ? this[`elements`][`button`][`analysis,reload`].addEventListener(`click`, () => { - this.send({"refresh": "manual"}); - }) : false; + // Add the event listeners. + (Object.keys(ACTIONS)).forEach((NAME) => { + (this.window.elements[`interactive`][`action`][NAME] ? this.window.elements[`interactive`][`action`][NAME].length : false) + ? this.window.elements[`interactive`][`action`][NAME].forEach((ELEMENT) => { + ELEMENT.addEventListener(`click`, ACTIONS[NAME]); + }) + : false; + }) } }