Merge branch 'development-GUI' into development-scraper
This commit is contained in:
		
						commit
						95c80173db
					
				
					 5 changed files with 102 additions and 17 deletions
				
			
		|  | @ -1,8 +1,11 @@ | ||||||
| { | { | ||||||
|  | 	"extensionIcon_error": { | ||||||
|  | 		"symbol": "⚠" | ||||||
|  | 	}, | ||||||
| 	"extensionIcon_product_bad": { | 	"extensionIcon_product_bad": { | ||||||
| 		"symbol": "👎" | 		"symbol": "👎" | ||||||
| 	}, | 	}, | ||||||
| 	"extensionIcon_product_OK": { | 	"extensionIcon_product_ok": { | ||||||
| 		"symbol": "🆗" | 		"symbol": "🆗" | ||||||
| 	}, | 	}, | ||||||
| 	"extensionIcon_product_good": { | 	"extensionIcon_product_good": { | ||||||
|  | @ -15,6 +18,6 @@ | ||||||
| 		"symbol": "✕" | 		"symbol": "✕" | ||||||
| 	}, | 	}, | ||||||
| 	"extensionIcon_website_loading": { | 	"extensionIcon_website_loading": { | ||||||
| 		"symbol": "..." | 		"symbol": "…" | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  | @ -1,8 +1,7 @@ | ||||||
| import BrowserIcon from '/scripts/GUI/browsericon.js'; | import BrowserIcon from '/scripts/GUI/browsericon.js'; | ||||||
| import Image from '/scripts/mapping/image.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 {session} from '/scripts/secretariat.js'; | import {global, observe} from "/scripts/secretariat.js"; | ||||||
| 
 | 
 | ||||||
| const CONFIG = chrome.runtime.getURL("styles/colors/icon.json"); | const CONFIG = chrome.runtime.getURL("styles/colors/icon.json"); | ||||||
| 
 | 
 | ||||||
|  | @ -11,12 +10,57 @@ class IconIndicator { | ||||||
| 	Indicate that the website is supported through icon change.  | 	Indicate that the website is supported through icon change.  | ||||||
| 	*/ | 	*/ | ||||||
| 	static enable() { | 	static enable() { | ||||||
| 		BrowserIcon.enable(); | 		BrowserIcon.enable();		 | ||||||
| 		(Tabs.query(null, 0)).then(async (TAB) => { | 
 | ||||||
| 			BrowserIcon.set({ | 		// Enable icon changes if enabled within the settings. 
 | ||||||
| 					"BadgeText": await (new texts(`extensionIcon_website_loading`)).symbol, | 		(Tabs.query(null, 0)).then((TAB) => { | ||||||
| 					"BadgeBackgroundColor": await fetch(CONFIG).then((response) => response.json()).then((jsonData) => {return (jsonData[`loading`]);}) | 			// Get the URL of the tab. 
 | ||||||
| 				}, {"tabId": TAB.id}); | 			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() { | 	static disable() { | ||||||
| 		BrowserIcon.disable(); | 		BrowserIcon.disable(); | ||||||
| 		(Tabs.query(null, 0)).then(async (TAB) => { | 
 | ||||||
| 			BrowserIcon.set({ | 		// Enable icon changes if enabled within the settings. 
 | ||||||
| 					"BadgeText": await (new texts(`extensionIcon_website_unsupported`)).symbol, | 		global.read([`settings`, `general`, `showApplicable`]).then((PREFERENCE) => { | ||||||
| 					"BadgeBackgroundColor": await fetch(CONFIG).then((response) => response.json()).then((jsonData) => {return (jsonData[`N/A`]);}) | 			(Tabs.query(null, 0)).then(async (TAB) => { | ||||||
| 				}, {"tabId": TAB.id}); | 				(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) { | 	static set(callback) { | ||||||
| 		BrowserIcon.addActionListener("onClicked", 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}; | export {IconIndicator as default}; | ||||||
|  | @ -71,6 +71,13 @@ export default class logging { | ||||||
| 	@param {boolean} critical the critical nature | 	@param {boolean} critical the critical nature | ||||||
| 	*/ | 	*/ | ||||||
| 	static async error(ERROR_CODE, ERROR_MESSAGE, ERROR_STACK, critical = true) { | 	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.
 | 		// 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, ``); | 		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_universal | ||||||
| 	Read a file stored in the universal strings. */ | 	Read a file stored in the universal strings. */ | ||||||
| 
 | 
 | ||||||
|  | import logging from "/scripts/logging.js"; | ||||||
|  | 
 | ||||||
| export default class texts { | 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. | 	/* 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); | 				return (SYMBOL); | ||||||
| 			}) | 			}) | ||||||
| 			.catch((error) => { | 			.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