split the content script from watch
This commit is contained in:
		
							parent
							
								
									a226f12645
								
							
						
					
					
						commit
						3e683a7803
					
				
					 2 changed files with 63 additions and 56 deletions
				
			
		
							
								
								
									
										14
									
								
								scripts/external/content.js
									
										
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								scripts/external/content.js
									
										
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,14 @@ | ||||||
|  | /*  | ||||||
|  | content.js | ||||||
|  | 
 | ||||||
|  | The content script | ||||||
|  | */ | ||||||
|  | 
 | ||||||
|  | // Import the necessary modules.
 | ||||||
|  | (async () => { | ||||||
|  |      // Import the watchman module.
 | ||||||
|  |      let watchman = await import(chrome.runtime.getURL("scripts/external/watch.js")); | ||||||
|  |       | ||||||
|  |      // Begin the job.
 | ||||||
|  |      watchman.job(); | ||||||
|  | }) | ||||||
							
								
								
									
										105
									
								
								scripts/external/watch.js
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										105
									
								
								scripts/external/watch.js
									
										
									
									
										vendored
									
									
								
							|  | @ -2,68 +2,61 @@ | ||||||
| Be sensitive to changes and update the state. | Be sensitive to changes and update the state. | ||||||
| */ | */ | ||||||
| 
 | 
 | ||||||
| let main = (async () => { | import filters from "/scripts/filters.js"; | ||||||
| 	// Import modules.
 | import processor from "/scripts/external/processor.js"; | ||||||
| 	let filters = new ((await import(chrome.runtime.getURL("scripts/filters.js"))).default); | import logging from "/scripts/logging.js"; | ||||||
| 	const processor = (await import(chrome.runtime.getURL("scripts/external/processor.js"))).default; | import texts from "/scripts/mapping/read.js"; | ||||||
| 	const logging = (await import(chrome.runtime.getURL("scripts/logging.js"))).default; |  | ||||||
| 	const texts = (await import(chrome.runtime.getURL("scripts/strings/read.js"))).default; |  | ||||||
| 
 | 
 | ||||||
| 	class watchman { |  | ||||||
| 		/* Check the current URL. |  | ||||||
| 
 | 
 | ||||||
| 			@param {string} URL the page URL; default value is the current webpage | export default class watchman { | ||||||
| 			@return {dictionary} the filter to follow | 	/* Check the current URL. | ||||||
| 			*/ |  | ||||||
| 		static async observe(URL = window.location.href) { |  | ||||||
| 			// Create the variable to determine the corresponding key.
 |  | ||||||
| 			let activity = await filters.select(URL); |  | ||||||
| 
 | 
 | ||||||
| 			return activity; | 		@param {string} URL the page URL; default value is the current webpage | ||||||
| 		} | 		@return {dictionary} the filter to follow | ||||||
| 
 |  | ||||||
| 		/* Act on the page. |  | ||||||
| 
 |  | ||||||
| 		@param {dictionary} filters the filter to work with |  | ||||||
| 		@return {boolean} the state |  | ||||||
| 		*/ | 		*/ | ||||||
| 		static act(matches) { | 	static async observe(URL = window.location.href) { | ||||||
| 			// Let user know that the website is supported, if ever they have opened the console. 
 | 		// Create the variable to determine the corresponding key.
 | ||||||
| 			new logging((new texts(`message_external_supported`)).localized); | 		let activity = await (new filters).select(URL); | ||||||
| 			// Show loading screen while the load is incomplete. 
 |  | ||||||
| 			 |  | ||||||
| 			 |  | ||||||
| 			// Begin only when the page is fully loaded. 
 |  | ||||||
| 			window.addEventListener(`DOMContentLoaded`, (event) => { |  | ||||||
| 				// Begin processing. 
 |  | ||||||
| 				let PROC = new processor(matches); |  | ||||||
| 				 |  | ||||||
| 				// Remove the loading screen. 
 |  | ||||||
| 				 |  | ||||||
| 			}); |  | ||||||
| 		} |  | ||||||
| 
 | 
 | ||||||
| 		/* Set the program to standby utnil next load. | 		return activity; | ||||||
| 		 */ |  | ||||||
| 		static standby() { |  | ||||||
| 			// Set the icon to indicate that it's not active. 
 |  | ||||||
| 		} |  | ||||||
| 
 |  | ||||||
| 		static async job() { |  | ||||||
| 			/* The main action. */ |  | ||||||
| 
 |  | ||||||
| 			(watchman.observe()).then((RULES) => { |  | ||||||
| 				if (RULES && Object.keys(RULES).length !== 0) { |  | ||||||
| 					watchman.act(RULES); |  | ||||||
| 				} else { |  | ||||||
| 					watchman.standby(); |  | ||||||
| 				} |  | ||||||
| 			}); |  | ||||||
| 		} |  | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	watchman.job(); | 	/* Act on the page. | ||||||
| }); |  | ||||||
| 
 | 
 | ||||||
|  | 	@param {dictionary} filters the filter to work with | ||||||
|  | 	@return {boolean} the state | ||||||
|  | 	*/ | ||||||
|  | 	static act(matches) { | ||||||
|  | 		// Let user know that the website is supported, if ever they have opened the console. 
 | ||||||
|  | 		new logging((new texts(`message_external_supported`)).localized); | ||||||
|  | 		// Show loading screen while the load is incomplete. 
 | ||||||
|  | 		 | ||||||
|  | 		 | ||||||
|  | 		// Begin only when the page is fully loaded. 
 | ||||||
|  | 		window.addEventListener(`DOMContentLoaded`, (event) => { | ||||||
|  | 			// Begin processing. 
 | ||||||
|  | 			let PROC = new processor(matches); | ||||||
|  | 			 | ||||||
|  | 			// Remove the loading screen. 
 | ||||||
|  | 			 | ||||||
|  | 		}); | ||||||
|  | 	} | ||||||
| 
 | 
 | ||||||
| main(); | 	/* Set the program to standby utnil next load. | ||||||
|  | 		*/ | ||||||
|  | 	static standby() { | ||||||
|  | 		// Set the icon to indicate that it's not active. 
 | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	static async job() { | ||||||
|  | 		/* The main action. */ | ||||||
|  | 
 | ||||||
|  | 		(watchman.observe()).then((RULES) => { | ||||||
|  | 			if (RULES && Object.keys(RULES).length !== 0) { | ||||||
|  | 				watchman.act(RULES); | ||||||
|  | 			} else { | ||||||
|  | 				watchman.standby(); | ||||||
|  | 			} | ||||||
|  | 		}); | ||||||
|  | 	} | ||||||
|  | } | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue