clean up code
This commit is contained in:
		
							parent
							
								
									b50df3400a
								
							
						
					
					
						commit
						62d8e415e2
					
				
					 4 changed files with 15 additions and 157 deletions
				
			
		|  | @ -7,7 +7,6 @@ | |||
| import {global} from "/scripts/secretariat.js"; | ||||
| import Page from "/scripts/pages/page.js"; | ||||
| import texts from "/scripts/mapping/read.js"; | ||||
| import nested from "/scripts/utils/nested.js"; | ||||
| 
 | ||||
| class Page_MiniConfig extends Page { | ||||
| 	constructor () { | ||||
|  | @ -97,6 +96,7 @@ class Page_MiniConfig extends Page { | |||
| 					const set_classes = () => { | ||||
| 						Object.keys(ELEMENTS[STEP_NUMBER][`container`]).forEach((PART) => { | ||||
| 							ELEMENTS[STEP_NUMBER][`container`][PART].classList.add(`card`.concat(([`container`].includes(PART)) ? `` : `-`.concat(PART))); | ||||
| 							[`container`].includes(PART) ? ELEMENTS[STEP_NUMBER][`container`][PART].classList.add(`horizontal`) : null; | ||||
| 						}); | ||||
| 					} | ||||
| 
 | ||||
|  |  | |||
|  | @ -86,19 +86,19 @@ export default class scraper { | |||
| 	@param {Object} options the options | ||||
| 	@return {Object} the texts | ||||
| 	*/ | ||||
| 	getTexts(fields, options) { | ||||
| 	getTexts(FIELDS, OPTIONS) { | ||||
| 		let CONTENT; | ||||
| 
 | ||||
| 		/* Read for the particular fields. */ | ||||
| 		function read(fields) { | ||||
| 		function read(FIELDS) { | ||||
| 			let DATA = {}; // Store here the resulting data
 | ||||
| 
 | ||||
| 			(Object.keys(fields)).forEach((NAME) => { | ||||
| 			(Object.keys(FIELDS)).forEach((NAME) => { | ||||
| 				// Remove trailing spaces within the name.
 | ||||
| 				NAME = (typeof NAME).includes(`str`) ? NAME.trim() : NAME; | ||||
| 
 | ||||
| 				// Set the referring value.
 | ||||
| 				let VALUE = fields[NAME]; | ||||
| 				let VALUE = FIELDS[NAME]; | ||||
| 				VALUE = (typeof VALUE).includes(`str`) ? VALUE.trim() : VALUE; | ||||
| 
 | ||||
| 				if (VALUE && NAME) { | ||||
|  | @ -132,158 +132,20 @@ export default class scraper { | |||
| 		}; | ||||
| 
 | ||||
| 		// Determine and set the appropriate field source.
 | ||||
| 		let FIELDS = (((typeof fields).includes(`obj`) && fields) ? Object.keys(fields).length : false) ? fields : this.fields; | ||||
| 		((((typeof options).includes(`obj`) && options) ? Object.hasOwn(`update`) : false) ? options[`update`] : true) | ||||
| 			? this.fields = FIELDS | ||||
| 		let CRITERIA = (((typeof FIELDS).includes(`obj`) && FIELDS) ? Object.keys(FIELDS).length : false) ? FIELDS : this.fields; | ||||
| 		((((typeof OPTIONS).includes(`obj`) && OPTIONS) ? Object.hasOwn(`update`) : false) ? OPTIONS[`update`] : true) | ||||
| 			? this.fields = CRITERIA | ||||
| 			: null; | ||||
| 
 | ||||
| 		// Read the fields.
 | ||||
| 		(FIELDS) | ||||
| 			? CONTENT = read(FIELDS) | ||||
| 		(CRITERIA) | ||||
| 			? CONTENT = read(CRITERIA) | ||||
| 			: false; | ||||
| 
 | ||||
| 		// Set the data if the options doesn't indicate otherwise.
 | ||||
| 		(((((typeof options).includes(`obj`) && options) ? Object.hasOwn(`update`) : false) ? options[`update`] : true) && CONTENT) | ||||
| 		(((((typeof OPTIONS).includes(`obj`) && OPTIONS) ? Object.hasOwn(`update`) : false) ? OPTIONS[`update`] : true) && CONTENT) | ||||
| 			? this.texts = CONTENT | ||||
| 			: false; | ||||
| 		return (CONTENT); | ||||
| 	}; | ||||
| 
 | ||||
| 	/* | ||||
| 	Scrape the images from a page. | ||||
| 	It's temporarily disabled due to consequent flagging of the IP address. Also it's output is not yet implemented. This is a future point of expansion (Crit E). | ||||
| 
 | ||||
| 	@param {Object} fields the fields to scrape | ||||
| 	@param {Object} options the options | ||||
| 	@return {Object} the blob of the images | ||||
| 	*/ | ||||
| 	async getImages(fields, options) { | ||||
| 		let DISABLE = true // This is how to disable it
 | ||||
| 
 | ||||
| 		if (!DISABLE) { | ||||
| 			let CONTENT; | ||||
| 
 | ||||
| 			/* | ||||
| 			Get the blob of the image in an element. | ||||
| 
 | ||||
| 			@param {Element} element the element to get the blob from | ||||
| 			@return {Blob} the blob of the image | ||||
| 			*/ | ||||
| 			async function blobbify(element) { | ||||
| 				/* | ||||
| 				Get the URL of the image. | ||||
| 
 | ||||
| 				@param {Element} element the element to get the URL from | ||||
| 				@return {String} the URL of the image | ||||
| 				*/ | ||||
| 				function reference(element) { | ||||
| 					let LOCATION; | ||||
| 
 | ||||
| 					// Get using standard attributes.
 | ||||
| 					LOCATION = element.getAttribute(`src`); | ||||
| 
 | ||||
| 					if (!LOCATION) { | ||||
| 						// Use the CSS background image.
 | ||||
| 						(window.getComputedStyle(element).backgroundImage) | ||||
| 							? LOCATION = window.getComputedStyle(element).backgroundImage.slice(4, -1).replace(/"/g, "") | ||||
| 							: false; | ||||
| 					} | ||||
| 
 | ||||
| 					// Return the location.
 | ||||
| 					return LOCATION; | ||||
| 				} | ||||
| 
 | ||||
| 				/* | ||||
| 				Get the blob from the URL. | ||||
| 
 | ||||
| 				@param {String} URL the URL to get the blob from | ||||
| 				@return {Blob} the blob of the image | ||||
| 				*/ | ||||
| 				function getBlob(URL) { | ||||
| 					return(net.download(URL, `blob`)); | ||||
| 				} | ||||
| 
 | ||||
| 				let LOCATION = reference(element); | ||||
| 				let BLOB = await getBlob(LOCATION); | ||||
| 
 | ||||
| 				return ((BLOB.type.includes(`image`)) ? BLOB : null); | ||||
| 			} | ||||
| 
 | ||||
| 			/* Read for the particular fields. */ | ||||
| 			async function read(fields) { | ||||
| 				/* | ||||
| 				Select all images from an element and get their blobs. | ||||
| 
 | ||||
| 				@param {Element} element the element to get the images from | ||||
| 				@return {Array} the blobs of the images | ||||
| 				*/ | ||||
| 				async function select(element) { | ||||
| 					let IMAGES = [...element.querySelectorAll(`*`)]; | ||||
| 					let BLOBS = []; | ||||
| 
 | ||||
| 					if (IMAGES && IMAGES.length) { | ||||
| 						for (let IMAGE of IMAGES) { | ||||
| 							let BLOB = await blobbify(IMAGE); | ||||
| 							(BLOB) ? BLOBS.push(BLOB) : false; | ||||
| 						} | ||||
| 					} | ||||
| 
 | ||||
| 					return BLOBS; | ||||
| 				} | ||||
| 
 | ||||
| 				let DATA = []; // Store here the resulting data
 | ||||
| 
 | ||||
| 				for (let NAME of Object.keys(fields)) { | ||||
| 					// Remove trailing spaces within the name.
 | ||||
| 					NAME = (typeof NAME).includes(`str`) ? NAME.trim() : NAME; | ||||
| 					let VALUE = fields[NAME]; | ||||
| 
 | ||||
| 					if (VALUE && NAME) { | ||||
| 						// Check if array.
 | ||||
| 						if (Array.isArray(VALUE)) { | ||||
| 							// Temporarily create an empty list.
 | ||||
| 							for (let PARTICULAR of VALUE) { | ||||
| 								if ((typeof PARTICULAR).includes(`obj`) && PARTICULAR && !Array.isArray(PARTICULAR)) { | ||||
| 									DATA = [...DATA, ...(await read(PARTICULAR))]; | ||||
| 								} else { | ||||
| 									let ELEMENTS = [...(document.querySelectorAll(PARTICULAR))]; | ||||
| 
 | ||||
| 									if (ELEMENTS && ELEMENTS.length) { | ||||
| 										for (let ELEMENT of ELEMENTS) { | ||||
| 											let BLOBS = await select(ELEMENT); | ||||
| 											if (BLOBS && BLOBS.length) DATA = [...DATA, ...BLOBS]; | ||||
| 										} | ||||
| 									} | ||||
| 								} | ||||
| 							} | ||||
| 						} else if ((typeof VALUE).includes(`obj`) && VALUE) { | ||||
| 							DATA = [...DATA, ...(await read(VALUE))]; | ||||
| 						} else if (document.querySelector(VALUE)) { | ||||
| 							let ELEMENTS = [...(document.querySelectorAll(VALUE))]; | ||||
| 
 | ||||
| 							if (ELEMENTS && ELEMENTS.length) { | ||||
| 								for (let ELEMENT of ELEMENTS) { | ||||
| 									let BLOBS = await select(ELEMENT); | ||||
| 									if (BLOBS && BLOBS.length) DATA = [...DATA, ...BLOBS]; | ||||
| 								} | ||||
| 							} | ||||
| 						} | ||||
| 					} | ||||
| 				} | ||||
| 
 | ||||
| 				return (DATA); | ||||
| 			}; | ||||
| 
 | ||||
| 			// Read the fields.
 | ||||
| 			(((typeof fields).includes(`obj`) && fields) ? Object.keys(fields).length : false) | ||||
| 				? CONTENT = await read(fields) | ||||
| 				: false; | ||||
| 
 | ||||
| 			// Set the data if the options doesn't indicate otherwise.
 | ||||
| 			(((((typeof options).includes(`obj`) && options) ? Object.hasOwn(`update`) : false) ? options[`update`] : true) && CONTENT) | ||||
| 				? this.images = CONTENT | ||||
| 				: false; | ||||
| 			return (CONTENT); | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  |  | |||
|  | @ -17,7 +17,6 @@ export default class watch { | |||
| 		if (FILTER_RESULT && Object.keys(FILTER_RESULT).length > 0) { | ||||
| 			// Let user know that the website is supported, if ever they have opened the console. 
 | ||||
| 			new logging((new texts(`message_external_supported_title`)).localized, (new texts(`message_external_supported_body`)).localized); | ||||
| 
 | ||||
| 			watch.process(FILTER_RESULT); | ||||
| 		} | ||||
| 	} | ||||
|  |  | |||
|  | @ -79,16 +79,14 @@ nested.dictionary = class dictionary { | |||
| 	@param {object} options the options | ||||
| 	@return {object} the results | ||||
| 	*/ | ||||
| 	static search(data, value, options) { | ||||
| 	static search(DATA, TERM, OPTIONS) { | ||||
| 		// Set the default options.
 | ||||
| 		let OPTIONS = Object.assign({}, {"strictness": 0}, options); | ||||
| 		let DATA = data; | ||||
| 		let TERM = value; | ||||
| 		OPTIONS = Object.assign({}, {"strictness": 0}, OPTIONS); | ||||
| 		let RESULTS; | ||||
| 
 | ||||
| 		if (data && ((typeof data).includes(`obj`) && !Array.isArray(data))) { | ||||
| 		if (DATA && ((typeof DATA).includes(`obj`) && !Array.isArray(DATA))) { | ||||
| 			if (!TERM || ((typeof TERM).includes(`str`) ? !TERM.trim() : false)) { | ||||
| 				RESULTS = data; | ||||
| 				RESULTS = DATA; | ||||
| 			} else { | ||||
| 				RESULTS = {}; | ||||
| 
 | ||||
|  | @ -124,7 +122,6 @@ nested.dictionary = class dictionary { | |||
| 												((OPTIONS[`strictness`] < 0.5) | ||||
| 													? (VALUE[`current`].includes(TERM)) | ||||
| 													: false) | ||||
| 												|| TERM.includes(VALUE[`current`]) | ||||
| 												|| (RegExManager.test(VALUE[`current`]) | ||||
| 													? (new RegExp(VALUE[`current`])).test(TERM) | ||||
| 													: false))) | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue