52 lines
1.6 KiB
HTML
52 lines
1.6 KiB
HTML
<html>
|
|
<head>
|
|
<script src="http://skulpt.org/js/skulpt.min.js"></script>
|
|
<script src="http://skulpt.org/js/skulpt-stdlib.js"></script>
|
|
</head>
|
|
<body>
|
|
<script>
|
|
let cb;
|
|
|
|
function outf(t) {
|
|
document.getElementById("output").innerHTML += t;
|
|
}
|
|
|
|
function inputf(prompt) {
|
|
document.getElementById("promptLbl").textContent = prompt;
|
|
const box = document.getElementById("inpBox");
|
|
document.getElementById("inpC").style.display = "block";
|
|
box.value = "";
|
|
box.focus();
|
|
return new Promise(r => cb = r);
|
|
}
|
|
|
|
function submitInput() {
|
|
const box = document.getElementById("inpBox");
|
|
document.getElementById("inpC").style.display = "none";
|
|
cb(box.value);
|
|
}
|
|
|
|
function runit() {
|
|
document.getElementById("output").innerHTML = "";
|
|
document.getElementById("inpC").style.display = "none";
|
|
Sk.configure({
|
|
output: outf,
|
|
read: x => Sk.builtinFiles.files[x],
|
|
inputfun: inputf,
|
|
inputfunTakesPrompt: true
|
|
});
|
|
Sk.misceval.asyncToPromise(() => Sk.importMainWithBody(" < stdin > ", false, document.getElementById("yourcode").value, true));
|
|
}
|
|
</script>
|
|
<textarea id="yourcode" cols="40" rows="6">name = raw_input("Name: ")
|
|
print "Hello, " + name
|
|
</textarea>
|
|
<button onclick="runit()">Run</button>
|
|
<pre id="output"></pre>
|
|
<div id="inpC" style="display:none;">
|
|
<label id="promptLbl"></label>
|
|
<input id="inpBox" onkeypress="event.key==='Enter' && submitInput()">
|
|
<button onclick="submitInput()">OK</button>
|
|
</div>
|
|
</body>
|
|
</html> |