started adding some command functionality

This commit is contained in:
Valentijn :)
2024-01-16 12:28:59 +01:00
parent eaa428518a
commit 713bb6136f
11 changed files with 711 additions and 67 deletions

View File

@@ -1,10 +1,9 @@
const username = "guest";
const hostname = `192.168.${Math.floor(Math.random()*100)}.${Math.floor(Math.random()*255)}`;
document.addEventListener("DOMContentLoaded", function () {
document.querySelectorAll(".pathText").forEach((element)=> {
element.innerHTML = `${username}@${hostname}`;
element.innerHTML = `guest@${hostname}`;
});
const terminalInput = document.getElementById("terminalInput");
@@ -16,22 +15,36 @@ document.addEventListener("DOMContentLoaded", function () {
terminalInput.addEventListener('blur', function(e) {
e.preventDefault();
terminalInput.focus();
setTimeout(() => {
terminalInput.focus();
}, 0);
}, false);
document.addEventListener('click', function(e) {
e.preventDefault();
setTimeout(() => {
terminalInput.focus();
}, 0);
}, false);
terminalInput.focus();
terminalInput.addEventListener("keydown", function (e) {
terminalInput.addEventListener("keydown", async function (e) {
if (e.key === "Enter"){
sendCommand(e);
await sendCommand(e);
}
});
});
function sendCommand(e){
async function sendCommand(e){
const command = e.target.value;
console.log("COMMAND SENT: "+command);
const response = await fetch("/execute")
const files = await response.json();
console.log(files);
e.target.value = "";
resizeInput();
}