Open gillyspy opened 2 years ago
these changes i made here bd6b0dd3c2956f8193730a17e66c0bb0697df403 work for me
Note that mode 0 and 1 are the meaningful ones. The user can do 2 and 3 simply by adding event listener wrappers on their own scripts in combination with mode 1.
if ( scriptMode === 0 ){
Function(scriptContents)();
}
if ( scriptMode === 1 ){
createScriptEl({ node : 'head', scriptContents })
}
if ( scriptMode === 2 ){
window.addEventListener('load', (ev) => {
createScriptEl({ node : 'body', scriptContents });
})
}
if ( scriptMode === 3 ){
document.addEventListener('DOMContentLoaded', (ev) => {
createScriptEl({ node : 'body', scriptContents });
});
I would like to get a reference to the true global scope.
window.load
, etc, etc all provide a reference to window that is limited to content scripts.I see that in the content script that you are using
Function
to immediately run the script.What if there was an option to load the content into a
script
tag. Similar to what you are doing with css (andstyle
tags).in this way the script should load as if it was a local script and thus have global scope, etc.
maybe there could be a new declaration of
X===1 means to behave as proposed below
@mode
missing or undefined, etc means to behave as you already have it (usingFunction(scriptContents)()
)