From 776d9888725f33f2c56d0e411daae7ebc7643da3 Mon Sep 17 00:00:00 2001 From: zyqunix <117040076+zyqunix@users.noreply.github.com> Date: Tue, 15 Apr 2025 21:18:46 +0200 Subject: [PATCH] js evaluator --- js/index.html | 20 ++++++++++++++++++++ js/index.js | 19 +++++++++++++++++++ js/style.css | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+) create mode 100644 js/index.html create mode 100644 js/index.js create mode 100644 js/style.css diff --git a/js/index.html b/js/index.html new file mode 100644 index 0000000..62469a8 --- /dev/null +++ b/js/index.html @@ -0,0 +1,20 @@ + + + + + + JavaScript Evaluator + + + + +
+

JavaScript Evaluator

+ + +
Output
+
+ + + + diff --git a/js/index.js b/js/index.js new file mode 100644 index 0000000..52930e4 --- /dev/null +++ b/js/index.js @@ -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; +}); diff --git a/js/style.css b/js/style.css new file mode 100644 index 0000000..39374f2 --- /dev/null +++ b/js/style.css @@ -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; +}