Created
July 7, 2021 17:30
-
-
Save mrcnski/2d2c0dbaf805658537344c68f3d0f7ef to your computer and use it in GitHub Desktop.
Dynamically load SDK from skynet-js.hns
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"> | |
fetch(document.location.href, { method: "HEAD" }) | |
.then(resp => { | |
const portal = resp.headers.get("skynet-portal-api"); | |
const _loadScript = function(path) { | |
var script = document.createElement('script'); | |
script.type = 'text/javascript'; | |
script.src = path; | |
var callback = function () { | |
// Logic for finished initialization. | |
const button = document.getElementById("save-trigger") | |
button.classList.remove("loading") | |
} | |
script.onload = callback; | |
document.head.appendChild(script); | |
}; | |
const _addSubdomain = function(url, subdomain) { | |
const urlObj = new URL(url); | |
urlObj.hostname = `${subdomain}.${urlObj.hostname}`; | |
return urlObj.toString(); | |
} | |
_loadScript(_addSubdomain(portal, "skynet-js.hns") + "/4.0-beta/index.js"); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Few notes:
callback
function.skynet.
, e.g.new skynet.SkynetClient()
.