diff --git a/src/scripts/data/product.js b/src/scripts/data/product.js index bc1440d..dd96039 100644 --- a/src/scripts/data/product.js +++ b/src/scripts/data/product.js @@ -2,7 +2,7 @@ Ask product information to Google Gemini. */ // Import the storage management module. -import {global, session, compare} from "/scripts/secretariat.js"; +import {global, compare} from "/scripts/secretariat.js"; import hash from "/scripts/utils/hash.js"; import {URLs} from "/scripts/utils/URLs.js"; @@ -29,18 +29,18 @@ export default class product { // Set private variables. this.#options = options; - // Set the status. + // Set the status. this.status = {}; }; /* - Check the data with data from the storage. + Check the data with data from the storage. */ async read() { if (this.details) { // Add the data digest. this.snip = (await hash.digest(this.details, {"output": "Array"})); - + // Add the status about this data. this.status[`update`] = !(await (compare([`sites`, this.URL, `snip`], this.snip))); }; @@ -52,9 +52,9 @@ export default class product { } async save() { - // There is only a need to save the data if an update is needed. - if (Object.hasOwn(this.status, `update`) ? this.status[`update`] : true) { - // Save the snip data. + // There is only a need to save the data if an update is needed. + if (Object.hasOwn(this.status, `update`) ? this.status[`update`] : true) { + // Save the snip data. (this.snip) ? await global.write([`sites`, this.URL, `snip`], this.snip, 1) : false; // Write the analysis data to the storage. diff --git a/src/scripts/pages/error.js b/src/scripts/pages/error.js index 745aa01..a2d0fec 100644 --- a/src/scripts/pages/error.js +++ b/src/scripts/pages/error.js @@ -1,5 +1,5 @@ /* -Display the error screen details. +Display the error screen details. */ import Page from "/scripts/pages/page.js"; @@ -22,7 +22,7 @@ class Page_Error extends Page { }; async background() { - // Wait until a change in the session storage. + // Wait until a change in the storage. new background(async (changes) => { await this.update(); this.fill(); @@ -30,25 +30,25 @@ class Page_Error extends Page { } /* - Update the data. + Update the data. */ async update() { - // Set the reference website when overriding or unset. + // Set the reference website when overriding or unset. if (!this[`ref`]) {this[`ref`] = await pointer.read(`URL`)}; - // Get all the data to be used here. + // Get all the data to be used here. let STORAGE_DATA = await global.read([`sites`, this[`ref`], `status`, `error`], -1); - // Update all other data. + // Update all other data. this[`status`][`error`] = ((STORAGE_DATA && (typeof STORAGE_DATA).includes(`obj`)) ? (Object.keys(STORAGE_DATA).length) : false) ? STORAGE_DATA - // Accomodate data erasure. + // Accomodate data erasure. : ((this[`status`][`error`]) ? this[`status`][`error`] : {}); - + const parse = (error) => { - // If the error isn't the correct type, try to disect it assuming it's in the stack format. + // If the error isn't the correct type, try to disect it assuming it's in the stack format. this[`status`][`error`] = {}; try { @@ -57,7 +57,7 @@ class Page_Error extends Page { "message": (((error.split(`\n`))[0]).split(texts.localized(`delimiter_error`))).slice(1).join(texts.localized(`delimiter_error`)).trim(), "stack": error.split(`\n`).slice(1).join(`\n`) }; - + (Object.keys(FIELDS)).forEach((KEY) => { this[`status`][`error`][KEY] = (FIELDS[KEY]) ? FIELDS[KEY] : ``; }) @@ -77,7 +77,7 @@ class Page_Error extends Page { } /* - Extract the contents of the page. + Extract the contents of the page. */ content () { this[`elements`] = (this[`elements`]) ? this[`elements`] : {}; @@ -85,12 +85,12 @@ class Page_Error extends Page { const error_display = () => { this[`elements`][`error display`] = {}; let ERROR_CONTENTS = document.querySelectorAll(`[data-error]`); - + ERROR_CONTENTS.forEach((ELEMENT) => { let PROPERTY = ELEMENT.getAttribute(`data-error`).trim(); this[`elements`][`error display`][PROPERTY] = ELEMENT; - // Remove properties used to construct since it is already saved. + // Remove properties used to construct since it is already saved. ELEMENT.removeAttribute(`data-error`); }); }; @@ -100,7 +100,7 @@ class Page_Error extends Page { }; /* - Fill in the content of the page. + Fill in the content of the page. */ async fill () { await this.update(); @@ -113,10 +113,10 @@ class Page_Error extends Page { } /* - Add event listeners to the page. + Add event listeners to the page. */ events () { - // Add an event listener to the refresh button. + // Add an event listener to the refresh button. (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) => { @@ -133,7 +133,7 @@ class Page_Error extends Page { */ send() { try { - // Send a message to the content script. + // Send a message to the content script. Tabs.query(null, 0).then((TAB) => { chrome.tabs.sendMessage(TAB.id, {"refresh": "manual"}); }); @@ -143,4 +143,4 @@ class Page_Error extends Page { }; } -new Page_Error() \ No newline at end of file +new Page_Error() diff --git a/src/scripts/pages/popup.js b/src/scripts/pages/popup.js index 9324db7..673434e 100644 --- a/src/scripts/pages/popup.js +++ b/src/scripts/pages/popup.js @@ -18,31 +18,31 @@ class Page_Popup extends Page { }; async background() { - // Wait until a change in the session storage. + // Wait until a change in the storage. new background((changes) => { this.update(); this.switch(); }); } - /* - Update the data used by the page. + /* + 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. + // Set the reference website when overriding or unset. if (override || !this[`ref`]) {this[`ref`] = await global.read([`last`])}; - // Get all the data to be used here. + // Get all the data to be used here. let DATA = {}; DATA[`status`] = await global.read([`sites`, this[`ref`], `status`], -1); DATA[`init`] = (await global.read([`init`])) && (await global.read([`settings`,`analysis`,`api`,`key`])); - // Update all other data. + // Update all other data. this[`status`] = (DATA[`status`] != null) ? DATA[`status`] - // Accomodate data erasure. + // Accomodate data erasure. : ((this[`status`]) ? this[`status`] : {}); @@ -65,15 +65,15 @@ class Page_Popup extends Page { "OOBE": "hello.htm", "error": "error.htm" }; - // Set the width and the height. + // 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. + + // Prepare all the necessary data. this.update().then(() => { // Make sure that the website has been selected! if (this[`ref`]) { @@ -85,20 +85,20 @@ class Page_Popup extends Page { : `loading`) : `OOBE`; let PAGE = chrome.runtime.getURL(`pages/popup/`.concat(PAGES[SELECTION])); - + // Replace the iframe src with the new page. (this.elements[`frame`].src != PAGE) ? this.elements[`frame`].src = PAGE : false; - - // The results and OOBE pages has its own container. + + // The results and OOBE pages has its own container. this.elements[`container`].classList[([`results`, `OOBE`].includes(SELECTION)) ? `remove` : `add`](`container`); - // Set the title bar content. + // Set the title bar content. 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); + this[`window`][`navigation bar`][(NAME == SELECTION) ? `show` : `hide`](`header`, NAME); }); - // Set the dimensions of the body. + // Set the dimensions of the body. Object.keys(PAGES_DIMENSIONS[SELECTION]).forEach((DIMENSION) => { document.body.style[DIMENSION] = PAGES_DIMENSIONS[SELECTION][DIMENSION]; }); @@ -106,18 +106,18 @@ class Page_Popup extends Page { }); } - // Also set the loader. + // 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() { this.elements = {}; this.elements[`container`] = document.querySelector(`main`); this.elements[`frame`] = document.querySelector(`main > iframe.viewer`); this.elements[`nav`] = document.querySelector(`nav`); - + // Check if the frame is available. if (this.elements[`frame`]) { this.switch(); @@ -132,14 +132,14 @@ class Page_Popup extends Page { }; /* - Call for the scraper and analyzer. + Call for the scraper and analyzer. */ send(options) { - // Make sure that it is the correct format. + // Make sure that it is the correct format. let OPTIONS = (options && (typeof options).includes(`obj`) && !Array.isArray(options)) ? options : {}; try { - // Send a message to the content script. + // Send a message to the content script. Tabs.query(null, 0).then((TAB) => { chrome.tabs.sendMessage(TAB.id, OPTIONS); }); @@ -153,7 +153,7 @@ class Page_Popup extends Page { ACTIONS[`open,settings`] = () => {chrome.runtime.openOptionsPage();}; ACTIONS[`analysis,reload`] = () => {this.send({"refresh": "manual"});} - // Add the event listeners. + // 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) => { @@ -164,4 +164,4 @@ class Page_Popup extends Page { } } -new Page_Popup(); \ No newline at end of file +new Page_Popup(); diff --git a/src/scripts/pages/results.js b/src/scripts/pages/results.js index aac226e..6a2becf 100644 --- a/src/scripts/pages/results.js +++ b/src/scripts/pages/results.js @@ -17,68 +17,68 @@ class Page_Results extends Page { }; async background() { - // Wait until a change in the session storage. + // Wait until a change in the storage. new background((changes) => { this.update(); this.content(); - // First, update site data but retain the URL. + // First, update site data but retain the URL. }); } - /* - Update the data used by the page. + /* + 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. + // Set the reference website when overriding or unset. if (override || !this[`ref`]) { let RECORD = await global.read([`last`]); (RECORD) ? this[`ref`] = RECORD : false; }; - + if (this[`ref`]) { - // Get all the data. + // Get all the data. let DATA = { "data": await global.read([`sites`, this[`ref`]]) } - - // Set the data. + + // Set the data. this[`data`] = (DATA[`data`] && (typeof DATA[`data`]).includes(`obj`)) ? DATA[`data`] : (this[`data`] ? this[`data`] : {}); } } async content() { - // Select all the elements and add it to the object. + // Select all the elements and add it to the object. if (document.querySelectorAll(`[data-active-result]`)) { this.elements = {} document.querySelectorAll(`[data-active-result]`).forEach((ELEMENT) => { let PROPERTY = ELEMENT.getAttribute(`data-active-result`).trim(); this.elements[PROPERTY] = ELEMENT; - // Copy the expected type of sub-elements, if any. + // Copy the expected type of sub-elements, if any. if (ELEMENT.getAttribute(`data-active-result-type`)) { this.elements[PROPERTY][`target element type`] = ELEMENT.getAttribute(`data-active-result-type`).trim(); - ELEMENT.removeAttribute(`data-active-result-type`); + ELEMENT.removeAttribute(`data-active-result-type`); }; - // Remove the construction data active result. + // Remove the construction data active result. ELEMENT.removeAttribute(`data-active-result`); }); } - + await this.update(); this.fill(); } /* - Resize the window to fit the content. + Resize the window to fit the content. */ async resize() { } - /* + /* Populate the contents. */ async fill() { @@ -87,7 +87,7 @@ class Page_Results extends Page { ? (Object.keys(this.elements)).forEach(async (SOURCE) => { if (SOURCE.indexOf(`*`) < SOURCE.length - 1) { let DATA = (nested.dictionary.get(this[`data`][`analysis`], SOURCE)); - + this.elements[SOURCE][(this.elements[SOURCE].nodeName.toLowerCase().includes(`input`) || this.elements[SOURCE].nodeName.toLowerCase().includes(`progress`)) ? `value` : `innerHTML`] = (DATA) ? (((typeof DATA).includes(`obj`) && !Array.isArray(DATA)) ? JSON.stringify(DATA) @@ -95,36 +95,36 @@ class Page_Results extends Page { : null; } else if (SOURCE.indexOf(`*`) >= SOURCE.length - 1) { let DATA = (nested.dictionary.get(this[`data`][`analysis`], SOURCE.split(`,`).slice(0, -1))); - + (!Array.isArray(DATA) && (typeof DATA).includes(`obj`) && DATA != null) - + let ELEMENT_TYPES = { "container": "section", "content": "article", "title": "p", "body": "p" }; - - (DATA) + + (DATA) ? (Object.keys(DATA)).forEach((ITEM) => { let ELEMENTS = {}; - - // Create the elements. + + // Create the elements. (Object.keys(ELEMENT_TYPES)).forEach((TYPE) => { ELEMENTS[TYPE] = document.createElement(ELEMENT_TYPES[TYPE]); - + (([`content`, `action`, `title`].includes(TYPE) || TYPE.includes(`container`)) && this.elements[SOURCE][`target element type`]) ? ELEMENTS[TYPE].classList.add(this.elements[SOURCE][`target element type`].concat((!TYPE.includes(`container`)) ? `-${TYPE}` : ``)) : false; }); - + ELEMENTS[`title`].innerText = String(ITEM).trim(); ELEMENTS[`title`].classList.add(`flow-text`); ELEMENTS[`body`].innerText = String(DATA[ITEM]).trim(); - - // Inject the elements. + + // Inject the elements. [`title`, `body`].forEach((CONTENT) => { ELEMENTS[`content`].appendChild(ELEMENTS[CONTENT]); }); @@ -135,11 +135,11 @@ class Page_Results extends Page { } }) : false; - - // Set the color. + + // Set the color. (nested.dictionary.get(this[`data`][`analysis`], [`Rating`, `Trust`]) && document.querySelector(`summary`)) ? document.querySelector(`summary`).setAttribute(`result`, (nested.dictionary.get(this[`data`][`analysis`], [`Rating`, `Trust`]))) : false; } }; } -new Page_Results(); \ No newline at end of file +new Page_Results();