let textbox; let text = '
# welcome to gride!
\n# start typing to code a program in Ground!
\n'; // Wait for the window to load before doing anything window.addEventListener("load", function() { textbox = document.getElementById("editor"); textbox.innerHTML = text + "
"; }); // When we press a key, start doing stuff onkeydown = (event) => { if (event.key == "Enter") { text += "\n"; } else if (event.key == "Tab") { text += " "; } else if (event.key == "Backspace") { if (text.slice(-8) == "
\n") { 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 + "
"; } async function runCode() { console.log(text.split("").join("").split("
").join("")); const result = await fetch("http://localhost:5000/runProgram", { "method": "POST", //"mode": "no-cors", "body": text.split("").join("").split("
").join("") }); const data = await result.json(); console.log("Output: ", data); }