work on filter selection as OOP
Initializing the filters set its object to the filters stored in memory. To select one, first run select and then you can access it via "one" key.
This commit is contained in:
		
							parent
							
								
									d8380020a4
								
							
						
					
					
						commit
						917266dfd2
					
				
					 1 changed files with 122 additions and 103 deletions
				
			
		|  | @ -11,8 +11,21 @@ export default class filters { | ||||||
| 
 | 
 | ||||||
| 	@param {string} URL the current URL | 	@param {string} URL the current URL | ||||||
| 	*/ | 	*/ | ||||||
|   static select(URL = window.location.href) { | 	static async select(URL = window.location.href) { | ||||||
|     this.one = {}; | 		this.one = await (async () => { | ||||||
|  | 			// Import the secretariat.
 | ||||||
|  | 			const secretariat = await import( | ||||||
|  | 				chrome.runtime.getURL("scripts/secretariat.js") | ||||||
|  | 			); | ||||||
|  | 
 | ||||||
|  | 			// Get the filters.
 | ||||||
|  | 			let filter = (await secretariat.read(`filters`, -1, {"field": "URL", "test value": URL})); | ||||||
|  | 
 | ||||||
|  | 			// If there are filters, then filter the URL.
 | ||||||
|  | 			return (filter); | ||||||
|  | 		})(); | ||||||
|  | 
 | ||||||
|  | 		return (this.one); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	/* Update all filters or just one. | 	/* Update all filters or just one. | ||||||
|  | @ -21,7 +34,7 @@ export default class filters { | ||||||
| 	@return {boolean} the state | 	@return {boolean} the state | ||||||
| 	*/ | 	*/ | ||||||
| 	static update(URL) { | 	static update(URL) { | ||||||
|     (async () => { | 		this.all = (async () => { | ||||||
| 			// Import the updater.
 | 			// Import the updater.
 | ||||||
| 			const secretariat = await import( | 			const secretariat = await import( | ||||||
| 				chrome.runtime.getURL("scripts/secretariat.js") | 				chrome.runtime.getURL("scripts/secretariat.js") | ||||||
|  | @ -101,6 +114,7 @@ export default class filters { | ||||||
| 									), | 									), | ||||||
| 								); | 								); | ||||||
| 							} | 							} | ||||||
|  | 							 | ||||||
| 						}) | 						}) | ||||||
| 						.catch((error) => { | 						.catch((error) => { | ||||||
| 							// Inform the user of the download failure.
 | 							// Inform the user of the download failure.
 | ||||||
|  | @ -117,6 +131,11 @@ export default class filters { | ||||||
| 				// Inform the user of the download being unnecessary.
 | 				// Inform the user of the download being unnecessary.
 | ||||||
| 				alerts.warn(texts.localized(`settings_filters_update_stop`)); | 				alerts.warn(texts.localized(`settings_filters_update_stop`)); | ||||||
| 			} | 			} | ||||||
|  | 
 | ||||||
|  | 			// Regardless of the download result, update will also mean setting the filters object to whatever is in storage. 
 | ||||||
|  | 			return(secretariat.read(`filters`, -1).then((filters) => { | ||||||
|  | 				return(filters) | ||||||
|  | 			})); | ||||||
| 		})(); | 		})(); | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue