diff --git a/content/apply.js b/content/apply.js index f1132746..90208d21 100644 --- a/content/apply.js +++ b/content/apply.js @@ -88,9 +88,10 @@ const APPLY = (() => { // Since it's easy to spoof the browser version in pre-Quantum FF we're checking // for getPreventDefault which got removed in FF59 https://bugzil.la/691151 const EVENT_NAME = chrome.runtime.id; - let ready; + const usePageScript = CHROME || IS_OWN_PAGE || Event.prototype.getPreventDefault ? + Promise.resolve(false) : injectPageScript(); return (el, content, disabled) => - checkPageScript().then(ok => { + usePageScript.then(ok => { if (!ok) { el.textContent = content; // https://github.com/openstyles/stylus/issues/693 @@ -106,14 +107,6 @@ const APPLY = (() => { } }); - function checkPageScript() { - if (!ready) { - ready = CHROME || IS_OWN_PAGE || Event.prototype.getPreventDefault ? - Promise.resolve(false) : injectPageScript(); - } - return ready; - } - function injectPageScript() { const scriptContent = EVENT_NAME => { document.currentScript.remove(); @@ -156,7 +149,7 @@ const APPLY = (() => { script.onerror = resolveFalse; window.addEventListener('error', resolveFalse); window.addEventListener(EVENT_NAME, handleInit); - (document.head || document.documentElement).appendChild(script); + document.documentElement.appendChild(script); return promise.then(result => { script.remove(); window.removeEventListener(EVENT_NAME, handleInit);