diff --git a/media/config.symbols.json b/media/config.symbols.json index 6e36d7a..1ac23fe 100644 --- a/media/config.symbols.json +++ b/media/config.symbols.json @@ -1,8 +1,11 @@ { + "extensionIcon_error": { + "symbol": "⚠" + }, "extensionIcon_product_bad": { "symbol": "👎" }, - "extensionIcon_product_OK": { + "extensionIcon_product_ok": { "symbol": "🆗" }, "extensionIcon_product_good": { @@ -15,6 +18,6 @@ "symbol": "✕" }, "extensionIcon_website_loading": { - "symbol": "..." + "symbol": "…" } } \ No newline at end of file diff --git a/scripts/GUI/entrypoints/iconindicator.js b/scripts/GUI/entrypoints/iconindicator.js index bb9c240..1f1e419 100644 --- a/scripts/GUI/entrypoints/iconindicator.js +++ b/scripts/GUI/entrypoints/iconindicator.js @@ -1,8 +1,7 @@ import BrowserIcon from '/scripts/GUI/browsericon.js'; -import Image from '/scripts/mapping/image.js'; import Tabs from '/scripts/GUI/tabs.js'; import texts from "/scripts/mapping/read.js"; -import {session} from '/scripts/secretariat.js'; +import {global, observe} from "/scripts/secretariat.js"; const CONFIG = chrome.runtime.getURL("styles/colors/icon.json"); @@ -11,12 +10,57 @@ class IconIndicator { Indicate that the website is supported through icon change. */ static enable() { - BrowserIcon.enable(); - (Tabs.query(null, 0)).then(async (TAB) => { - BrowserIcon.set({ - "BadgeText": await (new texts(`extensionIcon_website_loading`)).symbol, - "BadgeBackgroundColor": await fetch(CONFIG).then((response) => response.json()).then((jsonData) => {return (jsonData[`loading`]);}) - }, {"tabId": TAB.id}); + BrowserIcon.enable(); + + // Enable icon changes if enabled within the settings. + (Tabs.query(null, 0)).then((TAB) => { + // Get the URL of the tab. + const LOCATION = TAB.url; + + global.read([`settings`, `general`, `showApplicable`]).then((PREFERENCE) => {(PREFERENCE) + ? fetch(CONFIG).then((response) => response.json()).then(async (jsonData) => { + const ICON_COLORS = jsonData; + + /* + Show an iconified summary of the results. + + @param {string} location the URL of the page + @param {string} ID the tab's ID + */ + function showDetails(location, ID) { + let LOCATION = location; + // If the tab data is ready, change the icon to reflect the results. + global.read([`sites`, LOCATION, `status`]).then(async (STATUS) => { + if (STATUS) { + (STATUS[`error`]) ? BrowserIcon.set({ + "BadgeText": await (new texts(`extensionIcon_error`)).symbol, + "BadgeBackgroundColor": ICON_COLORS[`error`] + }, {"tabId": ID}) : false; + + if (STATUS[`done`]) { + global.read([`sites`, LOCATION, `analysis`, `Rating`, `Trust`]).then(async (RESULTS) => { + (RESULTS) ? BrowserIcon.set({ + "BadgeText": await (new texts(`extensionIcon_product_`.concat(RESULTS))).symbol, + "BadgeBackgroundColor": ICON_COLORS[`product_`.concat(RESULTS)] + }, {"tabId": ID}) : false; + }) + }; + }; + }); + } + + BrowserIcon.set({ + "BadgeText": await (new texts(`extensionIcon_website_loading`)).symbol, + "BadgeBackgroundColor": ICON_COLORS[`loading`] + }, {"tabId": TAB.id}); + + showDetails(LOCATION, TAB.id); + observe((changes) => { + showDetails(LOCATION, TAB.id); + }); + }) + : false; + }) }) } @@ -25,11 +69,17 @@ class IconIndicator { */ static disable() { BrowserIcon.disable(); - (Tabs.query(null, 0)).then(async (TAB) => { - BrowserIcon.set({ - "BadgeText": await (new texts(`extensionIcon_website_unsupported`)).symbol, - "BadgeBackgroundColor": await fetch(CONFIG).then((response) => response.json()).then((jsonData) => {return (jsonData[`N/A`]);}) - }, {"tabId": TAB.id}); + + // Enable icon changes if enabled within the settings. + global.read([`settings`, `general`, `showApplicable`]).then((PREFERENCE) => { + (Tabs.query(null, 0)).then(async (TAB) => { + (PREFERENCE) + ? BrowserIcon.set({ + "BadgeText": await (new texts(`extensionIcon_website_unsupported`)).symbol, + "BadgeBackgroundColor": await fetch(CONFIG).then((response) => response.json()).then((jsonData) => {return (jsonData[`N/A`]);})}, + {"tabId": TAB.id}) + : false; + }) }) } @@ -41,6 +91,21 @@ class IconIndicator { static set(callback) { BrowserIcon.addActionListener("onClicked", callback); } + + /* + The action when the icon is clicked. + */ + static onclick() { + // Check if autorunning is not enabled. + (global.read([`settings`, `behavior`, `autoRun`])).then((result) => { + if (!result) { + (Tabs.query(null, 0)).then((TAB) => { + // Tell the content script to begin scraping the page. + chrome.tabs.sendMessage(TAB.id, {"refresh": true}); + }); + } + }); + } } export {IconIndicator as default}; \ No newline at end of file diff --git a/scripts/logging.js b/scripts/logging.js index 70087d3..57a7ccb 100644 --- a/scripts/logging.js +++ b/scripts/logging.js @@ -71,6 +71,13 @@ export default class logging { @param {boolean} critical the critical nature */ static async error(ERROR_CODE, ERROR_MESSAGE, ERROR_STACK, critical = true) { + // Depackage the shortcut method of sending the error message. + (!ERROR_MESSAGE && !ERROR_STACK && (typeof ERROR_CODE).includes(`obj`)) ? ( + ERROR_MESSAGE = ERROR_CODE.message, + ERROR_STACK = ERROR_CODE.stack, + ERROR_CODE = ERROR_CODE.name + ) : false; + // Display the error message. console.error('%c%s%c%s%c%s%c\n%s%c', `font-weight: bold;`, ERROR_CODE, ``, `: `, ``, ERROR_MESSAGE, `font-family: monospace;`, ERROR_STACK, ``); diff --git a/scripts/mapping/read.js b/scripts/mapping/read.js index 6d33616..eb1d210 100644 --- a/scripts/mapping/read.js +++ b/scripts/mapping/read.js @@ -1,6 +1,8 @@ /* read_universal Read a file stored in the universal strings. */ +import logging from "/scripts/logging.js"; + export default class texts { /* This reads the message from its source. This is a fallback for the content scripts, who doesn't appear to read classes. @@ -54,7 +56,7 @@ export default class texts { return (SYMBOL); }) .catch((error) => { - console.error(error); + logging.error(error.name, null, null, false); })); }; } diff --git a/styles/colors/icon.JSON b/styles/colors/icon.JSON index 00c06ea..589d37e 100644 --- a/styles/colors/icon.JSON +++ b/styles/colors/icon.JSON @@ -1 +1,9 @@ -{ "loading": "rgb(255, 134, 57)", "N/A": "rgb(127, 127, 127)", "product_bad": "rgba(255, 0, 0)", "product_OK": "rgba(255, 255, 0)", "product_good": "rgb(0, 255, 0)", "product_trusted": "rgb(0, 255, 0)" } \ No newline at end of file +{ + "loading": "rgb(255, 134, 57)", + "N/A": "rgb(127, 127, 127)", + "error": "rgb(255, 0, 0)", + "product_bad": "rgba(255, 0, 0)", + "product_OK": "rgba(255, 255, 0)", + "product_good": "rgb(0, 255, 0)", + "product_trusted": "rgb(0, 255, 0)" +} \ No newline at end of file