This doesn’t cause the change that would occur if the code was executed, probably because I lack some command to execute it.
I think this way because the following code (which I currently don’t fully understand) does work, I mean, I call the exact same code (available website A) from the exact same website (website B) and it does work:
window.setTimeout(()=>{
fetch('https://raw.githubusercontent.com/USER/REPOSITORY/main/FILE.js').then(function(response) {
if (!response.ok) {
return false;
}
return response.blob();
}).then(function(myBlob) {
var objectURL = URL.createObjectURL(myBlob);
var sc = document.createElement("script");
sc.setAttribute("src", objectURL);
sc.setAttribute("type", "text/javascript");
document.head.appendChild(sc);
})
}, 1000);
I don’t know why this second code works. This code reads very “sugary” or unintuitive for me, I would prefer to learn what I lacked in the first code instead just automatically use this second code.
What did I lack in the first code eval()?, bind()? Something else?
You may want to explain what is being done in the second code and if it can be written with clearer naming and without something like:
Also, what does the loaded script… do… or at least, does it do things when you load it? Or is it just a bunch of functions you’re loading and then trying to invoke some other way?
@m_hutley my sincerece apology for confused in the reply which I have deleted. I have edited the question to make it clearer that website A is GitHub (and not website B as I wrote in the deleted comment).
Okay, i’m guessing that you’re then doing document.head.appendChild(newScript); and immediately following it with doSomeFunction() and expecting it to work.
I must find a workaround because the particular code I run is very general and helps me stay more focused on several computers I work with. I just want all loaders to load it from one place so if there is a change, I change only in one place for all terminals.
Perhaps, I should ask for explanation of the second code example above, which is the only one I found to work from nearly ten or twelve I have tested.