Revert "Revert defer page script injection (#758)"
This reverts commit 7d52326eb7
.
This commit is contained in:
parent
0e9d5ce08c
commit
67930db04c
|
@ -88,10 +88,9 @@ const APPLY = (() => {
|
||||||
// Since it's easy to spoof the browser version in pre-Quantum FF we're checking
|
// 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
|
// for getPreventDefault which got removed in FF59 https://bugzil.la/691151
|
||||||
const EVENT_NAME = chrome.runtime.id;
|
const EVENT_NAME = chrome.runtime.id;
|
||||||
const usePageScript = CHROME || IS_OWN_PAGE || Event.prototype.getPreventDefault ?
|
let ready;
|
||||||
Promise.resolve(false) : injectPageScript();
|
|
||||||
return (el, content, disabled) =>
|
return (el, content, disabled) =>
|
||||||
usePageScript.then(ok => {
|
checkPageScript().then(ok => {
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
el.textContent = content;
|
el.textContent = content;
|
||||||
// https://github.com/openstyles/stylus/issues/693
|
// https://github.com/openstyles/stylus/issues/693
|
||||||
|
@ -107,6 +106,14 @@ const APPLY = (() => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function checkPageScript() {
|
||||||
|
if (!ready) {
|
||||||
|
ready = CHROME || IS_OWN_PAGE || Event.prototype.getPreventDefault ?
|
||||||
|
Promise.resolve(false) : injectPageScript();
|
||||||
|
}
|
||||||
|
return ready;
|
||||||
|
}
|
||||||
|
|
||||||
function injectPageScript() {
|
function injectPageScript() {
|
||||||
const scriptContent = EVENT_NAME => {
|
const scriptContent = EVENT_NAME => {
|
||||||
document.currentScript.remove();
|
document.currentScript.remove();
|
||||||
|
@ -149,7 +156,7 @@ const APPLY = (() => {
|
||||||
script.onerror = resolveFalse;
|
script.onerror = resolveFalse;
|
||||||
window.addEventListener('error', resolveFalse);
|
window.addEventListener('error', resolveFalse);
|
||||||
window.addEventListener(EVENT_NAME, handleInit);
|
window.addEventListener(EVENT_NAME, handleInit);
|
||||||
document.documentElement.appendChild(script);
|
(document.head || document.documentElement).appendChild(script);
|
||||||
return promise.then(result => {
|
return promise.then(result => {
|
||||||
script.remove();
|
script.remove();
|
||||||
window.removeEventListener(EVENT_NAME, handleInit);
|
window.removeEventListener(EVENT_NAME, handleInit);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user