put queue in another module instead
for future reusability
This commit is contained in:
		
							parent
							
								
									586578fe45
								
							
						
					
					
						commit
						f2e9869965
					
				
					 2 changed files with 43 additions and 26 deletions
				
			
		
							
								
								
									
										41
									
								
								scripts/common.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								scripts/common.js
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,41 @@ | |||
| // common.js provides the advanced data structures. 
 | ||||
| 
 | ||||
| export class Queue { | ||||
|      #elements; | ||||
| 
 | ||||
|      constructor() { | ||||
|           this.#elements = []; | ||||
|      } | ||||
| 
 | ||||
|      enqueue(element) { | ||||
|           this.#elements.push(element); | ||||
|      } | ||||
| 
 | ||||
|      dequeue() { | ||||
|           return this.#elements.shift(); | ||||
|      } | ||||
| 
 | ||||
|      isEmpty() { | ||||
|           return this.#elements.length <= 0; | ||||
|      } | ||||
| } | ||||
| 
 | ||||
| export class Stack { | ||||
|      #elements; | ||||
| 
 | ||||
|      constructor() { | ||||
|           this.#elements = []; | ||||
|      } | ||||
| 
 | ||||
|      push(element) { | ||||
|           this.#elements.push(element); | ||||
|      } | ||||
| 
 | ||||
|      pop() { | ||||
|           return this.#elements.pop(); | ||||
|      } | ||||
| 
 | ||||
|      isEmpty() { | ||||
|           return this.#elements.length <= 0; | ||||
|      } | ||||
| } | ||||
|  | @ -6,15 +6,11 @@ const secretariat = await import(chrome.runtime.getURL("scripts/secretariat.js") | |||
| const net = await import(chrome.runtime.getURL("scripts/net.js")); | ||||
| const texts = (await import(chrome.runtime.getURL("gui/scripts/read.js"))).default; | ||||
| const alerts = (await import(chrome.runtime.getURL("gui/scripts/alerts.js"))).default; | ||||
| const common = (await import(chrome.runtime.getURL("scripts/common.js"))); | ||||
| 
 | ||||
| export default class filters { | ||||
| 	constructor() { | ||||
| 		this.all = async () => { | ||||
| 			// Import the updater.
 | ||||
| 			const secretariat = await import( | ||||
| 				chrome.runtime.getURL("scripts/secretariat.js") | ||||
| 			); | ||||
| 
 | ||||
| 			return secretariat.read(`filters`, -1).then((filters) => { | ||||
| 				return filters; | ||||
| 			}); | ||||
|  | @ -43,27 +39,8 @@ export default class filters { | |||
| 	@return {boolean} the state | ||||
| 	*/ | ||||
| 	async update(URL) { | ||||
| 		// Apparently, JS doesn't have a native queueing system, but it might best work here.
 | ||||
| 		class Queue { | ||||
| 			constructor() { | ||||
| 				this.elements = []; | ||||
| 			} | ||||
| 
 | ||||
| 			enqueue(element) { | ||||
| 				this.elements.push(element); | ||||
| 			} | ||||
| 
 | ||||
| 			dequeue() { | ||||
| 				return this.elements.shift(); | ||||
| 			} | ||||
| 
 | ||||
| 			isEmpty() { | ||||
| 				return this.elements.length <= 0; | ||||
| 			} | ||||
| 		} | ||||
| 
 | ||||
| 		// Create a queue of the filters.
 | ||||
| 		let filters = new Queue(); | ||||
| 		let filters = new common.Queue(); | ||||
| 
 | ||||
| 		if (URL) { | ||||
| 			// Check if the URL is in a valid protocol
 | ||||
|  | @ -75,7 +52,6 @@ export default class filters { | |||
| 			// Add every item to the queue based on what was loaded first.
 | ||||
| 			if (await secretariat.read(`filters`, -1)) { | ||||
| 				for (let FILTER_URL_INDEX = 0; FILTER_URL_INDEX < Object.keys(await secretariat.read(`filters`, -1)).length; FILTER_URL_INDEX++) { | ||||
| 					console.log(await secretariat.read([`settings`], 1)); | ||||
| 					let FILTER_URL = Object.keys(await secretariat.read([`settings`, `filters`], 1))[FILTER_URL_INDEX]; | ||||
| 					if (FILTER_URL.includes(`://`)) { | ||||
| 						filters.enqueue(FILTER_URL); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue