Skip to content

Instantly share code, notes, and snippets.

@ego-lay-atman-bay
Last active September 26, 2023 20:49
Show Gist options
  • Select an option

  • Save ego-lay-atman-bay/0eecc1e3156ef0bfb23268f47281aa1d to your computer and use it in GitHub Desktop.

Select an option

Save ego-lay-atman-bay/0eecc1e3156ef0bfb23268f47281aa1d to your computer and use it in GitHub Desktop.
// definition
function loadScript(scriptUrl) {
console.log('loading script', scriptUrl);
const script = document.createElement('script');
script.src = scriptUrl;
document.body.appendChild(script);
return new Promise((res, rej) => {
script.onload = function() {
res({message: 'script loaded'});
}
script.onerror = function (error) {
rej(error.target);
}
});
}
function log(message) {
console.log(message);
span = document.createElement('p');
span.innerHTML = message;
document.body.appendChild(span);
}
// use
loadScript('https://cdn.jsdelivr.net/npm/eruda')
.then((response) => {
log(response.message);
log(eruda);
log('')
for (let a in eruda) {
log(a)
}
eruda.init();
})
.catch((error) => {
log(error.message)
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment