2025-09-25 22:16:05 +10:00
|
|
|
let textbox;
|
2025-09-25 09:07:44 +10:00
|
|
|
let textconsole;
|
2025-09-25 22:16:05 +10:00
|
|
|
let text = '<p># welcome to gride!</p>\n<p># start typing to code a program in Ground!</p>\n<p>';
|
|
|
|
|
|
|
|
|
|
// Wait for the window to load before doing anything
|
|
|
|
|
window.addEventListener("load", function() {
|
|
|
|
|
textbox = document.getElementById("editor");
|
2025-09-25 09:07:44 +10:00
|
|
|
textconsole = document.getElementById("console");
|
2025-09-25 22:16:05 +10:00
|
|
|
textbox.innerHTML = text + "</p>";
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// When we press a key, start doing stuff
|
|
|
|
|
onkeydown = (event) => {
|
|
|
|
|
if (event.key == "Enter") {
|
|
|
|
|
text += "</p>\n<p>";
|
|
|
|
|
} else if (event.key == "Tab") {
|
|
|
|
|
text += " ";
|
|
|
|
|
} else if (event.key == "Backspace") {
|
|
|
|
|
if (text.slice(-8) == "</p>\n<p>") {
|
|
|
|
|
text = text.slice(0, -8)
|
|
|
|
|
} else {
|
|
|
|
|
text = text.slice(0, -1)
|
|
|
|
|
}
|
|
|
|
|
} else if (!(event.key == "Control" || event.key == "Alt" || event.key == "Meta" || event.key == "Shift" || event.key == "Escape")) {
|
|
|
|
|
text += event.key;
|
|
|
|
|
}
|
|
|
|
|
textbox.innerHTML = text + "</p>";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function runCode() {
|
|
|
|
|
console.log(text.split("<p>").join("").split("</p>").join(""));
|
|
|
|
|
const result = await fetch("http://localhost:5000/runProgram", {
|
|
|
|
|
"method": "POST",
|
|
|
|
|
//"mode": "no-cors",
|
|
|
|
|
"body": text.split("<p>").join("").split("</p>").join("")
|
|
|
|
|
});
|
|
|
|
|
const data = await result.json();
|
2025-09-25 09:07:44 +10:00
|
|
|
textconsole.innerHTML = data.stdout;
|
2025-09-25 22:16:05 +10:00
|
|
|
}
|