Created
January 12, 2018 07:10
-
-
Save t0rr3sp3dr0/c0718f5e42ce3f26d3ce053dcb79a4dd 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
const run = (glue, stdin, stdout, stderr) => { | |
const iframe = document.createElement('iframe'); | |
iframe.setAttribute('style', 'display: none; '); | |
iframe.src = 'about:blank'; | |
iframe.onload = () => { | |
iframe.contentWindow.Module = { | |
preRun: [ | |
() => { | |
const _in = new TextEncoder('ascii').encode(stdin).values(); | |
iframe.contentWindow.FS.init(() => _in.next().value, null, null); | |
}, | |
], | |
postRun: [ | |
() => document.body.removeChild(iframe), | |
], | |
print: (...arguments) => stdout(arguments.join(' ')), | |
printErr: (...arguments) => stderr(arguments.join(' ')), | |
setStatus: console.log, | |
monitorRunDependencies: (left) => { | |
this.totalDependencies = Math.max(this.totalDependencies || 0, left); | |
console.log(left ? 'Preparing... (' + (this.totalDependencies - left) + '/' + this.totalDependencies + ')' : 'All downloads complete.'); | |
}, | |
}; | |
const script = document.createElement('script'); | |
script.setAttribute('async', ''); | |
script.src = glue; | |
iframe.contentDocument.body.appendChild(script); | |
} | |
document.body.appendChild(iframe); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment