set loader percentage and send manual refresh
This commit is contained in:
		
							parent
							
								
									4242ecc799
								
							
						
					
					
						commit
						f2b2106bbd
					
				
					 1 changed files with 53 additions and 40 deletions
				
			
		|  | @ -48,18 +48,15 @@ class Page_Popup extends Page { | |||
| 			: ((this[`status`]) | ||||
| 				? this[`status`] | ||||
| 				: {}); | ||||
| 
 | ||||
| 		// Call for scraping of data if global data does not indicate automatic scraping or if data doesn't exist. 
 | ||||
| 		if (!await global.read([`settings`, `behavior`, `autoRun`]) && DATA[`status`] == null) { | ||||
| 			this.send(); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	async loading() { | ||||
| 		this.loading = new Loader(); | ||||
| 		this[`elements`] = (this[`elements`]) ? this[`elements`] : {}; | ||||
| 		this[`elements`][`loader`] = new Loader(); | ||||
| 	} | ||||
| 
 | ||||
| 	async switch() { | ||||
| 		if (this.elements[`frame`]) { | ||||
| 			let PAGES = { | ||||
| 				"results": "results.htm", | ||||
| 				"loading": "load.htm", | ||||
|  | @ -76,7 +73,7 @@ class Page_Popup extends Page { | |||
| 					PAGES[PAGE] = chrome.runtime.getURL(`pages/popup/${PAGES[PAGE]}`); | ||||
| 				}); | ||||
| 				 | ||||
| 			let PAGE = PAGES[((this[`status`][`done`]) | ||||
| 				let PAGE = PAGES[(((this[`status`] && (typeof this[`status`]).includes(`obj`)) ? (this[`status`][`done`] >= 1) : false) | ||||
| 					? ((this[`status`][`error`] && this[`status`][`error`] != {}) | ||||
| 						? `error` | ||||
| 						: `results`) | ||||
|  | @ -85,9 +82,16 @@ class Page_Popup extends Page { | |||
| 				// Replace the iframe src with the new page.
 | ||||
| 				this.elements[`frame`].src = PAGE; | ||||
| 				 | ||||
| 	 | ||||
| 				// The results page has its own container. 
 | ||||
| 				this.elements[`container`].classList[(PAGE.includes(`results`)) ? `remove` : `add`](`container`); | ||||
| 			}; | ||||
| 		} | ||||
| 
 | ||||
| 		// Also set the loader. 
 | ||||
| 		(this[`elements`][`loader`]) | ||||
| 			? ((this[`status`] ? (this[`status`][`done`] ? (this[`status`][`done`] <= 1) : false) : false) ? parseFloat(this[`elements`][`loader`].update(this[`status`][`done`])) : false) | ||||
| 			: false | ||||
| 	}; | ||||
| 	 | ||||
| 	async content() { | ||||
|  | @ -99,21 +103,30 @@ class Page_Popup extends Page { | |||
| 		// Check if the frame is available.
 | ||||
| 		if (this.elements[`frame`]) { | ||||
| 			await this.switch(); | ||||
| 			this.background(); | ||||
| 
 | ||||
| 			// Call for scraping of data if global data does not indicate automatic scraping or if data doesn't exist. 
 | ||||
| 			if (!await global.read([`settings`, `behavior`, `autoRun`]) && DATA[`status`] == null) { | ||||
| 				this.send({"refresh": "automatic"}); | ||||
| 			} | ||||
| 		} else { | ||||
| 			this.loading(); | ||||
| 		} | ||||
| 	}; | ||||
| 
 | ||||
| 	send() { | ||||
| 	/* | ||||
| 	Call for the scraper and analyzer.  | ||||
| 	*/ | ||||
| 	send(options) { | ||||
| 		// Make sure that it is the correct format. 
 | ||||
| 		let OPTIONS = (options && (typeof options).includes(`obj`) && !Array.isArray(options)) ? options : {}; | ||||
| 
 | ||||
| 		try { | ||||
| 			// Send a message to the content script. 
 | ||||
| 			Tabs.query(null, 0).then((TAB) => { | ||||
| 				chrome.tabs.sendMessage(TAB.id, {"refresh": true}); | ||||
| 				chrome.tabs.sendMessage(TAB.id, OPTIONS); | ||||
| 			}); | ||||
| 		} catch(err) { | ||||
| 			logging.error(err.name, err.message, err.stack); | ||||
| 			throw (err); | ||||
| 		}; | ||||
| 	}; | ||||
| 
 | ||||
|  | @ -133,12 +146,12 @@ class Page_Popup extends Page { | |||
| 			chrome.runtime.openOptionsPage(); | ||||
| 		}) : false; | ||||
| 
 | ||||
| 		(this[`elements`][`button`][`open,help`]) ? this[`elements`][`button`][`open,help`].addEventListener("click", () => { | ||||
| 		(this[`elements`][`button`][`open,help`]) ? this[`elements`][`button`][`open,help`].addEventListener(`click`, () => { | ||||
| 			new Window(`help.htm`); | ||||
| 		}) : false;  | ||||
| 
 | ||||
| 		(this[`elements`][`button`][`analysis,reload`]) ? this[`elements`][`button`][`analysis,reload`].addEventListener("click", () => { | ||||
| 			this.send(); | ||||
| 		(this[`elements`][`button`][`analysis,reload`]) ? this[`elements`][`button`][`analysis,reload`].addEventListener(`click`, () => { | ||||
| 			this.send({"refresh": "manual"}); | ||||
| 		}) : false; | ||||
| 	} | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue