Display the website's status via selecting the cleaned URL

This commit is contained in:
buzz-lightsnack-2007 2024-05-08 22:04:43 +08:00
parent 716be06ef4
commit 3d1c653138

View file

@ -2,6 +2,7 @@ import BrowserIcon from '/scripts/GUI/browsericon.js';
import Tabs from '/scripts/GUI/tabs.js'; import Tabs from '/scripts/GUI/tabs.js';
import texts from "/scripts/mapping/read.js"; import texts from "/scripts/mapping/read.js";
import {global, observe} from "/scripts/secretariat.js"; import {global, observe} from "/scripts/secretariat.js";
import {URLs} from "/scripts/utils/URLs.js";
const CONFIG = chrome.runtime.getURL("styles/colors/icon.json"); const CONFIG = chrome.runtime.getURL("styles/colors/icon.json");
@ -16,7 +17,7 @@ class IconIndicator {
// Enable icon changes if enabled within the settings. // Enable icon changes if enabled within the settings.
(Tabs.query(null, 0)).then((TAB) => { (Tabs.query(null, 0)).then((TAB) => {
// Get the URL of the tab. // Get the URL of the tab.
const LOCATION = TAB.url; const LOCATION = URLs.clean(TAB.url);
global.read([`settings`, `general`, `showApplicable`]).then((PREFERENCE) => {(PREFERENCE) global.read([`settings`, `general`, `showApplicable`]).then((PREFERENCE) => {(PREFERENCE)
? fetch(CONFIG).then((response) => response.json()).then(async (jsonData) => { ? fetch(CONFIG).then((response) => response.json()).then(async (jsonData) => {
@ -31,14 +32,14 @@ class IconIndicator {
function showDetails(location, ID) { function showDetails(location, ID) {
let LOCATION = location; let LOCATION = location;
// If the tab data is ready, change the icon to reflect the results. // If the tab data is ready, change the icon to reflect the results.
global.read([`sites`, LOCATION, `status`]).then(async (STATUS) => { global.read([`sites`, LOCATION, `status`], -1).then(async (STATUS) => {
if (STATUS) { if (STATUS) {
(STATUS[`error`]) ? BrowserIcon.set({ (STATUS[`error`]) ? BrowserIcon.set({
"BadgeText": await (new texts(`extensionIcon_error`)).symbol, "BadgeText": await (new texts(`extensionIcon_error`)).symbol,
"BadgeBackgroundColor": ICON_COLORS[`error`] "BadgeBackgroundColor": ICON_COLORS[`error`]
}, {"tabId": ID}) : false; }, {"tabId": ID}) : false;
if (STATUS[`done`]) { if ((STATUS[`done`] && (typeof STATUS[`done`]).includes(`num`)) ? STATUS[`done`] >= 1 : false) {
global.read([`sites`, LOCATION, `analysis`, `Rating`, `Trust`]).then(async (RESULTS) => { global.read([`sites`, LOCATION, `analysis`, `Rating`, `Trust`]).then(async (RESULTS) => {
(RESULTS) ? BrowserIcon.set({ (RESULTS) ? BrowserIcon.set({
"BadgeText": await (new texts(`extensionIcon_product_`.concat(RESULTS))).symbol, "BadgeText": await (new texts(`extensionIcon_product_`.concat(RESULTS))).symbol,