From d586ef8115af684a5466e97fcfd93a33cc36d86d Mon Sep 17 00:00:00 2001 From: buzz-lightsnack-2007 <73412182+buzz-lightsnack-2007@users.noreply.github.com> Date: Mon, 6 May 2024 11:48:54 +0800 Subject: [PATCH 1/9] add error symbol --- media/config.symbols.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/media/config.symbols.json b/media/config.symbols.json index 6e36d7a..cabf712 100644 --- a/media/config.symbols.json +++ b/media/config.symbols.json @@ -1,4 +1,7 @@ { + "extensionIcon_product_error": { + "symbol": "⚠" + }, "extensionIcon_product_bad": { "symbol": "👎" }, @@ -15,6 +18,6 @@ "symbol": "✕" }, "extensionIcon_website_loading": { - "symbol": "..." + "symbol": "…" } } \ No newline at end of file From 1f7661ff121311aa1998bb4d94b312f6754d62f2 Mon Sep 17 00:00:00 2001 From: buzz-lightsnack-2007 <73412182+buzz-lightsnack-2007@users.noreply.github.com> Date: Mon, 6 May 2024 11:51:24 +0800 Subject: [PATCH 2/9] Unpackage an error object --- scripts/logging.js | 7 +++++++ 1 file changed, 7 insertions(+) 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, ``); From 61af4d11437271ad8d62629497dd586fba365c9e Mon Sep 17 00:00:00 2001 From: buzz-lightsnack-2007 <73412182+buzz-lightsnack-2007@users.noreply.github.com> Date: Mon, 6 May 2024 11:52:03 +0800 Subject: [PATCH 3/9] Use the logging to display the error message --- scripts/mapping/read.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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); })); }; } From ec7e085aeec1ffc3f1967a3d53e81761eaed0b90 Mon Sep 17 00:00:00 2001 From: buzz-lightsnack-2007 <73412182+buzz-lightsnack-2007@users.noreply.github.com> Date: Mon, 6 May 2024 11:57:46 +0800 Subject: [PATCH 4/9] rename the error symbol It's not really under the product information. --- media/config.symbols.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/media/config.symbols.json b/media/config.symbols.json index cabf712..1ac23fe 100644 --- a/media/config.symbols.json +++ b/media/config.symbols.json @@ -1,11 +1,11 @@ { - "extensionIcon_product_error": { + "extensionIcon_error": { "symbol": "⚠" }, "extensionIcon_product_bad": { "symbol": "👎" }, - "extensionIcon_product_OK": { + "extensionIcon_product_ok": { "symbol": "🆗" }, "extensionIcon_product_good": { From 0498c62339459f80b38f2f89239e3047bdcd753a Mon Sep 17 00:00:00 2001 From: buzz-lightsnack-2007 <73412182+buzz-lightsnack-2007@users.noreply.github.com> Date: Mon, 6 May 2024 12:07:48 +0800 Subject: [PATCH 5/9] add error icon color --- styles/colors/icon.JSON | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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 From b21fa1438dca87b540bae82818217e7e3867fc61 Mon Sep 17 00:00:00 2001 From: buzz-lightsnack-2007 <73412182+buzz-lightsnack-2007@users.noreply.github.com> Date: Mon, 6 May 2024 12:13:54 +0800 Subject: [PATCH 6/9] enable icon changes when necessary and add the onclick event Onclick event currently not yet linked --- scripts/GUI/entrypoints/iconindicator.js | 90 ++++++++++++++++++++---- 1 file changed, 78 insertions(+), 12 deletions(-) diff --git a/scripts/GUI/entrypoints/iconindicator.js b/scripts/GUI/entrypoints/iconindicator.js index bb9c240..1086519 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"); @@ -12,12 +11,60 @@ class IconIndicator { */ 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}); + + // Enable icon changes if enabled within the settings. + global.read([`settings`, `behavior`, `showApplicable`]).then(async (PREFERENCE) => {(PREFERENCE) + ? fetch(CONFIG).then((response) => response.json()).then((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) => { + ((typeof RESULTS).includes(`str`)) ? RESULTS.trim() : false; + (RESULTS) ? BrowserIcon.set({ + "BadgeText": await (new texts(`extensionIcon_product_`.concat(RESULTS))).symbol, + "BadgeBackgroundColor": ICON_COLORS[`product_`.concat(RESULTS)] + }, {"tabId": ID}) : false; + }) + }; + }; + }); + } + + + (Tabs.query(null, 0)).then(async (TAB) => { + // Get the URL of the tab. + let LOCATION = TAB.url; + + 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 +72,15 @@ 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`, `behavior`, `showApplicable`]).then((PREFERENCE) => { + (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}); + }) }) } @@ -41,6 +92,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 From 4d1958d13f8e19f4c2be097c74844036d6891e3e Mon Sep 17 00:00:00 2001 From: buzz-lightsnack-2007 <73412182+buzz-lightsnack-2007@users.noreply.github.com> Date: Mon, 6 May 2024 13:03:18 +0800 Subject: [PATCH 7/9] Merge the strings update from 'storage' --- _locales/en/messages.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 266a8c0..6f59544 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -118,7 +118,7 @@ "message": "Update" }, "settings_filters_update_status": { - "message": "Updating the filter at $filter_url$…", + "message": "Updating…", "placeholders": { "filter_url": { "content": "$1" @@ -126,7 +126,7 @@ } }, "settings_filters_update_status_complete": { - "message": "Updated the filter at $filter_url$.", + "message": "Update complete.", "placeholders": { "filter_url": { "content": "$1" From a723791d1bccbe602e3a6aef26d4b7b65c54b4a2 Mon Sep 17 00:00:00 2001 From: buzz-lightsnack-2007 <73412182+buzz-lightsnack-2007@users.noreply.github.com> Date: Mon, 6 May 2024 13:03:35 +0800 Subject: [PATCH 8/9] rename the source preference for icon display --- scripts/GUI/entrypoints/iconindicator.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/scripts/GUI/entrypoints/iconindicator.js b/scripts/GUI/entrypoints/iconindicator.js index 1086519..4fda646 100644 --- a/scripts/GUI/entrypoints/iconindicator.js +++ b/scripts/GUI/entrypoints/iconindicator.js @@ -10,10 +10,10 @@ class IconIndicator { Indicate that the website is supported through icon change. */ static enable() { - BrowserIcon.enable(); + BrowserIcon.enable(); // Enable icon changes if enabled within the settings. - global.read([`settings`, `behavior`, `showApplicable`]).then(async (PREFERENCE) => {(PREFERENCE) + global.read([`settings`, `general`, `showApplicable`]).then((PREFERENCE) => {(PREFERENCE) ? fetch(CONFIG).then((response) => response.json()).then((jsonData) => { const ICON_COLORS = jsonData; @@ -35,7 +35,6 @@ class IconIndicator { if (STATUS[`done`]) { global.read([`sites`, LOCATION, `analysis`, `Rating`, `Trust`]).then(async (RESULTS) => { - ((typeof RESULTS).includes(`str`)) ? RESULTS.trim() : false; (RESULTS) ? BrowserIcon.set({ "BadgeText": await (new texts(`extensionIcon_product_`.concat(RESULTS))).symbol, "BadgeBackgroundColor": ICON_COLORS[`product_`.concat(RESULTS)] @@ -74,7 +73,7 @@ class IconIndicator { BrowserIcon.disable(); // Enable icon changes if enabled within the settings. - global.read([`settings`, `behavior`, `showApplicable`]).then((PREFERENCE) => { + global.read([`settings`, `general`, `showApplicable`]).then((PREFERENCE) => { (Tabs.query(null, 0)).then(async (TAB) => { BrowserIcon.set({ "BadgeText": await (new texts(`extensionIcon_website_unsupported`)).symbol, From fa97743fc8fd76a06e10a9955d91c42476a7612b Mon Sep 17 00:00:00 2001 From: buzz-lightsnack-2007 <73412182+buzz-lightsnack-2007@users.noreply.github.com> Date: Mon, 6 May 2024 13:41:07 +0800 Subject: [PATCH 9/9] Improve icon display --- scripts/GUI/entrypoints/iconindicator.js | 82 ++++++++++++------------ 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/scripts/GUI/entrypoints/iconindicator.js b/scripts/GUI/entrypoints/iconindicator.js index 4fda646..1f1e419 100644 --- a/scripts/GUI/entrypoints/iconindicator.js +++ b/scripts/GUI/entrypoints/iconindicator.js @@ -13,43 +13,42 @@ class IconIndicator { BrowserIcon.enable(); // Enable icon changes if enabled within the settings. - global.read([`settings`, `general`, `showApplicable`]).then((PREFERENCE) => {(PREFERENCE) - ? fetch(CONFIG).then((response) => response.json()).then((jsonData) => { - const ICON_COLORS = jsonData; + (Tabs.query(null, 0)).then((TAB) => { + // Get the URL of the tab. + const LOCATION = TAB.url; - /* - Show an iconified summary of the results. + global.read([`settings`, `general`, `showApplicable`]).then((PREFERENCE) => {(PREFERENCE) + ? fetch(CONFIG).then((response) => response.json()).then(async (jsonData) => { + const ICON_COLORS = jsonData; - @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; - }) - }; - }; - }); - } - - - (Tabs.query(null, 0)).then(async (TAB) => { - // Get the URL of the tab. - let LOCATION = TAB.url; + /* + 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`] @@ -58,12 +57,11 @@ class IconIndicator { showDetails(LOCATION, TAB.id); observe((changes) => { showDetails(LOCATION, TAB.id); - }) - }); + }); + }) + : false; }) - : false; }) - } /* @@ -75,10 +73,12 @@ class IconIndicator { // Enable icon changes if enabled within the settings. global.read([`settings`, `general`, `showApplicable`]).then((PREFERENCE) => { (Tabs.query(null, 0)).then(async (TAB) => { - BrowserIcon.set({ + (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}); + "BadgeBackgroundColor": await fetch(CONFIG).then((response) => response.json()).then((jsonData) => {return (jsonData[`N/A`]);})}, + {"tabId": TAB.id}) + : false; }) }) }