Add filter deletion functionality to settings page
This commit is contained in:
		
							parent
							
								
									6a5efb219d
								
							
						
					
					
						commit
						a4296b15e1
					
				
					 2 changed files with 51 additions and 26 deletions
				
			
		|  | @ -58,6 +58,28 @@ function events(window) { | ||||||
| 			}); | 			}); | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
|  | 	if (document.querySelector(`[data-action="filters,delete,one"]`)) { | ||||||
|  | 		document | ||||||
|  | 			.querySelector(`[data-action="filters,delete,one"]`) | ||||||
|  | 			.addEventListener(`click`, async () => { | ||||||
|  | 				(async () => { | ||||||
|  | 					// Import the filters module.
 | ||||||
|  | 					let texts = ( | ||||||
|  | 						await import(chrome.runtime.getURL(`gui/scripts/read.js`)) | ||||||
|  | 					).default; | ||||||
|  | 					let filters = new ( | ||||||
|  | 						await import(chrome.runtime.getURL(`scripts/filters.js`)) | ||||||
|  | 					).default(); | ||||||
|  | 
 | ||||||
|  | 					// Open text input window for adding a filter.
 | ||||||
|  | 					let filter_source = prompt(texts.localized(`settings_filters_add_prompt`)); | ||||||
|  | 					if (filter_source ? filter_source.trim() : false) { | ||||||
|  | 						filters.remove(filter_source.trim()); | ||||||
|  | 					} | ||||||
|  | 				})(); | ||||||
|  | 			}); | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
| 	if (document.querySelector(`[data-action="storage,clear"]`)) { | 	if (document.querySelector(`[data-action="storage,clear"]`)) { | ||||||
| 		document | 		document | ||||||
| 			.querySelector(`[data-action="storage,clear"]`) | 			.querySelector(`[data-action="storage,clear"]`) | ||||||
|  |  | ||||||
|  | @ -292,14 +292,15 @@ export default class windowman { | ||||||
| 		async function fill() { | 		async function fill() { | ||||||
| 			let input_elements = document.querySelectorAll("[data-store]"); | 			let input_elements = document.querySelectorAll("[data-store]"); | ||||||
| 
 | 
 | ||||||
| 			input_elements.forEach((input_element) => { | 			input_elements.forEach(function(input_element) { | ||||||
| 				// Gather data about the element.
 | 				// Gather data about the element.
 | ||||||
| 				// Get the corresponding storage data.
 | 				// Get the corresponding storage data.
 | ||||||
| 				let data = {}; | 				let data = {}; | ||||||
| 				data[`source`] = input_element.getAttribute(`data-store`); | 				data[`source`] = input_element.getAttribute(`data-store`); | ||||||
| 				data[`value`] = secretariat.read(data[`source`], -1); | 				data[`origin`] = (input_element.hasAttribute(`data-store-location`)) ? parseInt(input_element.getAttribute(`data-store-location`)) : -1 | ||||||
|  | 				data[`value`] = secretariat.read(data[`source`], data[`origin`]); | ||||||
| 
 | 
 | ||||||
| 				data[`value`].then((value) => { | 				data[`value`].then(async function(value) { | ||||||
| 					switch (input_element.getAttribute(`type`).toLowerCase()) { | 					switch (input_element.getAttribute(`type`).toLowerCase()) { | ||||||
| 						case `checkbox`: | 						case `checkbox`: | ||||||
| 							input_element.checked = value; | 							input_element.checked = value; | ||||||
|  | @ -335,14 +336,14 @@ export default class windowman { | ||||||
| 				let element = {}; | 				let element = {}; | ||||||
| 				element[`type`] = input_element.getAttribute(`type`).toLowerCase(); | 				element[`type`] = input_element.getAttribute(`type`).toLowerCase(); | ||||||
| 				element[`event`] = function () {}; | 				element[`event`] = function () {}; | ||||||
| 
 |  | ||||||
| 				switch (element[`type`]) { | 				switch (element[`type`]) { | ||||||
| 					case `checkbox`: | 					case `checkbox`: | ||||||
| 						element[`event`] = function () { | 						element[`event`] = function () { | ||||||
| 							let UI_item = {}; | 							let UI_item = {}; | ||||||
| 							UI_item[`source`] = this.getAttribute(`data-store`); | 							UI_item[`source`] = this.getAttribute(`data-store`); | ||||||
| 							UI_item[`value`] = this.checked; | 							UI_item[`value`] = this.checked; | ||||||
| 							secretariat.write(UI_item[`source`], UI_item[`value`], 1); | 							UI_item[`store`] = (this.hasAttribute(`data-store-location`)) ? parseInt(this.getAttribute(`data-store-location`)) : -1; | ||||||
|  | 							secretariat.write(UI_item[`source`], UI_item[`value`], UI_item[`store`]); | ||||||
| 						}; | 						}; | ||||||
| 						break; | 						break; | ||||||
| 					default: | 					default: | ||||||
|  | @ -354,12 +355,13 @@ export default class windowman { | ||||||
| 									? parseFloat(this.value) | 									? parseFloat(this.value) | ||||||
| 									: parseInt(this.value) | 									: parseInt(this.value) | ||||||
| 								: this.value; | 								: this.value; | ||||||
| 							secretariat.write(UI_item[`source`], UI_item[`value`], 1); | 							UI_item[`store`] = (this.hasAttribute(`data-store-location`)) ? parseInt(this.getAttribute(`data-store-location`)) : -1; | ||||||
|  | 							secretariat.write(UI_item[`source`], UI_item[`value`], UI_item[`store`]); | ||||||
| 						}; | 						}; | ||||||
| 						break; | 						break; | ||||||
| 				} | 				} | ||||||
| 
 | 
 | ||||||
| 				input_element.addEventListener("change", element[`event`]); | 				input_element.addEventListener(`change`, element[`event`]); | ||||||
| 			}); | 			}); | ||||||
| 		} | 		} | ||||||
| 		 | 		 | ||||||
|  | @ -422,10 +424,9 @@ export default class windowman { | ||||||
| 							ELEMENT_TARGET.innerHTML = ``; | 							ELEMENT_TARGET.innerHTML = ``; | ||||||
| 
 | 
 | ||||||
| 							function setSelected(element) { | 							function setSelected(element) { | ||||||
| 								SEARCH[TARGET_NAME][`selected`] = (element) ? (Object.keys(RESULTS))[(Array.prototype.slice.call(element.parentElement.children)).indexOf(element)] : null; | 								SEARCH[TARGET_NAME][`selected`] = (element) ? (Object.keys(RESULTS))[(Array.prototype.slice.call(element.parentElement.parentElement.querySelectorAll(`a`))).indexOf(element)] : null; | ||||||
| 								 | 								 | ||||||
| 								// Array.prototype.slice.call(element.parentElement.children)
 | 								// Array.prototype.slice.call(element.parentElement.children)
 | ||||||
| 								// console.log(new Array(element.parentElement.querySelectorAll(`*`)), (new Array(element.parentElement.querySelectorAll(`*`))).indexOf(element), (Object.keys(RESULTS))[(new Array(element.parentElement.querySelectorAll(`*`))).indexOf(element)]);
 |  | ||||||
| 								if (element) {(element.parentElement).parentElement.querySelectorAll(`li`).forEach((element_others) => { | 								if (element) {(element.parentElement).parentElement.querySelectorAll(`li`).forEach((element_others) => { | ||||||
| 									element_others.classList.remove(`active`); | 									element_others.classList.remove(`active`); | ||||||
| 								}); element.parentElement.classList.add(`active`)};							 | 								}); element.parentElement.classList.add(`active`)};							 | ||||||
|  | @ -466,7 +467,6 @@ export default class windowman { | ||||||
| 										pick(result, RESULTS[result], TARGET_NAME); | 										pick(result, RESULTS[result], TARGET_NAME); | ||||||
| 
 | 
 | ||||||
| 										// Set the access key.
 | 										// Set the access key.
 | ||||||
| 										this.parentElement.querySelectorAll(`*`) |  | ||||||
| 										accessKey(this); | 										accessKey(this); | ||||||
| 									}); | 									}); | ||||||
| 									 | 									 | ||||||
|  | @ -510,28 +510,28 @@ export default class windowman { | ||||||
|                                                     let DATA = {}; |                                                     let DATA = {}; | ||||||
|                                                      |                                                      | ||||||
|                                                     DATA[`target`] = (Object.keys(ITEM).includes(ELEMENT.getAttribute(`data-result-store`))) ? [...AREA, ...[NAME], ...(ELEMENT.getAttribute(`data-result-store`).split(`,`))] : [...(ELEMENT.getAttribute(`data-result-store`).split(`,`)), ...[NAME]]; |                                                     DATA[`target`] = (Object.keys(ITEM).includes(ELEMENT.getAttribute(`data-result-store`))) ? [...AREA, ...[NAME], ...(ELEMENT.getAttribute(`data-result-store`).split(`,`))] : [...(ELEMENT.getAttribute(`data-result-store`).split(`,`)), ...[NAME]]; | ||||||
|                                                     DATA[`value`] = (Object.keys(ITEM).includes(ELEMENT.getAttribute(`data-result-store`))) ? ITEM[ELEMENT.getAttribute(`data-result-store`)] : await secretariat.read(DATA[`target`]); |  | ||||||
| 													 | 													 | ||||||
| 													console.log(DATA); | 													let TARGET = (Object.keys(ITEM).includes(ELEMENT.getAttribute(`data-result-store`))) ? [...AREA, ...[NAME], ...(ELEMENT.getAttribute(`data-result-store`).split(`,`))] : [...(ELEMENT.getAttribute(`data-result-store`).split(`,`)), ...[NAME]]; | ||||||
|  |                                                     DATA[`value`] = (Object.keys(ITEM).includes(ELEMENT.getAttribute(`data-result-store`))) ? ITEM[ELEMENT.getAttribute(`data-result-store`)] : await secretariat.read(TARGET); | ||||||
| 
 | 
 | ||||||
|                                                     switch (ELEMENT[`type`]) { |                                                     switch (ELEMENT[`type`]) { | ||||||
| 														case `checkbox`: | 														case `checkbox`: | ||||||
| 															ELEMENT.checked = DATA[`value`]; | 															ELEMENT.checked = DATA[`value`]; | ||||||
|  | 															console.log(await secretariat.read(null, 1)); | ||||||
|                                                              |                                                              | ||||||
|                                                             ELEMENT[`function`] = async function() { |                                                             ELEMENT[`function`] = async function() { | ||||||
|                                                                 await secretariat.write(DATA[`target`], ELEMENT.checked, 1); | 																DATA[`value`] = ELEMENT.checked; | ||||||
|  |                                                                 await secretariat.write(DATA[`target`], DATA[`value`], (ELEMENT.hasAttribute(`data-store-location`)) ? parseInt(ELEMENT.getAttribute(`data-store-location`)) : -1); | ||||||
|                                                             } |                                                             } | ||||||
|                                                              |  | ||||||
|                                                             break; |                                                             break; | ||||||
|                                                         default: |                                                         default: | ||||||
|                                                             if ((typeof (ITEM[ELEMENT.getAttribute(`data-result-store`)])).includes(`obj`)) { |                                                             if ((typeof (ITEM[ELEMENT.getAttribute(`data-result-store`)])).includes(`obj`)) { | ||||||
|                                                                 ELEMENT.value = JSON.stringify(DATA[`value`]); |                                                                 ELEMENT.value = JSON.stringify(DATA[`value`]); | ||||||
|                                                                  |                                                                  | ||||||
|                                                                 ELEMENT[`function`] = async function() { |                                                                 ELEMENT[`function`] = function() { | ||||||
|                                                                     console.log(`running`); |  | ||||||
| 																	try { | 																	try { | ||||||
|                                                                         DATA[`value`] = JSON.parse(ELEMENT.value); | 																		DATA[`value`] = JSON.parse(ELEMENT.value.trim()); | ||||||
|                                                                         secretariat.write(DATA[`target`], DATA[`value`]); | 																		(async function() {secretariat.write(DATA[`target`], DATA[`value`], (ELEMENT.hasAttribute(`data-store-location`)) ? parseInt(ELEMENT.getAttribute(`data-store-location`)) : -1);}) | ||||||
|                                                                     } catch(err) { |                                                                     } catch(err) { | ||||||
|                                                                         // The JSON isn't valid.
 |                                                                         // The JSON isn't valid.
 | ||||||
|                                                                         alerts.error(err.name, texts.localized(`JSON_parse_error`), err.stack, false); |                                                                         alerts.error(err.name, texts.localized(`JSON_parse_error`), err.stack, false); | ||||||
|  | @ -541,8 +541,8 @@ export default class windowman { | ||||||
|                                                                 ELEMENT.value = DATA[`value`]; |                                                                 ELEMENT.value = DATA[`value`]; | ||||||
| 																 | 																 | ||||||
|                                                                 ELEMENT[`function`] = async function() { |                                                                 ELEMENT[`function`] = async function() { | ||||||
|                                                                     await secretariat.write(DATA[`target`], ELEMENT.value); | 																	DATA[`value`] = ELEMENT.value.trim() | ||||||
|                                                                     console.log(`saving...`); |                                                                     await secretariat.write(DATA[`target`], DATA[`value`], (ELEMENT.hasAttribute(`data-store-location`)) ? parseInt(ELEMENT.getAttribute(`data-store-location`)) : -1); | ||||||
|                                                                 } |                                                                 } | ||||||
|                                                             } |                                                             } | ||||||
|                                                             break; |                                                             break; | ||||||
|  | @ -634,8 +634,11 @@ export default class windowman { | ||||||
| 						{ | 						{ | ||||||
| 							pick(null, null, element.getAttribute(`data-result`)); | 							pick(null, null, element.getAttribute(`data-result`)); | ||||||
| 						} | 						} | ||||||
| 					} |  | ||||||
| 
 | 
 | ||||||
|  | 						secretariat.observe((what) => { | ||||||
|  | 							find(element); | ||||||
|  | 						}); | ||||||
|  | 					} | ||||||
| 				} | 				} | ||||||
| 
 | 
 | ||||||
| 				document.querySelectorAll(`[data-result]`).forEach((element) => { | 				document.querySelectorAll(`[data-result]`).forEach((element) => { | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue