js evaluator

This commit is contained in:
zyqunix 2025-04-15 21:18:46 +02:00
parent 4fb79a1d68
commit 776d988872
No known key found for this signature in database
GPG key ID: 134A8DEEA83B80E6
3 changed files with 86 additions and 0 deletions

20
js/index.html Normal file
View file

@ -0,0 +1,20 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>JavaScript Evaluator</title>
<link rel="shortcut icon" href="https://rimgo.pussthecat.org/RFbdMMB.png" type="image/x-icon">
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="card shadow">
<h1>JavaScript Evaluator</h1>
<textarea id="input" type="text" placeholder="Enter code..." rows="10" columns="10"></textarea>
<button id="evaluate">Evaluate</button>
<pre id="output" placeholder="Output" rows="5">Output</pre>
</div>
<script src="index.js"></script>
</body>
</html>

19
js/index.js Normal file
View file

@ -0,0 +1,19 @@
const btn = document.getElementById('evaluate');
const input = document.getElementById('input');
const output = document.getElementById('output');
btn.addEventListener('click', function() {
output.innerText = '';
const originalLog = console.log;
console.log = function(...args) {
output.innerText += args.join(' ') + '\n';
originalLog.apply(console, args);
};
try {
let result = eval(input.value);
if (result !== undefined) output.innerText += result;
} catch (e) {
output.innerText += 'Error: ' + e.message;
}
console.log = originalLog;
});

47
js/style.css Normal file
View file

@ -0,0 +1,47 @@
@import url(/global.css);
.container {
text-align: center;
padding: 20px;
border-radius: 20px;
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.7);
}
textarea {
width: 90%;
margin-top: 10px;
padding: 10px;
border-radius: 10px;
border: none;
background-color: #333;
color: #f0f0f0;
resize: none;
outline: none;
}
button {
width: 70%;
margin-top: 10px;
padding: 10px;
border-radius: 10px;
border: none;
background-color: #333;
color: #f0f0f0;
}
button {
cursor: pointer;
background-color: #444;
}
button:hover {
background-color: #555;
}
pre {
font-family: "JetBrainsMono";
background-color: #333;
color: #fff;
text-align: left;
padding: 3px;
}