EdgeCoder / templates /index.html
ayush-thakur02's picture
Create templates/index.html
43195a9 verified
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>EdgeCoder | Reconfigure</title>
<script src="https://cdn.jsdelivr.net/gh/Reconfigure-In/Content-Protection-Script@refs/heads/main/script.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.2/codemirror.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.2/codemirror.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.2/mode/python/python.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.24.1/themes/prism.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.24.1/prism.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.24.1/components/prism-python.min.js"></script>
<style>
body, html {
margin: 0;
padding: 0;
height: 100vh;
overflow: hidden;
font-family: Arial, sans-serif;
}
body {
display: flex;
flex-direction: column;
background-color: #f0f0f0;
}
.container {
display: flex;
flex: 1;
overflow: hidden;
}
.editor, .output {
flex: 1;
display: flex;
flex-direction: column;
margin: 10px;
background-color: #fff;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0,0,0,0.1);
}
.CodeMirror {
flex: 1;
height: auto;
font-size: 14px;
}
#output-container {
flex: 1;
overflow: auto;
font-family: monospace;
font-size: 14px;
line-height: 1.5;
}
#output-table {
border-collapse: collapse;
width: 100%;
}
#line-numbers {
width: 1%;
padding-left: 20px;
text-align: right;
color: #999;
user-select: none;
vertical-align: top;
border-right: 1px solid #ddd;
background-color: #f7f7f7;
}
#output {
padding-left: 10px;
white-space: pre-wrap;
word-break: break-all;
vertical-align: top;
}
.button-container {
padding: 10px;
background-color: #f0f0f0;
display: flex;
align-items: baseline;
}
button {
padding: 10px 20px;
background-color: black;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
transition: 0.3s;
margin-right: auto;
}
button:hover {
background-color: #333;
}
.error {
color: red;
font-weight: bold;
}
#output .token.comment { color: gray; }
#output .token.keyword { color: blue; }
#output .token.string { color: green; }
#output .token.function { color: red; }
#output .token.number { color: purple; }
a {
color: black;
text-decoration: none;
font-size: 16px;
margin-left: auto;
font-family: monospace;
}
</style>
</head>
<body>
<div class="container">
<div class="editor">
<textarea id="code">def div(x, y):
return x/y</textarea>
</div>
<div class="output">
<div id="output-container">
<table id="output-table">
<tr>
<td id="line-numbers"></td>
<td id="output"></td>
</tr>
</table>
</div>
</div>
</div>
<div class="button-container">
<button onclick="runCode()">Enhance \w EdgeCoder</button>
<a href="https://reconfigure.in/" target="_blank">Build By Reconfigure.in</a>
</div>
<script>
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
lineNumbers: true,
mode: "python",
theme: "default"
});
function runCode() {
alert("Thinking! Please wait a moment.");
var code = editor.getValue();
fetch('/', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: 'code=' + encodeURIComponent(code)
})
.then(response => response.json())
.then(data => {
var outputElement = document.getElementById('output');
var lineNumbersElement = document.getElementById('line-numbers');
if (data.error) {
outputElement.innerHTML = '<span class="error">Error: ' + data.error + '</span>\n\nTraceback:\n' + data.traceback;
} else {
outputElement.innerHTML = Prism.highlight(data.result, Prism.languages.python, 'python');
}
var lines = outputElement.innerHTML.split('\n');
lineNumbersElement.innerHTML = lines.map((_, i) => i + 1).join('\n');
var outputContainer = document.getElementById('output-container');
outputContainer.scrollTop = outputContainer.scrollHeight;
})
.catch((error) => {
console.error('Error:', error);
document.getElementById('output').innerHTML = '<span class="error">An unexpected error occurred. Please try again.</span>';
});
}
</script>
</body>
</html>