improve import method
This commit is contained in:
		
							parent
							
								
									16e57f45fc
								
							
						
					
					
						commit
						be0f4334f7
					
				
					 1 changed files with 35 additions and 37 deletions
				
			
		|  | @ -3,13 +3,15 @@ | ||||||
| */ | */ | ||||||
| 
 | 
 | ||||||
| // Import modules.
 | // Import modules.
 | ||||||
| //import { windowman } from "../windowman.js";
 |  | ||||||
| 
 |  | ||||||
| import {global} from "/scripts/secretariat.js"; | import {global} from "/scripts/secretariat.js"; | ||||||
| import Page from "/scripts/pages/page.js"; | import Page from "/scripts/pages/page.js"; | ||||||
| import texts from "/scripts/mapping/read.js"; | import texts from "/scripts/mapping/read.js"; | ||||||
|  | import filters from "/scripts/filters.js"; | ||||||
|  | import logging from "/scripts/logging.js"; | ||||||
| 
 | 
 | ||||||
| class Page_Settings extends Page { | class Page_Settings extends Page { | ||||||
|  | 	data = {}; | ||||||
|  | 
 | ||||||
| 	constructor() { | 	constructor() { | ||||||
| 		super(); | 		super(); | ||||||
| 		(this.events) ? this.events() : false; | 		(this.events) ? this.events() : false; | ||||||
|  | @ -37,51 +39,47 @@ class Page_Settings extends Page { | ||||||
| 				.querySelector(`[data-action="filters,add,one"]`) | 				.querySelector(`[data-action="filters,add,one"]`) | ||||||
| 				.addEventListener(`click`, async () => { | 				.addEventListener(`click`, async () => { | ||||||
| 					// Import the filters module.
 | 					// Import the filters module.
 | ||||||
| 					let filters = new ( | 					this.data.filters = (this.data.filters) ? this.data.filters : new filters(); | ||||||
| 						await import(chrome.runtime.getURL(`scripts/filters.js`)) | 
 | ||||||
| 					).default(); | 					// Update all of the filters. 
 | ||||||
| 					 | 					filters.update(`*`); | ||||||
| 					let filter_source = prompt( | 				}) | ||||||
| 						texts.localized(`settings_filters_add_prompt`), | 			: false; | ||||||
| 					); | 	 | ||||||
| 					if (filter_source ? filter_source.trim() : false) { | 		(document.querySelector(`[data-action="filters,add,one"]`)) | ||||||
| 						filters.update(filter_source.trim()); | 			? document.querySelector(`[data-action="filters,add,one"]`).addEventListener(`click`, async () => { | ||||||
|  | 				// Import the filters module.
 | ||||||
|  | 				this.data.filters = (this.data.filters) ? this.data.filters : new filters(); | ||||||
|  | 				// Request for the filter URL. 
 | ||||||
|  | 				let FILTER_SOURCE = prompt(texts.localized(`settings_filters_add_prompt`)); | ||||||
|  | 
 | ||||||
|  | 				// Update the filter if the source is not empty.
 | ||||||
|  | 				if (FILTER_SOURCE ? FILTER_SOURCE.trim() : false) { | ||||||
|  | 					this.data.filters.update(FILTER_SOURCE.trim()); | ||||||
| 					}; | 					}; | ||||||
| 				}); | 			}) | ||||||
| 		} | 			: false; | ||||||
| 		if (document.querySelector(`[data-action="filters,update,one"]`)) { | 		 | ||||||
| 			document | 		(document.querySelector(`[data-action="filters,update,one"]`)) | ||||||
| 				.querySelector(`[data-action="filters,update,one"]`) | 			? document.querySelector(`[data-action="filters,update,one"]`).addEventListener(`click`, async () => { | ||||||
| 				.addEventListener(`click`, async () => { | 					this.data.filters = (this.data.filters) ? this.data.filters : new filters(); | ||||||
| 					// Import the filters module.
 |  | ||||||
| 					const texts = ( |  | ||||||
| 						await import(chrome.runtime.getURL(`/scripts/mapping/read.js`)) |  | ||||||
| 					).default; |  | ||||||
| 					let filters = new ( |  | ||||||
| 						await import(chrome.runtime.getURL(`scripts/filters.js`)) |  | ||||||
| 					).default(); |  | ||||||
| 	 | 	 | ||||||
| 					// Open text input window for adding a filter.
 | 					// Open text input window for adding a filter.
 | ||||||
| 					let filter_source = (document.querySelector(`[data-result-linked="filters"] [data-result-content="*"]`)) ? document.querySelector(`[data-result-linked="filters"] [data-result-content="*"]`).innerText : prompt(texts.localized(`settings_filters_add_prompt`)); | 					let filter_source = (document.querySelector(`[data-result-linked="filters"] [data-result-content="*"]`)) ? document.querySelector(`[data-result-linked="filters"] [data-result-content="*"]`).innerText : prompt(texts.localized(`settings_filters_add_prompt`)); | ||||||
| 					if (filter_source ? filter_source.trim() : false) { | 					if (filter_source ? filter_source.trim() : false) { | ||||||
| 						filters.update(filter_source.trim()); | 						this.data.filters.update(filter_source.trim()); | ||||||
| 					}; | 					}; | ||||||
| 				}); | 				}) | ||||||
| 		} | 			: false; | ||||||
| 		 | 		 | ||||||
| 		if (document.querySelector(`[data-action="filters,delete,one"]`)) { | 		if (document.querySelector(`[data-action="filters,delete,one"]`)) { | ||||||
| 			document | 			document.querySelector(`[data-action="filters,delete,one"]`).addEventListener(`click`, async () => { | ||||||
| 				.querySelector(`[data-action="filters,delete,one"]`) | 				this.data.filters = (this.data.filters) ? this.data.filters : new filters(); | ||||||
| 				.addEventListener(`click`, async () => { |  | ||||||
| 					// Import the filters module.
 |  | ||||||
| 					let filters = new ( |  | ||||||
| 						await import(chrome.runtime.getURL(`scripts/filters.js`)) |  | ||||||
| 					).default(); |  | ||||||
| 	 | 	 | ||||||
| 					// Open text input window for adding a filter.
 | 					// Open text input window for adding a filter.
 | ||||||
| 					let filter_source = (document.querySelector(`[data-result-linked="filters"] [data-result-content="*"]`)) ? document.querySelector(`[data-result-linked="filters"] [data-result-content="*"]`).innerText : prompt(texts.localized(`settings_filters_remove_prompt`)); | 					let filter_source = (document.querySelector(`[data-result-linked="filters"] [data-result-content="*"]`)) ? document.querySelector(`[data-result-linked="filters"] [data-result-content="*"]`).innerText : prompt(texts.localized(`settings_filters_remove_prompt`)); | ||||||
| 					if (filter_source ? filter_source.trim() : false) { | 					if (filter_source ? filter_source.trim() : false) { | ||||||
| 						filters.remove(filter_source.trim()); | 						this.data.filters.remove(filter_source.trim()); | ||||||
| 					} | 					} | ||||||
| 				}); | 				}); | ||||||
| 		} | 		} | ||||||
|  | @ -101,8 +99,8 @@ class Page_Settings extends Page { | ||||||
| 			? document.querySelector(`[data-action="storage,clear"]`).addEventListener(`click`, async () => { | 			? document.querySelector(`[data-action="storage,clear"]`).addEventListener(`click`, async () => { | ||||||
| 					await global.forget(`sites`); | 					await global.forget(`sites`); | ||||||
| 					console.log(await global.read(null, 1), await global.read(null, -1)); | 					console.log(await global.read(null, 1), await global.read(null, -1)); | ||||||
| 				}); | 				}) | ||||||
| 		} | 			: false;		 | ||||||
| 
 | 
 | ||||||
| 		(document.querySelectorAll(`[data-action]`)).forEach((ELEMENT) => { | 		(document.querySelectorAll(`[data-action]`)).forEach((ELEMENT) => { | ||||||
| 			ELEMENT.removeAttribute(`data-action`); | 			ELEMENT.removeAttribute(`data-action`); | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue