don’t read for storage data automatically
saves on resources for files that don’t necessarily need it
This commit is contained in:
		
							parent
							
								
									51574e0ba8
								
							
						
					
					
						commit
						333310fcc8
					
				
					 1 changed files with 247 additions and 243 deletions
				
			
		|  | @ -214,7 +214,91 @@ export default class windowman { | ||||||
| 				}); | 				}); | ||||||
| 			} | 			} | ||||||
| 
 | 
 | ||||||
| 			async function storage() { | 			elements(); | ||||||
|  | 			text(); | ||||||
|  | 			icons(); | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
|  | 		// Adds events to the window.
 | ||||||
|  | 		function events() { | ||||||
|  | 			/* Map buttons to their corresponding action buttons. */ | ||||||
|  | 			function actions() { | ||||||
|  | 				function links() { | ||||||
|  | 					let buttons = document.querySelectorAll("button[href]"); | ||||||
|  | 
 | ||||||
|  | 					if (buttons) { | ||||||
|  | 						buttons.forEach((button) => { | ||||||
|  | 							let event = function () { | ||||||
|  | 								// Get the data from the button.
 | ||||||
|  | 								let target = {}; | ||||||
|  | 								target[`source`] = this.getAttribute(`href`); | ||||||
|  | 
 | ||||||
|  | 								// Get the correct path.
 | ||||||
|  | 								target[`path`] = ( | ||||||
|  | 									!target[`source`].includes(`://`) | ||||||
|  | 										? window.location.pathname | ||||||
|  | 												.split(`/`) | ||||||
|  | 												.slice(0, -1) | ||||||
|  | 												.join(`/`) | ||||||
|  | 												.concat(`/`) | ||||||
|  | 										: `` | ||||||
|  | 								).concat(target[`source`]); | ||||||
|  | 
 | ||||||
|  | 								windowman.new( | ||||||
|  | 									target[`path`], | ||||||
|  | 									this.getAttribute(`tab-height`) | ||||||
|  | 										? this.getAttribute(`tab-height`) | ||||||
|  | 										: null, | ||||||
|  | 									this.getAttribute(`tab-width`) | ||||||
|  | 										? this.getAttribute(`tab-width`) | ||||||
|  | 										: null, | ||||||
|  | 								); | ||||||
|  | 							}; | ||||||
|  | 							button.addEventListener("click", event); | ||||||
|  | 						}); | ||||||
|  | 					} | ||||||
|  | 				} | ||||||
|  | 
 | ||||||
|  | 				// Responsiveness to different screen sizes.
 | ||||||
|  | 				function resize() { | ||||||
|  | 					function sidebar() { | ||||||
|  | 						 | ||||||
|  | 						if (document.querySelector(`.sidenav`)) { | ||||||
|  | 							(document.querySelectorAll(`.sidenav`)).forEach(function (sidebar_element) { | ||||||
|  | 								if (sidebar_element.getAttribute(`name`)) { | ||||||
|  | 									document.querySelector(`[works-sidebar="${sidebar_element.getAttribute(`name`)}"]`) | ||||||
|  | 									.addEventListener(`click`, function () { | ||||||
|  | 										M.Sidenav.getInstance(sidebar_element).open(); | ||||||
|  | 									}); | ||||||
|  | 								} else if (document.querySelector(`[data-action="ui,open,navbar"]`)) { | ||||||
|  | 									document.querySelector(`[data-action="ui,open,navbar"]`).forEach(function (button_element) { | ||||||
|  | 										button_element.addEventListener(`click`, function() { | ||||||
|  | 											M.Sidenav.getInstance(sidebar).open(); | ||||||
|  | 										}); | ||||||
|  | 									}); | ||||||
|  | 								} | ||||||
|  | 							}); | ||||||
|  | 						} | ||||||
|  | 					} | ||||||
|  | 
 | ||||||
|  | 					sidebar(); | ||||||
|  | 				} | ||||||
|  | 
 | ||||||
|  | 				resize(); | ||||||
|  | 				links(); | ||||||
|  | 			} | ||||||
|  | 			 | ||||||
|  | 			actions(); | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
|  | 		headers(); | ||||||
|  | 		appearance(); | ||||||
|  | 		events(); | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	/* Run this function if you would like to synchronize with data. */ | ||||||
|  | 	sync() { | ||||||
|  | 		async function fill() { | ||||||
| 			// Import the module.
 | 			// Import the module.
 | ||||||
| 			const secretariat = await import( | 			const secretariat = await import( | ||||||
| 				chrome.runtime.getURL("scripts/secretariat.js") | 				chrome.runtime.getURL("scripts/secretariat.js") | ||||||
|  | @ -254,16 +338,8 @@ export default class windowman { | ||||||
| 			}); | 			}); | ||||||
| 		} | 		} | ||||||
| 		 | 		 | ||||||
| 			elements(); |  | ||||||
| 			text(); |  | ||||||
| 			icons(); |  | ||||||
| 			storage(); |  | ||||||
| 		} |  | ||||||
| 
 |  | ||||||
| 		// Adds events to the window.
 |  | ||||||
| 		function events() { |  | ||||||
| 		/* Add events related to storage. */ | 		/* Add events related to storage. */ | ||||||
| 			async function storage() { | 		async function update() { | ||||||
| 			// Import the module.
 | 			// Import the module.
 | ||||||
| 			const secretariat = await import( | 			const secretariat = await import( | ||||||
| 				chrome.runtime.getURL("scripts/secretariat.js") | 				chrome.runtime.getURL("scripts/secretariat.js") | ||||||
|  | @ -306,44 +382,46 @@ export default class windowman { | ||||||
| 			}); | 			}); | ||||||
| 		} | 		} | ||||||
| 		 | 		 | ||||||
| 			/* Map buttons to their corresponding action buttons. */ | 		/* | ||||||
| 			function actions() { | 			Update the interface based on the storage data changes. | ||||||
| 				function links() { | 		*/ | ||||||
| 					let buttons = document.querySelectorAll("button[href]"); | 		async function updates() { | ||||||
| 
 | 			// Import the module.
 | ||||||
| 					if (buttons) { | 			const secretariat = await import( | ||||||
| 						buttons.forEach((button) => { | 				chrome.runtime.getURL("scripts/secretariat.js") | ||||||
| 							let event = function () { |  | ||||||
| 								// Get the data from the button.
 |  | ||||||
| 								let target = {}; |  | ||||||
| 								target[`source`] = this.getAttribute(`href`); |  | ||||||
| 
 |  | ||||||
| 								// Get the correct path.
 |  | ||||||
| 								target[`path`] = ( |  | ||||||
| 									!target[`source`].includes(`://`) |  | ||||||
| 										? window.location.pathname |  | ||||||
| 												.split(`/`) |  | ||||||
| 												.slice(0, -1) |  | ||||||
| 												.join(`/`) |  | ||||||
| 												.concat(`/`) |  | ||||||
| 										: `` |  | ||||||
| 								).concat(target[`source`]); |  | ||||||
| 
 |  | ||||||
| 								windowman.new( |  | ||||||
| 									target[`path`], |  | ||||||
| 									this.getAttribute(`tab-height`) |  | ||||||
| 										? this.getAttribute(`tab-height`) |  | ||||||
| 										: null, |  | ||||||
| 									this.getAttribute(`tab-width`) |  | ||||||
| 										? this.getAttribute(`tab-width`) |  | ||||||
| 										: null, |  | ||||||
| 			); | 			); | ||||||
| 							}; | 
 | ||||||
| 							button.addEventListener("click", event); | 			// Get the storage data.
 | ||||||
|  | 			let storage_data = await secretariat.read(); | ||||||
|  | 
 | ||||||
|  | 			async function enable() { | ||||||
|  | 				let input_elements = document.querySelectorAll("[data-enable]"); | ||||||
|  | 
 | ||||||
|  | 				if (input_elements) { | ||||||
|  | 					input_elements.forEach((input_element) => { | ||||||
|  | 						if (input_element.getAttribute("data-enable")) { | ||||||
|  | 							(async () => { | ||||||
|  | 								input_element.disabled = !((await secretariat.read(input_element.getAttribute("data-enable"))) != null | ||||||
|  | 									? (typeof (await secretariat.read(input_element.getAttribute("data-enable")))).includes(`obj`) | ||||||
|  | 										? (Object.keys(await secretariat.read(input_element.getAttribute("data-enable")))).length > 0 | ||||||
|  | 										: !!(await secretariat.read( | ||||||
|  | 												input_element.getAttribute("data-enable"), | ||||||
|  | 											)) | ||||||
|  | 									: false); | ||||||
|  | 							})(); | ||||||
|  | 						} | ||||||
| 					}); | 					}); | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
| 
 | 
 | ||||||
|  | 			// Update the input elements.
 | ||||||
|  | 			secretariat.observe((what) => { | ||||||
|  | 				enable(); | ||||||
|  | 			}); | ||||||
|  | 
 | ||||||
|  | 			enable(); | ||||||
|  | 		}; | ||||||
|  | 		 | ||||||
| 		/* Enable the searching interface. */ | 		/* Enable the searching interface. */ | ||||||
| 		function search() { | 		function search() { | ||||||
| 			if (document.querySelectorAll(`[data-result]`)) { | 			if (document.querySelectorAll(`[data-result]`)) { | ||||||
|  | @ -458,84 +536,10 @@ export default class windowman { | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 				// Responsiveness to different screen sizes.
 | 		fill(); | ||||||
| 				function resize() { | 		update(); | ||||||
| 					function sidebar() { |  | ||||||
| 						 |  | ||||||
| 						if (document.querySelector(`.sidenav`)) { |  | ||||||
| 							(document.querySelectorAll(`.sidenav`)).forEach(function (sidebar_element) { |  | ||||||
| 								if (sidebar_element.getAttribute(`name`)) { |  | ||||||
| 									document.querySelector(`[works-sidebar="${sidebar_element.getAttribute(`name`)}"]`) |  | ||||||
| 									.addEventListener(`click`, function () { |  | ||||||
| 										M.Sidenav.getInstance(sidebar_element).open(); |  | ||||||
| 									}); |  | ||||||
| 								} else if (document.querySelector(`[data-action="ui,open,navbar"]`)) { |  | ||||||
| 									document.querySelector(`[data-action="ui,open,navbar"]`).forEach(function (button_element) { |  | ||||||
| 										button_element.addEventListener(`click`, function() { |  | ||||||
| 											M.Sidenav.getInstance(sidebar).open(); |  | ||||||
| 										}); |  | ||||||
| 									}); |  | ||||||
| 								} |  | ||||||
| 							}); |  | ||||||
| 						} |  | ||||||
| 					} |  | ||||||
| 
 |  | ||||||
| 					sidebar(); |  | ||||||
| 				} |  | ||||||
| 
 |  | ||||||
| 				resize(); |  | ||||||
| 				search(); |  | ||||||
| 				links(); |  | ||||||
| 			} |  | ||||||
| 
 |  | ||||||
| 			/* |  | ||||||
| 		Update the interface based on the storage data changes. |  | ||||||
| 		*/ |  | ||||||
| 			async function updates() { |  | ||||||
| 				// Import the module.
 |  | ||||||
| 				const secretariat = await import( |  | ||||||
| 					chrome.runtime.getURL("scripts/secretariat.js") |  | ||||||
| 				); |  | ||||||
| 
 |  | ||||||
| 				// Get the storage data.
 |  | ||||||
| 				let storage_data = await secretariat.read(); |  | ||||||
| 
 |  | ||||||
| 				async function enable() { |  | ||||||
| 					let input_elements = document.querySelectorAll("[data-enable]"); |  | ||||||
| 
 |  | ||||||
| 					if (input_elements) { |  | ||||||
| 						input_elements.forEach((input_element) => { |  | ||||||
| 							if (input_element.getAttribute("data-enable")) { |  | ||||||
| 								(async () => { |  | ||||||
| 									input_element.disabled = !((await secretariat.read(input_element.getAttribute("data-enable"))) != null |  | ||||||
| 										? (typeof (await secretariat.read(input_element.getAttribute("data-enable")))).includes(`obj`) |  | ||||||
| 											? (Object.keys(await secretariat.read(input_element.getAttribute("data-enable")))).length > 0 |  | ||||||
| 											: !!(await secretariat.read( |  | ||||||
| 													input_element.getAttribute("data-enable"), |  | ||||||
| 												)) |  | ||||||
| 										: false); |  | ||||||
| 								})(); |  | ||||||
| 							} |  | ||||||
| 						}); |  | ||||||
| 					} |  | ||||||
| 				} |  | ||||||
| 
 |  | ||||||
| 				// Update the input elements.
 |  | ||||||
| 				secretariat.observe((what) => { |  | ||||||
| 					enable(); |  | ||||||
| 				}); |  | ||||||
| 
 |  | ||||||
| 				enable(); |  | ||||||
| 			} |  | ||||||
| 
 |  | ||||||
| 			storage(); |  | ||||||
| 			actions(); |  | ||||||
| 		updates(); | 		updates(); | ||||||
| 		} | 		search(); | ||||||
| 
 |  | ||||||
| 		headers(); |  | ||||||
| 		appearance(); |  | ||||||
| 		events(); |  | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue