Last active
May 14, 2019 18:47
-
-
Save igoventura/42a14de0dbe35f9b37dfa55fb2e78ac3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AsyncInjector { | |
constructor() {} | |
injectScript( | |
document: any, | |
src: string, | |
async: boolean = false, | |
callbackLoaded = () => {} | |
) { | |
let script = document.createElement("script"); | |
let id = src.slice(src.lastIndexOf("/") + 1); | |
script.type = "text/javascript"; | |
script.async = async; | |
script.onload = callbackLoaded; | |
script.src = src; | |
script.id = id; | |
if (!document.getElementById(id)){ | |
document.getElementsByTagName("head")[0].appendChild(script); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AsyncInjector{constructor(){}injectScript(e,t,c,a=(()=>{})){let n=e.createElement("script"),s=t.slice(t.lastIndexOf("/")+1);n.type="text/javascript",n.async=c,n.onload=a,n.src=t,n.id=s,e.getElementById(s)||e.getElementsByTagName("head")[0].appendChild(n)}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment