Merge branch 'development-GUI' of https://codeberg.org/buzzcode2007/ShopAI into development-GUI
This commit is contained in:
		
						commit
						4ed6285e29
					
				
					 7 changed files with 105 additions and 34 deletions
				
			
		|  | @ -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" | ||||
|  |  | |||
|  | @ -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": "…" | ||||
| 	} | ||||
| } | ||||
|  | @ -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,11 +11,57 @@ 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}); | ||||
| 		BrowserIcon.addActionListener("onClicked", () => {BrowserIcon.onclick();}); | ||||
| 
 | ||||
| 		// 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,21 +70,34 @@ 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}); | ||||
| 		BrowserIcon.removeActionListener("onClicked", () => {BrowserIcon.onclick();}); | ||||
| 
 | ||||
| 		// 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; | ||||
| 			}) | ||||
| 		}) | ||||
| 	} | ||||
| 
 | ||||
| 	/* | ||||
| 	Set the function.  | ||||
| 	 | ||||
| 	@param {function} callback the function to run. | ||||
| 	The action when the icon is clicked. | ||||
| 	*/ | ||||
| 	static set(callback) { | ||||
| 		BrowserIcon.addActionListener("onClicked", callback); | ||||
| 	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}); | ||||
| 				}); | ||||
| 			} | ||||
| 		}); | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
|  |  | |||
							
								
								
									
										13
									
								
								scripts/external/watch.js
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										13
									
								
								scripts/external/watch.js
									
										
									
									
										vendored
									
									
								
							|  | @ -9,22 +9,16 @@ import texts from "/scripts/mapping/read.js"; | |||
| import {global} from "/scripts/secretariat.js"; | ||||
| 
 | ||||
| export default class watch { | ||||
| 	/* Open relevant graphical user interfaces.  | ||||
| 	*/ | ||||
| 	static callGUI() { | ||||
| 		 | ||||
| 	} | ||||
| 
 | ||||
| 	/* Act on the page. | ||||
| 
 | ||||
| 	@param {object} filter the filter to work with | ||||
| 	@param {object} options the options | ||||
| 	*/ | ||||
| 	static async process(filter, options) { | ||||
| 	static async process(filter, options = {}) { | ||||
| 		document.onreadystatechange = async () => { | ||||
| 			if (document.readyState == 'complete' && (await global.read([`settings`, `behavior`, `autoRun`]) || ((typeof options).includes(`object`) && options != null) ? options[`override`] : false)) { | ||||
| 			if (document.readyState == 'complete' && (await global.read([`settings`, `behavior`, `autoRun`]) || ((((typeof options).includes(`object`) && options) ? Object.hasOwn(options, `override`) : false) ? options[`override`] : false))) { | ||||
| 				new logging((new texts(`scrape_msg_ready`)).localized); | ||||
| 				this.processed = (override || this.processed == null) ? new processor(filter) : this.processed; | ||||
| 				this.processed = (((options && typeof options == `object`) ? options[`override`] : false) || this.processed == null) ? new processor(filter) : this.processed; | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
|  | @ -36,7 +30,6 @@ export default class watch { | |||
| 				new logging((new texts(`message_external_supported`)).localized); | ||||
| 
 | ||||
| 				watch.process(FILTER_RESULT); | ||||
| 				watch.callGUI(); | ||||
| 				 | ||||
| 				// Create a listener for messages indicating re-processing. 
 | ||||
| 				chrome.runtime.onMessage.addListener(async (message, sender, sendResponse) => { | ||||
|  |  | |||
|  | @ -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, ``); | ||||
| 		 | ||||
|  |  | |||
|  | @ -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); | ||||
| 			})); | ||||
| 	}; | ||||
| } | ||||
|  |  | |||
|  | @ -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)" | ||||
| } | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue