Skip to content

Instantly share code, notes, and snippets.

@Asbra
Created June 8, 2017 01:19
Show Gist options
  • Save Asbra/a507cf4003ed91a19ada95b813730a9c to your computer and use it in GitHub Desktop.
Save Asbra/a507cf4003ed91a19ada95b813730a9c to your computer and use it in GitHub Desktop.
Anti-Adblock JavaScript loader
(function() {
var index = 0,
scripts = ["https://domain.tld/script1.js","https://otherdomain.tld/script2.js"],
newScriptNode,
loadScripts = function () {
if (index >= scripts.length) { return; }
newScriptNode = window.document.createElement("script");
newScriptNode.type = "text/javascript";
newScriptNode.async = true;
var scriptNode = window.document.getElementsByTagName("script")[0];
newScriptNode.src = scripts[index];
// newScriptNode.crossOrigin = "anonymous";
newScriptNode.onerror = function () {
index++;
loadScripts()
};
scriptNode.parentNode.insertBefore(newScriptNode, scriptNode)
};
loadScripts();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment