Add support for bundling filters locally
This commit is contained in:
		
							parent
							
								
									a2cb524edd
								
							
						
					
					
						commit
						296c9af172
					
				
					 1 changed files with 37 additions and 6 deletions
				
			
		|  | @ -6,6 +6,8 @@ This script provides installation run scripts. | ||||||
| // File importation
 | // File importation
 | ||||||
| import {template, global} from "../secretariat.js"; | import {template, global} from "../secretariat.js"; | ||||||
| import pointer from "../data/pointer.js"; | import pointer from "../data/pointer.js"; | ||||||
|  | import {URLs} from "../utils/URLs.js"; | ||||||
|  | import net from "../utils/net.js"; | ||||||
| 
 | 
 | ||||||
| // The URL for the configuration file
 | // The URL for the configuration file
 | ||||||
| const config = chrome.runtime.getURL("config/config.json"); | const config = chrome.runtime.getURL("config/config.json"); | ||||||
|  | @ -41,21 +43,50 @@ export default class BackgroundImporter { | ||||||
| 			.then(async (jsonData) => { | 			.then(async (jsonData) => { | ||||||
| 				let configuration = jsonData; | 				let configuration = jsonData; | ||||||
| 				 | 				 | ||||||
| 				// Run the storage initialization.
 | 				if ((configuration) ? Object.keys(configuration).length : false) { | ||||||
| 				delete configuration[`OOBE`]; | 					// Run the storage initialization.
 | ||||||
| 				template.set(configuration); | 					delete configuration[`OOBE`]; | ||||||
|  | 				 | ||||||
|  | 					// Replace local URLs of filters to corresponding chrome extension pages.
 | ||||||
|  | 					if (((typeof configuration[`settings`][`filters`]).includes(`obj`) && configuration[`settings`][`filters`]) ? Object.keys(configuration[`settings`][`filters`]).length : false) { | ||||||
|  | 						for (let FILTER_NUMBER = 0; FILTER_NUMBER < Object.keys(configuration[`settings`][`filters`]).length; FILTER_NUMBER++) { | ||||||
|  | 							let SOURCE = (Object.keys(configuration[`settings`][`filters`]))[FILTER_NUMBER]; | ||||||
|  | 							 | ||||||
|  | 							// Check if the URL is invalid. 
 | ||||||
|  | 							 | ||||||
|  | 							if (!(URLs.test(SOURCE))) { | ||||||
|  | 								// Set the URL. 
 | ||||||
|  | 								let ORIGIN = {"raw": SOURCE}; | ||||||
|  | 								 | ||||||
|  | 								// If it is, it's most likely located within the extension. 
 | ||||||
|  | 								ORIGIN[`local`] = chrome.runtime.getURL(`config/filters/`.concat(ORIGIN[`raw`])); | ||||||
|  | 								 | ||||||
|  | 								// Attempt to verify the existence of the file. 
 | ||||||
|  | 								if (await net.download(ORIGIN[`local`], `json`, true)) { | ||||||
|  | 									configuration[`settings`][`filters`][ORIGIN[`local`]] = configuration[`settings`][`filters`][ORIGIN[`raw`]]; | ||||||
|  | 								}; | ||||||
|  | 								 | ||||||
|  | 								// Delete the illegal URLs. 
 | ||||||
|  | 								delete configuration[`settings`][`filters`][ORIGIN[`raw`]]; | ||||||
|  | 							}; | ||||||
|  | 						}; | ||||||
|  | 					}; | ||||||
|  | 					 | ||||||
|  | 					// Set the template. 
 | ||||||
|  | 					template.set(configuration); | ||||||
|  | 				}; | ||||||
| 			}) | 			}) | ||||||
| 			.catch((error) => { | 			.catch((error) => { | ||||||
| 				console.error(error); | 				console.error(error); | ||||||
| 			}); | 			}); | ||||||
| 	} | 	}; | ||||||
| 	 | 	 | ||||||
| 	trigger() { | 	trigger() { | ||||||
| 		chrome.runtime.onInstalled.addListener((details) => { | 		chrome.runtime.onInstalled.addListener((details) => { | ||||||
| 			(details.reason == chrome.runtime.OnInstalledReason.INSTALL) ? this.hello() : null; | 			(details.reason == chrome.runtime.OnInstalledReason.INSTALL) ? this.hello() : null; | ||||||
| 			this.setup(); | 			this.setup(); | ||||||
| 		}); | 		}); | ||||||
| 	} | 	}; | ||||||
| 
 | 
 | ||||||
| 	// main function 
 | 	// main function 
 | ||||||
| 	constructor () { | 	constructor () { | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue