use updated search interface data to perform actions
This commit is contained in:
		
							parent
							
								
									e25dad36f9
								
							
						
					
					
						commit
						d3520d1c54
					
				
					 1 changed files with 74 additions and 69 deletions
				
			
		|  | @ -8,14 +8,15 @@ 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 filters from "/scripts/filters.js"; | ||||||
| import logging from "/scripts/logging.js"; | import logging from "/scripts/logging.js"; | ||||||
|  | import {URLs} from "/scripts/utils/URLs.js"; | ||||||
| 
 | 
 | ||||||
| class Page_Settings extends Page { | class Page_Settings extends Page { | ||||||
| 	data = {}; | 	data = {}; | ||||||
| 
 | 
 | ||||||
| 	constructor() { | 	constructor() { | ||||||
| 		super(); | 		super(); | ||||||
| 		(this.events) ? this.events() : false; | 		this.events(); | ||||||
| 	} | 	}; | ||||||
| 
 | 
 | ||||||
| 	/* | 	/* | ||||||
| 	Define the mapping of each button. | 	Define the mapping of each button. | ||||||
|  | @ -23,77 +24,81 @@ class Page_Settings extends Page { | ||||||
| 	@param {object} window the window | 	@param {object} window the window | ||||||
| 	*/ | 	*/ | ||||||
| 	events() { | 	events() { | ||||||
| 		(document.querySelector(`[data-action="filters,update"]`)) | 		if ((Object.keys(this.window.elements[`interactive`][`action`])).length) { | ||||||
| 			? document.querySelector(`[data-action="filters,update"]`).addEventListener(`click`, async () => { | 			// Instantiate the filters module, since it's needed for some of the actions below. 
 | ||||||
| 					// Import the filters module.
 |  | ||||||
| 			this.data.filters = (this.data.filters) ? this.data.filters : new filters(); | 			this.data.filters = (this.data.filters) ? this.data.filters : new filters(); | ||||||
| 
 | 
 | ||||||
| 					// Update all of the filters. 
 |  | ||||||
| 					this.data.filters.update(`*`); |  | ||||||
| 				}) |  | ||||||
| 			: false; |  | ||||||
| 			 | 			 | ||||||
| 		(document.querySelector(`[data-action="filters,add,one"]`)) | 			// Set the actions. 
 | ||||||
| 			? document.querySelector(`[data-action="filters,add,one"]`).addEventListener(`click`, async () => { | 			let ACTIONS = {}; | ||||||
| 				// Import the filters module.
 | 			ACTIONS[`filters,update`] = async () => {this.data.filters.update(`*`);}; | ||||||
| 				this.data.filters = (this.data.filters) ? this.data.filters : new filters(); | 			ACTIONS[`filters,add,one`] = () => { | ||||||
| 				// Request for the filter URL. 
 | 				let SOURCE = ``; | ||||||
| 				let FILTER_SOURCE = prompt(texts.localized(`settings_filters_add_prompt`)); | 
 | ||||||
|  | 				while (true) { | ||||||
|  | 					SOURCE = prompt(texts.localized(`settings_filters_add_prompt`), SOURCE); | ||||||
| 
 | 
 | ||||||
| 					// Update the filter if the source is not empty.
 | 					// Update the filter if the source is not empty.
 | ||||||
| 				if (FILTER_SOURCE ? FILTER_SOURCE.trim() : false) { | 					if (SOURCE ? SOURCE.trim() : false) { | ||||||
| 					FILTER_SOURCE = FILTER_SOURCE.trim().split(`, `); | 						SOURCE = SOURCE.trim().split(`, `); | ||||||
| 					this.data.filters.update(FILTER_SOURCE); |  | ||||||
| 				}; |  | ||||||
| 			}) |  | ||||||
| 			: false; |  | ||||||
| 
 | 
 | ||||||
| 		(document.querySelector(`[data-action="filters,update,one"]`)) | 						// Verify user inputs are valid. 
 | ||||||
| 			? document.querySelector(`[data-action="filters,update,one"]`).addEventListener(`click`, async () => { | 						let VALID = true; | ||||||
| 					this.data.filters = (this.data.filters) ? this.data.filters : new filters(); |  | ||||||
| 
 | 
 | ||||||
| 					// Open text input window for adding a filter.
 | 						// Check if the URL is valid.
 | ||||||
| 					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`)); | 						SOURCE.forEach((LOCATION) => { | ||||||
| 					if (filter_source ? filter_source.trim() : false) { | 							VALID = (URLs.test(LOCATION)); | ||||||
| 						this.data.filters.update(filter_source.trim()); |  | ||||||
| 					}; |  | ||||||
| 				}) |  | ||||||
| 			: false; |  | ||||||
| 		 |  | ||||||
| 		if (document.querySelector(`[data-action="filters,delete,one"]`)) { |  | ||||||
| 			document.querySelector(`[data-action="filters,delete,one"]`).addEventListener(`click`, async () => { |  | ||||||
| 				this.data.filters = (this.data.filters) ? this.data.filters : new filters(); |  | ||||||
| 	 |  | ||||||
| 					// 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`)); |  | ||||||
| 					if (filter_source ? filter_source.trim() : false) { |  | ||||||
| 						this.data.filters.remove(filter_source.trim()); |  | ||||||
| 					} |  | ||||||
| 						}); | 						}); | ||||||
|  | 
 | ||||||
|  | 						// Update the filter if the source is valid.
 | ||||||
|  | 						if (VALID) { | ||||||
|  | 							return(this.data.filters.update(SOURCE)); | ||||||
|  | 						} else { | ||||||
|  | 							if (!confirm(texts.localized(`error_msg_notURL_syntax`))) { | ||||||
|  | 								return (false); | ||||||
|  | 							}; | ||||||
|  | 						} | ||||||
|  | 					} else { | ||||||
|  | 						return (false); | ||||||
|  | 					}; | ||||||
|  | 				} | ||||||
|  | 			}; | ||||||
|  | 			ACTIONS[`filters,update,one`] = () => { | ||||||
|  | 				// Update the selected filter. 
 | ||||||
|  | 				return((this.window.search.filters.selected) ? this.data.filters.update(this.window.search.filters.selected) : false) | ||||||
|  | 			}; | ||||||
|  | 			ACTIONS[`filters,delete,one`] = () => { | ||||||
|  | 				// Remove the selected filter. 
 | ||||||
|  | 				return((this.window.search.filters.selected) ? this.data.filters.remove(this.window.search.filters.selected) : false) | ||||||
|  | 			} | ||||||
|  | 			ACTIONS[`storage,clear`] = () => { | ||||||
|  | 				return(global.forget(`sites`)); | ||||||
| 			} | 			} | ||||||
| 			 | 			 | ||||||
|  | 			// Add the event listeners. 
 | ||||||
|  | 			(Object.keys(ACTIONS)).forEach((NAME) => { | ||||||
|  | 				(this.window.elements[`interactive`][`action`][NAME] ? this.window.elements[`interactive`][`action`][NAME].length : false) | ||||||
|  | 					? this.window.elements[`interactive`][`action`][NAME].forEach((ELEMENT) => { | ||||||
|  | 						ELEMENT.addEventListener(`click`, ACTIONS[NAME]); | ||||||
|  | 					}) | ||||||
|  | 					: false; | ||||||
|  | 			}) | ||||||
|  | 		}; | ||||||
|  | 
 | ||||||
|  | 		if (this.window.elements[`linked`] ? (this.window.elements[`linked`][`show`] ? Object.keys(this.window.elements[`linked`][`show`]).length : false) : false) { | ||||||
|  | 			(this.window.elements[`linked`][`show`][`settings,general,showApplicable`] ? this.window.elements[`linked`][`show`][`settings,general,showApplicable`].length : false) | ||||||
|  | 				? (this.window.elements[`linked`][`show`][`settings,general,showApplicable`]).forEach((ELEMENT) => { | ||||||
|  | 					ELEMENT.addEventListener(`change`, () => { | ||||||
| 						// The extension icon cache doesn't clear by itself. 
 | 						// The extension icon cache doesn't clear by itself. 
 | ||||||
| 		(document.querySelector(`[data-store="settings,general,showApplicable"]`)) |  | ||||||
| 			? document.querySelectorAll(`[data-store="settings,general,showApplicable"]`).forEach((ELEMENT) => { |  | ||||||
| 						ELEMENT.addEventListener(`change`, () => { | 						ELEMENT.addEventListener(`change`, () => { | ||||||
| 							!(ELEMENT.checked) | 							!(ELEMENT.checked) | ||||||
| 								? new logging(texts.localized(`settings_restartToApply`), texts.localized(`settings_restartToApply_iconChange`), true) | 								? new logging(texts.localized(`settings_restartToApply`), texts.localized(`settings_restartToApply_iconChange`), true) | ||||||
| 								: false; | 								: false; | ||||||
| 						}) | 						}) | ||||||
|  | 					}); | ||||||
| 				}) | 				}) | ||||||
| 				: false; | 				: false; | ||||||
| 	 | 		} | ||||||
| 		(document.querySelector(`[data-action="storage,clear"]`))  |  | ||||||
| 			? document.querySelector(`[data-action="storage,clear"]`).addEventListener(`click`, async () => { |  | ||||||
| 					await global.forget(`sites`); |  | ||||||
| 				}) |  | ||||||
| 			: false;		 |  | ||||||
| 
 |  | ||||||
| 		(document.querySelectorAll(`[data-action]`))  |  | ||||||
| 			? (document.querySelectorAll(`[data-action]`)).forEach((ELEMENT) => { |  | ||||||
| 				ELEMENT.removeAttribute(`data-action`); |  | ||||||
| 			}) |  | ||||||
| 			: false; |  | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue