Merge branch 'development-GUI' into development-scraper

This commit is contained in:
buzz-lightsnack-2007 2024-05-06 14:17:02 +08:00
commit 95c80173db
5 changed files with 102 additions and 17 deletions

View file

@ -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": ""
}
}

View file

@ -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};

View file

@ -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, ``);

View file

@ -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);
}));
};
}

View file

@ -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)" }
{
"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)"
}