fix sidebar
This commit is contained in:
		
							parent
							
								
									fe41352afd
								
							
						
					
					
						commit
						9d23ad1150
					
				
					 1 changed files with 409 additions and 316 deletions
				
			
		|  | @ -7,369 +7,462 @@ import texts from "./read.js"; | ||||||
| let DEBUG = false; | let DEBUG = false; | ||||||
| 
 | 
 | ||||||
| export default class windowman { | export default class windowman { | ||||||
| 	static new(URL, height, width) { |   static new(URL, height, width) { | ||||||
| 		this.window = chrome.windows.create({ |     this.window = chrome.windows.create({ | ||||||
| 			url: chrome.runtime.getURL(URL), |       url: chrome.runtime.getURL(URL), | ||||||
| 			type: "popup", |       type: "popup", | ||||||
| 			width: width ? parseInt(width) : 600, |       width: width ? parseInt(width) : 600, | ||||||
| 			height: height ? parseInt(height) : 600, |       height: height ? parseInt(height) : 600, | ||||||
| 		}); |     }); | ||||||
| 	} |   } | ||||||
| 
 | 
 | ||||||
| 	// Prepare the window with its metadata.
 |   // Prepare the window with its metadata.
 | ||||||
| 	constructor() { |   constructor() { | ||||||
| 		function headers() { |     function headers() { | ||||||
| 		let LOAD_STATE = true; |       let LOAD_STATE = true; | ||||||
| 			let UI = { |       let UI = { | ||||||
| 				"CSS": [ |         CSS: [ | ||||||
| 					chrome.runtime.getURL( |           chrome.runtime.getURL( | ||||||
| 						"gui/styles/external/fonts/materialdesignicons.min.css", |             "gui/styles/external/fonts/materialdesignicons.min.css", | ||||||
| 					), |           ), | ||||||
| 					chrome.runtime.getURL( |           chrome.runtime.getURL( | ||||||
| 						"gui/styles/external/materialize/css/materialize.css", |             "gui/styles/external/materialize/css/materialize.css", | ||||||
| 					), |           ), | ||||||
| 					chrome.runtime.getURL("gui/styles/ui.css"), |           chrome.runtime.getURL("gui/styles/ui.css"), | ||||||
| 				], |         ], | ||||||
| 			}; |       }; | ||||||
| 
 | 
 | ||||||
|  |       for (let index = 0; index < UI[`CSS`].length; index++) { | ||||||
|  |         const source = UI.CSS[index]; | ||||||
| 
 | 
 | ||||||
| 			for (let index = 0; index < UI[`CSS`].length; index++) { |         (async () => { | ||||||
| 				const source = UI.CSS[index]; |           const net = await import(chrome.runtime.getURL(`/scripts/net.js`)); | ||||||
| 				 |  | ||||||
| 				(async () => { |  | ||||||
| 					const net = await import(chrome.runtime.getURL(`/scripts/net.js`)); |  | ||||||
| 			 |  | ||||||
| 					let resource = false; |  | ||||||
| 					try { |  | ||||||
| 						resource = await net.download(source, `text`, true); |  | ||||||
| 					} catch(err) {}; |  | ||||||
| 	 |  | ||||||
| 					if (resource) { |  | ||||||
| 						let metadata_element = document.createElement(`link`); |  | ||||||
| 						metadata_element.setAttribute(`rel`, `stylesheet`); |  | ||||||
| 						metadata_element.setAttribute(`type`, `text/css`); |  | ||||||
| 						metadata_element.setAttribute(`href`, source); |  | ||||||
| 						document.querySelector(`head`).appendChild(metadata_element); |  | ||||||
| 					} else { |  | ||||||
| 						const alerts = (await import(chrome.runtime.getURL(`/gui/scripts/alerts.js`))).default; |  | ||||||
| 						const reader = (await import(chrome.runtime.getURL(`/gui/scripts/read.js`))).default; |  | ||||||
| 	 |  | ||||||
| 						alerts.error(-1, reader.localized(`error_msg_fileNotFound`), true, [source]); |  | ||||||
| 
 | 
 | ||||||
| 						// Stop loading the page when an error has occured; it's not going to work! 
 |           let resource = false; | ||||||
| 						if (!DEBUG) {window.close()}; |           try { | ||||||
| 					} |             resource = await net.download(source, `text`, true); | ||||||
| 				})(); |           } catch (err) {} | ||||||
| 			} |  | ||||||
| 		} |  | ||||||
| 
 | 
 | ||||||
| 		// Get the window.
 |           if (resource) { | ||||||
| 		this[`metadata`] = chrome.windows.getCurrent(); |             let metadata_element = document.createElement(`link`); | ||||||
|  |             metadata_element.setAttribute(`rel`, `stylesheet`); | ||||||
|  |             metadata_element.setAttribute(`type`, `text/css`); | ||||||
|  |             metadata_element.setAttribute(`href`, source); | ||||||
|  |             document.querySelector(`head`).appendChild(metadata_element); | ||||||
|  |           } else { | ||||||
|  |             const alerts = ( | ||||||
|  |               await import(chrome.runtime.getURL(`/gui/scripts/alerts.js`)) | ||||||
|  |             ).default; | ||||||
|  |             const reader = ( | ||||||
|  |               await import(chrome.runtime.getURL(`/gui/scripts/read.js`)) | ||||||
|  |             ).default; | ||||||
| 
 | 
 | ||||||
| 		/* |             alerts.error(-1, reader.localized(`error_msg_fileNotFound`), true, [ | ||||||
| 		window_metadata[`id`] = window.id; |               source, | ||||||
| 		window_metadata[`focused`] = window.focused; |             ]); | ||||||
| 		window_metadata[`state`] = window.state; |  | ||||||
| 		window_metadata[`type`] = window.type; |  | ||||||
| 		window_metadata[`incognito`] = window.incognito; |  | ||||||
| 		window_metadata[`alwaysOnTop`] = window.alwaysOnTop; |  | ||||||
| 		window_metadata[`sessionId`] = window.sessionId; |  | ||||||
| 		window_metadata[`tabs`] = window.tabs;*/ |  | ||||||
| 
 | 
 | ||||||
| 		/* Fill in data and events.  */ |             // Stop loading the page when an error has occured; it's not going to work!
 | ||||||
| 		function appearance() { |             if (!DEBUG) { | ||||||
| 			// Add missing classes to all elements. 
 |               window.close(); | ||||||
| 			function elements() { |             } | ||||||
| 				// Add buttons elements. 
 |           } | ||||||
| 				function buttons() { |         })(); | ||||||
| 					document.querySelectorAll(`button`).forEach((button) => { |       } | ||||||
| 						if (!button.classList.contains(`btn`)) { |     } | ||||||
| 							button.classList.add(`btn`); |  | ||||||
| 						} |  | ||||||
| 						if (!button.classList.contains(`waves-effect`)) { |  | ||||||
| 							button.classList.add(`waves-effect`); |  | ||||||
| 						} |  | ||||||
| 					}) |  | ||||||
| 					document.querySelectorAll(`a`).forEach((button) => { |  | ||||||
| 						if (!button.classList.contains(`waves-effect`)) { |  | ||||||
| 							button.classList.add(`waves-effect`); |  | ||||||
| 						} |  | ||||||
| 					}) |  | ||||||
| 
 | 
 | ||||||
| 					 |     // Get the window.
 | ||||||
| 				} |     this[`metadata`] = chrome.windows.getCurrent(); | ||||||
| 				buttons(); |  | ||||||
| 			} |  | ||||||
| 
 | 
 | ||||||
|  |     /* | ||||||
|  |     window_metadata[`id`] = window.id; | ||||||
|  |     window_metadata[`focused`] = window.focused; | ||||||
|  |     window_metadata[`state`] = window.state; | ||||||
|  |     window_metadata[`type`] = window.type; | ||||||
|  |     window_metadata[`incognito`] = window.incognito; | ||||||
|  |     window_metadata[`alwaysOnTop`] = window.alwaysOnTop; | ||||||
|  |     window_metadata[`sessionId`] = window.sessionId; | ||||||
|  |     window_metadata[`tabs`] = window.tabs;*/ | ||||||
| 
 | 
 | ||||||
| 			function icons() { |     /* Fill in data and events.  */ | ||||||
| 				let target_elements = document.querySelectorAll(`[data-icon]`); |     function appearance() { | ||||||
|  |       // Add missing classes to all elements.
 | ||||||
|  |       function elements() { | ||||||
|  |         // Add buttons elements.
 | ||||||
|  |         function buttons() { | ||||||
|  |           document.querySelectorAll(`button`).forEach((button) => { | ||||||
|  |             if (!button.classList.contains(`btn`)) { | ||||||
|  |               button.classList.add(`btn`); | ||||||
|  |             } | ||||||
|  |           }); | ||||||
| 
 | 
 | ||||||
| 				target_elements.forEach((element) => { |           [] | ||||||
| 					// Get the content before removing it.
 |             .concat( | ||||||
| 					let element_data = {}; |               document.querySelectorAll(`a`) | ||||||
|  |                 ? document.querySelectorAll(`a`) | ||||||
|  |                 : [], | ||||||
|  |               document.querySelectorAll(`button`) | ||||||
|  |                 ? document.querySelectorAll(`button`) | ||||||
|  |                 : [], | ||||||
|  |               document.querySelectorAll( | ||||||
|  |                 `input:not([type="checkbox"]):not([type="radio"]):not([type="range"])`, | ||||||
|  |               ) | ||||||
|  |                 ? document.querySelectorAll( | ||||||
|  |                     `input:not([type="checkbox"]):not([type="radio"]):not([type="range"])`, | ||||||
|  |                   ) | ||||||
|  |                 : [], | ||||||
|  |             ) | ||||||
|  |             .forEach((ELEMENT_TYPE) => { | ||||||
|  |               ELEMENT_TYPE.forEach((button) => { | ||||||
|  |                 if ( | ||||||
|  |                   button.classList | ||||||
|  |                     ? !button.classList.contains(`waves-effect`) | ||||||
|  |                     : true | ||||||
|  |                 ) { | ||||||
|  |                   button.classList.add(`waves-effect`); | ||||||
|  |                 } | ||||||
|  |               }); | ||||||
|  |             }); | ||||||
|  |         } | ||||||
|  |         buttons(); | ||||||
|  |       } | ||||||
| 
 | 
 | ||||||
| 					// Swap the placement of the existing content.
 |       function icons() { | ||||||
| 					function swap() { |         let target_elements = document.querySelectorAll(`[data-icon]`); | ||||||
| 						element_data[`content`] = element.innerHTML; |  | ||||||
| 						element.innerHTML = ``; |  | ||||||
| 
 | 
 | ||||||
| 						let element_text = document.createElement(`span`); |         target_elements.forEach((element) => { | ||||||
| 						element_text.innerHTML = element_data[`content`]; |           // Get the content before removing it.
 | ||||||
|  |           let element_data = {}; | ||||||
| 
 | 
 | ||||||
| 						element.appendChild(element_text); |           // Swap the placement of the existing content.
 | ||||||
| 					} |           function swap() { | ||||||
|  |             element_data[`content`] = element.innerHTML; | ||||||
|  |             element.innerHTML = ``; | ||||||
| 
 | 
 | ||||||
| 					// Add the icon.
 |             let element_text = document.createElement(`span`); | ||||||
| 					function iconify() { |             element_text.innerHTML = element_data[`content`]; | ||||||
| 						// Get the icon.
 |  | ||||||
| 						element_data[`icon`] = element.getAttribute(`data-icon`); |  | ||||||
| 
 | 
 | ||||||
| 						// Get the icon.
 |             element.appendChild(element_text); | ||||||
| 						let icon_element = document.createElement(`i`); |           } | ||||||
| 						icon_element.className = `mdi mdi-`.concat(element_data[`icon`]); |  | ||||||
| 						element.prepend(icon_element); |  | ||||||
| 					} |  | ||||||
| 
 | 
 | ||||||
| 					swap(); |           // Add the icon.
 | ||||||
| 					iconify(); |           function iconify() { | ||||||
| 				}); |             // Get the icon.
 | ||||||
| 			} |             element_data[`icon`] = element.getAttribute(`data-icon`); | ||||||
| 
 | 
 | ||||||
| 			function text() { |             // Get the icon.
 | ||||||
| 				let text_elements = {}; |             let icon_element = document.createElement(`i`); | ||||||
| 				text_elements[`content`] = document.querySelectorAll("[for]"); |             icon_element.className = `mdi mdi-`.concat(element_data[`icon`]); | ||||||
| 				text_elements[`alt`] = document.querySelectorAll("[alt-for]"); |             element.prepend(icon_element); | ||||||
| 				text_elements[`title`] = document.querySelectorAll("[title-for]"); |           } | ||||||
| 
 | 
 | ||||||
| 				text_elements[`content`].forEach((text_element) => { |           swap(); | ||||||
| 					let text_inserted = texts.localized( |           iconify(); | ||||||
| 						text_element.getAttribute(`for`), |         }); | ||||||
| 						false, |       } | ||||||
| 						text_element.hasAttribute(`for-parameter`) |  | ||||||
| 							? text_element.getAttribute(`for-parameter`).split(",") |  | ||||||
| 							: null, |  | ||||||
| 					); |  | ||||||
| 					if (!text_inserted) { |  | ||||||
| 						text_inserted = texts.localized( |  | ||||||
| 							`term_`.concat(text_element.getAttribute(`for`)), |  | ||||||
| 						); |  | ||||||
| 					} |  | ||||||
| 
 | 
 | ||||||
| 					if (text_element.tagName.toLowerCase().includes(`input`)) { |       function text() { | ||||||
| 						text_element.setAttribute(`placholder`, text_inserted); |         let text_elements = {}; | ||||||
| 					} else { |         text_elements[`content`] = document.querySelectorAll("[for]"); | ||||||
| 						text_element.innerText = text_inserted; |         text_elements[`alt`] = document.querySelectorAll("[alt-for]"); | ||||||
| 					} |         text_elements[`title`] = document.querySelectorAll("[title-for]"); | ||||||
| 				}); |  | ||||||
| 
 | 
 | ||||||
| 				delete text_elements[`content`]; |         text_elements[`content`].forEach((text_element) => { | ||||||
| 				Object.keys(text_elements).forEach((key) => { |           let text_inserted = texts.localized( | ||||||
| 					if (text_elements[key]) { |             text_element.getAttribute(`for`), | ||||||
| 						text_elements[key].forEach((text_element) => { |             false, | ||||||
| 							let text_inserted = texts.localized( |             text_element.hasAttribute(`for-parameter`) | ||||||
| 								text_element.getAttribute(key.concat(`-for`)), |               ? text_element.getAttribute(`for-parameter`).split(",") | ||||||
| 								false, |               : null, | ||||||
| 								text_element.hasAttribute(key.concat(`for-parameter`)) |           ); | ||||||
| 									? text_element |           if (!text_inserted) { | ||||||
| 											.getAttribute(key.concat(`for-parameter`)) |             text_inserted = texts.localized( | ||||||
| 											.split(",") |               `term_`.concat(text_element.getAttribute(`for`)), | ||||||
| 									: null, |             ); | ||||||
| 							); |           } | ||||||
| 							if (!text_inserted) { |  | ||||||
| 								text_inserted = texts.localized( |  | ||||||
| 									`term_`.concat(text_element.getAttribute(key.concat(`-for`))), |  | ||||||
| 								); |  | ||||||
| 							} |  | ||||||
| 
 | 
 | ||||||
| 							text_element.setAttribute(key, text_inserted); |           if (text_element.tagName.toLowerCase().includes(`input`)) { | ||||||
| 						}); |             text_element.setAttribute(`placholder`, text_inserted); | ||||||
| 					} |           } else { | ||||||
| 				}); |             text_element.innerText = text_inserted; | ||||||
| 			} |           } | ||||||
|  |         }); | ||||||
| 
 | 
 | ||||||
| 			async function storage() { |         delete text_elements[`content`]; | ||||||
| 				// Import the module.
 |         Object.keys(text_elements).forEach((key) => { | ||||||
| 				const secretariat = await import( |           if (text_elements[key]) { | ||||||
| 					chrome.runtime.getURL("scripts/secretariat.js") |             text_elements[key].forEach((text_element) => { | ||||||
| 				); |               let text_inserted = texts.localized( | ||||||
|  |                 text_element.getAttribute(key.concat(`-for`)), | ||||||
|  |                 false, | ||||||
|  |                 text_element.hasAttribute(key.concat(`for-parameter`)) | ||||||
|  |                   ? text_element | ||||||
|  |                       .getAttribute(key.concat(`for-parameter`)) | ||||||
|  |                       .split(",") | ||||||
|  |                   : null, | ||||||
|  |               ); | ||||||
|  |               if (!text_inserted) { | ||||||
|  |                 text_inserted = texts.localized( | ||||||
|  |                   `term_`.concat(text_element.getAttribute(key.concat(`-for`))), | ||||||
|  |                 ); | ||||||
|  |               } | ||||||
| 
 | 
 | ||||||
| 				let input_elements = document.querySelectorAll("[data-store]"); |               text_element.setAttribute(key, text_inserted); | ||||||
|  |             }); | ||||||
|  |           } | ||||||
|  |         }); | ||||||
|  |       } | ||||||
| 
 | 
 | ||||||
| 				input_elements.forEach((input_element) => { |       async function storage() { | ||||||
| 					// Gather data about the element.
 |         // Import the module.
 | ||||||
| 					// Get the corresponding storage data.
 |         const secretariat = await import( | ||||||
| 					let data = {}; |           chrome.runtime.getURL("scripts/secretariat.js") | ||||||
| 					data[`source`] = input_element.getAttribute(`data-store`); |         ); | ||||||
| 					data[`value`] = secretariat.read(data[`source`], -1); |  | ||||||
| 
 | 
 | ||||||
| 					data[`value`].then((value) => { |         let input_elements = document.querySelectorAll("[data-store]"); | ||||||
| 						switch (input_element.getAttribute(`type`).toLowerCase()) { |  | ||||||
| 							case `checkbox`: |  | ||||||
| 								input_element.checked = value; |  | ||||||
| 								break; |  | ||||||
| 							case `progress`: |  | ||||||
| 							case `range`: |  | ||||||
| 								// Ensure that it is a positive floating-point number.
 |  | ||||||
| 								value = !value ? 0 : Math.abs(parseFloat(value)); |  | ||||||
| 								if (value > 100) { |  | ||||||
| 									value = value / 100; |  | ||||||
| 								} |  | ||||||
| 
 | 
 | ||||||
| 								// Set the attribute of the progress bar.
 |         input_elements.forEach((input_element) => { | ||||||
| 								input_element.setAttribute(`value`, value); |           // Gather data about the element.
 | ||||||
| 								input_element.setAttribute(`max`, 1); |           // Get the corresponding storage data.
 | ||||||
| 								break; |           let data = {}; | ||||||
| 							default: |           data[`source`] = input_element.getAttribute(`data-store`); | ||||||
| 								input_element.value = value ? value : ``; |           data[`value`] = secretariat.read(data[`source`], -1); | ||||||
| 								break; |  | ||||||
| 						} |  | ||||||
| 					}); |  | ||||||
| 				}); |  | ||||||
| 			} |  | ||||||
| 
 | 
 | ||||||
| 			elements(); |           data[`value`].then((value) => { | ||||||
| 			text(); |             switch (input_element.getAttribute(`type`).toLowerCase()) { | ||||||
| 			icons(); |               case `checkbox`: | ||||||
| 			storage(); |                 input_element.checked = value; | ||||||
| 		} |                 break; | ||||||
|  |               case `progress`: | ||||||
|  |               case `range`: | ||||||
|  |                 // Ensure that it is a positive floating-point number.
 | ||||||
|  |                 value = !value ? 0 : Math.abs(parseFloat(value)); | ||||||
|  |                 if (value > 100) { | ||||||
|  |                   value = value / 100; | ||||||
|  |                 } | ||||||
| 
 | 
 | ||||||
| 		// Adds events to the window.
 |                 // Set the attribute of the progress bar.
 | ||||||
| 		function events() { |                 input_element.setAttribute(`value`, value); | ||||||
| 			/* Add events related to storage. */ |                 input_element.setAttribute(`max`, 1); | ||||||
| 			async function storage() { |                 break; | ||||||
| 				// Import the module.
 |               default: | ||||||
| 				const secretariat = await import( |                 input_element.value = value ? value : ``; | ||||||
| 					chrome.runtime.getURL("scripts/secretariat.js") |                 break; | ||||||
| 				); |             } | ||||||
|  |           }); | ||||||
|  |         }); | ||||||
|  |       } | ||||||
| 
 | 
 | ||||||
| 				let input_elements = document.querySelectorAll("[data-store]"); |       elements(); | ||||||
|  |       text(); | ||||||
|  |       icons(); | ||||||
|  |       storage(); | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
| 				input_elements.forEach((input_element) => { |     // Adds events to the window.
 | ||||||
| 					// Gather data about the element.
 |     function events() { | ||||||
| 					// Get the corresponding storage data.
 |       /* Add events related to storage. */ | ||||||
|  |       async function storage() { | ||||||
|  |         // Import the module.
 | ||||||
|  |         const secretariat = await import( | ||||||
|  |           chrome.runtime.getURL("scripts/secretariat.js") | ||||||
|  |         ); | ||||||
| 
 | 
 | ||||||
| 					let element = {}; |         let input_elements = document.querySelectorAll("[data-store]"); | ||||||
| 					element[`type`] = input_element.getAttribute(`type`).toLowerCase(); |  | ||||||
| 					element[`event`] = function () {}; |  | ||||||
| 
 | 
 | ||||||
| 					switch (element[`type`]) { |         input_elements.forEach((input_element) => { | ||||||
| 						case `checkbox`: |           // Gather data about the element.
 | ||||||
| 							element[`event`] = function () { |           // Get the corresponding storage data.
 | ||||||
| 								let UI_item = {}; |  | ||||||
| 								UI_item[`source`] = this.getAttribute(`data-store`); |  | ||||||
| 								UI_item[`value`] = this.checked; |  | ||||||
| 								secretariat.write(UI_item[`source`], UI_item[`value`]); |  | ||||||
| 							}; |  | ||||||
| 							break; |  | ||||||
| 						default: |  | ||||||
| 							element[`event`] = function () { |  | ||||||
| 								let UI_item = {}; |  | ||||||
| 								UI_item[`source`] = this.getAttribute(`data-store`); |  | ||||||
| 								UI_item[`value`] = element[`type`].includes(`num`) |  | ||||||
| 									? parseFloat(this.value) % 1 != 0 |  | ||||||
| 										? parseFloat(this.value) |  | ||||||
| 										: parseInt(this.value) |  | ||||||
| 									: this.value; |  | ||||||
| 								secretariat.write(UI_item[`source`], UI_item[`value`]); |  | ||||||
| 							}; |  | ||||||
| 							break; |  | ||||||
| 					} |  | ||||||
| 
 | 
 | ||||||
| 					input_element.addEventListener("change", element[`event`]); |           let element = {}; | ||||||
| 				}); |           element[`type`] = input_element.getAttribute(`type`).toLowerCase(); | ||||||
| 			} |           element[`event`] = function () {}; | ||||||
| 
 | 
 | ||||||
| 			/* Map buttons to their corresponding action buttons. */ |           switch (element[`type`]) { | ||||||
| 			function actions() { |             case `checkbox`: | ||||||
| 				function links() { |               element[`event`] = function () { | ||||||
| 					let buttons = document.querySelectorAll("button[href]"); |                 let UI_item = {}; | ||||||
|  |                 UI_item[`source`] = this.getAttribute(`data-store`); | ||||||
|  |                 UI_item[`value`] = this.checked; | ||||||
|  |                 secretariat.write(UI_item[`source`], UI_item[`value`]); | ||||||
|  |               }; | ||||||
|  |               break; | ||||||
|  |             default: | ||||||
|  |               element[`event`] = function () { | ||||||
|  |                 let UI_item = {}; | ||||||
|  |                 UI_item[`source`] = this.getAttribute(`data-store`); | ||||||
|  |                 UI_item[`value`] = element[`type`].includes(`num`) | ||||||
|  |                   ? parseFloat(this.value) % 1 != 0 | ||||||
|  |                     ? parseFloat(this.value) | ||||||
|  |                     : parseInt(this.value) | ||||||
|  |                   : this.value; | ||||||
|  |                 secretariat.write(UI_item[`source`], UI_item[`value`]); | ||||||
|  |               }; | ||||||
|  |               break; | ||||||
|  |           } | ||||||
| 
 | 
 | ||||||
| 					if (buttons) { |           input_element.addEventListener("change", element[`event`]); | ||||||
| 						buttons.forEach((button) => { |         }); | ||||||
| 							let event = function () { |       } | ||||||
| 								// Get the data from the button.
 |  | ||||||
| 								let target = {}; |  | ||||||
| 								target[`source`] = this.getAttribute(`href`); |  | ||||||
| 
 | 
 | ||||||
| 								// Get the correct path.
 |       /* Map buttons to their corresponding action buttons. */ | ||||||
| 								target[`path`] = ( |       function actions() { | ||||||
| 									!target[`source`].includes(`://`) |         function links() { | ||||||
| 										? window.location.pathname |           let buttons = document.querySelectorAll("button[href]"); | ||||||
| 												.split(`/`) |  | ||||||
| 												.slice(0, -1) |  | ||||||
| 												.join(`/`) |  | ||||||
| 												.concat(`/`) |  | ||||||
| 										: `` |  | ||||||
| 								).concat(target[`source`]); |  | ||||||
| 
 | 
 | ||||||
| 								windowman.new( |           if (buttons) { | ||||||
| 									target[`path`], |             buttons.forEach((button) => { | ||||||
| 									this.getAttribute(`tab-height`) |               let event = function () { | ||||||
| 										? this.getAttribute(`tab-height`) |                 // Get the data from the button.
 | ||||||
| 										: null, |                 let target = {}; | ||||||
| 									this.getAttribute(`tab-width`) |                 target[`source`] = this.getAttribute(`href`); | ||||||
| 										? this.getAttribute(`tab-width`) |  | ||||||
| 										: null, |  | ||||||
| 								); |  | ||||||
| 							}; |  | ||||||
| 							button.addEventListener("click", event); |  | ||||||
| 						}); |  | ||||||
| 					} |  | ||||||
| 				} |  | ||||||
| 
 | 
 | ||||||
| 				links(); |                 // Get the correct path.
 | ||||||
| 			} |                 target[`path`] = ( | ||||||
|  |                   !target[`source`].includes(`://`) | ||||||
|  |                     ? window.location.pathname | ||||||
|  |                         .split(`/`) | ||||||
|  |                         .slice(0, -1) | ||||||
|  |                         .join(`/`) | ||||||
|  |                         .concat(`/`) | ||||||
|  |                     : `` | ||||||
|  |                 ).concat(target[`source`]); | ||||||
| 
 | 
 | ||||||
| 			/* |                 windowman.new( | ||||||
| 			Update the interface based on the storage data changes. |                   target[`path`], | ||||||
| 			*/ |                   this.getAttribute(`tab-height`) | ||||||
| 			async function updates() { |                     ? this.getAttribute(`tab-height`) | ||||||
| 				// Import the module.
 |                     : null, | ||||||
| 				const secretariat = await import( |                   this.getAttribute(`tab-width`) | ||||||
| 					chrome.runtime.getURL("scripts/secretariat.js") |                     ? this.getAttribute(`tab-width`) | ||||||
| 				); |                     : null, | ||||||
|  |                 ); | ||||||
|  |               }; | ||||||
|  |               button.addEventListener("click", event); | ||||||
|  |             }); | ||||||
|  |           } | ||||||
|  |         } | ||||||
| 
 | 
 | ||||||
| 				// Get the storage data.
 |         /* Enable the searching interface. */ | ||||||
| 				let storage_data = await secretariat.read(); |         function search() {} | ||||||
| 
 | 
 | ||||||
| 				async function enable() { |         // Responsiveness to different screen sizes.
 | ||||||
| 					let input_elements = document.querySelectorAll("[data-enable]"); |         function resize() { | ||||||
|  |           function sidebar() { | ||||||
|  |             if (document.querySelector(`.sidebar`)) { | ||||||
|  |               if (window.innerWidth < 600) { | ||||||
|  |                 document | ||||||
|  |                   .querySelector(`.sidebar`) | ||||||
|  |                   .style.setProperty(`display`, `none`); | ||||||
|  |                 document | ||||||
|  |                   .querySelector(`.sidebar`) | ||||||
|  |                   .style.setProperty(`position`, `fixed`); | ||||||
|  |               } else { | ||||||
|  |                 document | ||||||
|  |                   .querySelector(`.sidebar`) | ||||||
|  |                   .style.removeProperty(`display`); | ||||||
|  |                 document | ||||||
|  |                   .querySelector(`.sidebar`) | ||||||
|  |                   .style.removeProperty(`position`); | ||||||
|  |               } | ||||||
|  |               if (document.querySelector(`[data-action="ui,close,navbar"]`)) { | ||||||
|  |                 document | ||||||
|  |                   .querySelector(`[data-action="ui,close,navbar"]`) | ||||||
|  |                   .addEventListener(`click`, function () { | ||||||
|  |                     if (document.querySelector(`.sidebar`)) { | ||||||
|  |                       document | ||||||
|  |                         .querySelector(`.sidebar`) | ||||||
|  |                         .style.removeProperty("display"); | ||||||
|  |                       document | ||||||
|  |                         .querySelector(`.sidebar`) | ||||||
|  |                         .style.removeProperty("position"); | ||||||
|  |                     } | ||||||
|  |                   }); | ||||||
|  |               } | ||||||
|  |               if (document.querySelector(`[data-action="ui,open,navbar"]`)) { | ||||||
|  |                 document | ||||||
|  |                   .querySelector(`[data-action="ui,open,navbar"]`) | ||||||
|  |                   .addEventListener(`click`, function () { | ||||||
|  |                     document | ||||||
|  |                       .querySelector(`.sidebar`) | ||||||
|  |                       .style.setProperty("display", "block"); | ||||||
|  |                     document | ||||||
|  |                       .querySelector(`.sidebar`) | ||||||
|  |                       .style.setProperty("position", "fixed"); | ||||||
|  |                   }); | ||||||
|  |               } | ||||||
|  |             } | ||||||
|  |           } | ||||||
| 
 | 
 | ||||||
| 					if (input_elements) { |           sidebar(); | ||||||
| 						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(`Object`) |  | ||||||
| 												? ((await secretariat.read(input_element.getAttribute("data-enable"))).length > 0) |  | ||||||
| 												: !!(await secretariat.read(input_element.getAttribute("data-enable"))) |  | ||||||
| 											) |  | ||||||
| 											: false); |  | ||||||
| 								})(); |  | ||||||
| 							} |  | ||||||
| 						}); |  | ||||||
| 					} |  | ||||||
| 				} |  | ||||||
| 
 | 
 | ||||||
| 				// Update the input elements.
 |         window.addEventListener("resize", resize); | ||||||
| 				secretariat.observe((what) => { |         resize(); | ||||||
| 					enable(); |         links(); | ||||||
| 				}); |       } | ||||||
| 
 | 
 | ||||||
| 				enable(); |       /* | ||||||
| 			} |     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") | ||||||
|  |         ); | ||||||
| 
 | 
 | ||||||
| 			storage(); |         // Get the storage data.
 | ||||||
| 			actions(); |         let storage_data = await secretariat.read(); | ||||||
| 			updates(); |  | ||||||
| 		} |  | ||||||
| 
 | 
 | ||||||
| 		headers(); |         async function enable() { | ||||||
| 		appearance(); |           let input_elements = document.querySelectorAll("[data-enable]"); | ||||||
| 		events(); | 
 | ||||||
| 	} |           if (input_elements) { | ||||||
|  |             input_elements.forEach((input_element) => { | ||||||
|  |               if (input_element.getAttribute("data-enable")) { | ||||||
|  |                 (async () => { | ||||||
|  |                   console.log( | ||||||
|  |                     await secretariat.read( | ||||||
|  |                       input_element.getAttribute("data-enable"), | ||||||
|  |                     ), | ||||||
|  |                   ); | ||||||
|  |                   input_element.disabled = !((await secretariat.read( | ||||||
|  |                     input_element.getAttribute("data-enable"), | ||||||
|  |                   )) != null | ||||||
|  |                     ? (typeof (await secretariat.read( | ||||||
|  |                         input_element.getAttribute("data-enable"), | ||||||
|  |                       ))).includes(`obj`) | ||||||
|  |                       ? ( | ||||||
|  |                           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(); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     headers(); | ||||||
|  |     appearance(); | ||||||
|  |     events(); | ||||||
|  |   } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export { windowman }; | export { windowman }; | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue