Created
October 11, 2019 19:33
-
-
Save boldsupport/d744103c4147912c7452d3d0ce746c72 to your computer and use it in GitHub Desktop.
load-subscriptions-script.js
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
<script type="text/javascript"> | |
(function accountInstall() { | |
var scriptSelectors = [ | |
'.cashier_loader_script', | |
'#bold-subscriptions-custom-script', | |
'#bold-subscriptions-script', | |
'#bold-subscriptions-platform-script', | |
]; | |
if (document.querySelector(scriptSelectors[0]) && document.querySelector(scriptSelectors[2])) { | |
return; | |
} | |
var xhr = new XMLHttpRequest(); | |
xhr.onreadystatechange = function () { | |
if (xhr.readyState == 4 && xhr.status == 200) { | |
var wrapper = document.createElement('div'); | |
wrapper.innerHTML = xhr.responseText; | |
for (var i = 0; i < scriptSelectors.length; i++) { | |
const scriptSelector = scriptSelectors[i]; | |
var script = wrapper.querySelector(scriptSelector); | |
var existingScript = document.querySelector(scriptSelector); | |
if (script && !existingScript) { | |
var newScript = document.createElement('script'); | |
newScript.type = 'text/javascript'; | |
newScript.innerHTML = script.innerHTML; | |
if (scriptSelector.indexOf('#') !== -1) { | |
newScript.id = scriptSelector.slice(1); | |
} | |
document.body.appendChild(newScript); | |
} | |
} | |
window.setTimeout(function () { | |
window.BOLD.subscriptions.contentLoaded(); | |
window.BOLD.subscriptions.platformContentLoaded(); | |
}, 0); | |
} | |
}; | |
xhr.open('GET', '/', true); | |
xhr.send(); | |
}()); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment