diff --git a/content/install-hook-usercss.js b/content/install-hook-usercss.js index 80e837ea..944c235b 100644 --- a/content/install-hook-usercss.js +++ b/content/install-hook-usercss.js @@ -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); diff --git a/install-usercss/install-usercss.js b/install-usercss/install-usercss.js index 82bb8b73..c074bf16 100644 --- a/install-usercss/install-usercss.js +++ b/install-usercss/install-usercss.js @@ -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); }); } }