Update templates/index.html
Browse files- templates/index.html +12 -24
templates/index.html
CHANGED
|
@@ -59,6 +59,7 @@
|
|
| 59 |
background: #005bb5;
|
| 60 |
}
|
| 61 |
</style>
|
|
|
|
| 62 |
</head>
|
| 63 |
<body>
|
| 64 |
<div class="terminal">
|
|
@@ -70,35 +71,22 @@
|
|
| 70 |
</div>
|
| 71 |
</div>
|
| 72 |
<script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
function executeCode() {
|
| 74 |
const codeInput = document.getElementById("code-input");
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
fetch("/execute", {
|
| 78 |
-
method: "POST",
|
| 79 |
-
headers: { "Content-Type": "application/json" },
|
| 80 |
-
body: JSON.stringify({ code: codeInput.value }),
|
| 81 |
-
})
|
| 82 |
-
.then(response => response.json())
|
| 83 |
-
.then(data => {
|
| 84 |
-
outputDiv.innerHTML += `\n> ${codeInput.value}\n${data.result}`;
|
| 85 |
-
outputDiv.scrollTop = outputDiv.scrollHeight; // Auto-scroll to bottom
|
| 86 |
-
codeInput.value = ""; // Clear input field
|
| 87 |
-
})
|
| 88 |
-
.catch(error => {
|
| 89 |
-
outputDiv.innerHTML += `\nError: ${error}`;
|
| 90 |
-
outputDiv.scrollTop = outputDiv.scrollHeight;
|
| 91 |
-
});
|
| 92 |
}
|
| 93 |
|
| 94 |
function cleanup() {
|
| 95 |
-
|
| 96 |
-
.then(response => response.json())
|
| 97 |
-
.then(data => {
|
| 98 |
-
const outputDiv = document.getElementById("output");
|
| 99 |
-
outputDiv.innerHTML += `\n${data.result}`;
|
| 100 |
-
outputDiv.scrollTop = outputDiv.scrollHeight; // Auto-scroll to bottom
|
| 101 |
-
});
|
| 102 |
}
|
| 103 |
|
| 104 |
// Cleanup temporary files when the user leaves the page
|
|
|
|
| 59 |
background: #005bb5;
|
| 60 |
}
|
| 61 |
</style>
|
| 62 |
+
<script src="https://cdn.socket.io/4.0.1/socket.io.min.js"></script>
|
| 63 |
</head>
|
| 64 |
<body>
|
| 65 |
<div class="terminal">
|
|
|
|
| 71 |
</div>
|
| 72 |
</div>
|
| 73 |
<script>
|
| 74 |
+
const socket = io();
|
| 75 |
+
const outputDiv = document.getElementById("output");
|
| 76 |
+
|
| 77 |
+
socket.on("output", function (data) {
|
| 78 |
+
outputDiv.innerHTML += data.data;
|
| 79 |
+
outputDiv.scrollTop = outputDiv.scrollHeight; // Auto-scroll to bottom
|
| 80 |
+
});
|
| 81 |
+
|
| 82 |
function executeCode() {
|
| 83 |
const codeInput = document.getElementById("code-input");
|
| 84 |
+
socket.emit("execute", { code: codeInput.value });
|
| 85 |
+
codeInput.value = ""; // Clear input field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
}
|
| 87 |
|
| 88 |
function cleanup() {
|
| 89 |
+
socket.emit("cleanup");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
}
|
| 91 |
|
| 92 |
// Cleanup temporary files when the user leaves the page
|