process current contents when live-reload is enabled
This commit is contained in:
		
							parent
							
								
									9994811819
								
							
						
					
					
						commit
						707cd6576f
					
				|  | @ -5,10 +5,10 @@ if (typeof self.oldCode !== 'string') { | |||
|   self.oldCode = (document.querySelector('body > pre') || document.body).textContent; | ||||
|   chrome.runtime.onConnect.addListener(port => { | ||||
|     if (port.name !== 'downloadSelf') return; | ||||
|     port.onMessage.addListener(({id, timer}) => { | ||||
|     port.onMessage.addListener(({id, force}) => { | ||||
|       fetch(location.href, {mode: 'same-origin'}) | ||||
|         .then(r => r.text()) | ||||
|         .then(code => ({id, code: timer && code === self.oldCode ? null : code})) | ||||
|         .then(code => ({id, code: force || code !== self.oldCode ? code : null})) | ||||
|         .catch(error => ({id, error: error.message || `${error}`})) | ||||
|         .then(msg => { | ||||
|           port.postMessage(msg); | ||||
|  |  | |||
|  | @ -331,7 +331,11 @@ | |||
|       onToggled(e) { | ||||
|         if (e) isEnabled = e.target.checked; | ||||
|         if (installed || installedDup) { | ||||
|           (isEnabled ? start : stop)(); | ||||
|           if (isEnabled) { | ||||
|             check({force: true}); | ||||
|           } else { | ||||
|             stop(); | ||||
|           } | ||||
|           $('.install').disabled = isEnabled; | ||||
|           Object.assign($('#live-reload-install-hint'), { | ||||
|             hidden: !isEnabled, | ||||
|  | @ -340,8 +344,8 @@ | |||
|         } | ||||
|       }, | ||||
|     }; | ||||
|     function check() { | ||||
|       getData() | ||||
|     function check(opts) { | ||||
|       getData(opts) | ||||
|         .then(update, logError) | ||||
|         .then(() => { | ||||
|           timer = 0; | ||||
|  | @ -398,10 +402,11 @@ | |||
|           .then(tab => tab.url === initialUrl && location.reload()) | ||||
|           .catch(closeCurrentTab); | ||||
|       }); | ||||
|       return ({timer = true} = {}) => new Promise((resolve, reject) => { | ||||
|       return (opts = {}) => new Promise((resolve, reject) => { | ||||
|         const id = performance.now(); | ||||
|         resolvers.set(id, {resolve, reject}); | ||||
|         port.postMessage({id, timer}); | ||||
|         opts.id = id; | ||||
|         port.postMessage(opts); | ||||
|       }); | ||||
|     } | ||||
|   } | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	Block a user