-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
109 lines (96 loc) · 4.25 KB
/
index.html
File metadata and controls
109 lines (96 loc) · 4.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CodeHorses</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet"
crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"
crossorigin="anonymous"></script>
<link rel="stylesheet" href="codemirror/lib/codemirror.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.7/codemirror.min.js"></script>
<script src="codemirror/mode/clike/clike.js"></script>
<link rel="stylesheet" href="codemirror/theme/dracula.css">
<script src="codemirror/addon/edit/closebrackets.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
<script src="codemirror/mode/python/python.js"></script>
<link href="https://fonts.googleapis.com/css2?family=Quicksand:wght@300..700&display=swap" rel="stylesheet">
</head>
<body style="background-color: #414141; color: white; font-family: Quicksand,sans-serif">
<h1 style="background-color: #198754; color: white; text-align: center;" class="p-2">CodeHorses</h1>
<div class="row">
<div class="col">
<div class="d-flex justify-content-between mb-2 bg-dark rounded p-2">
<div class="col-auto w-25">
<label class="visually-hidden" for="autoSizingSelect">Preference</label>
<select class="form-select" id="autoSizingSelect">
<option selected>Choose...</option>
<option value="Java">Java</option>
<option value="C++">C++</option>
<option value="Python">Python</option>
</select>
</div>
<div>
<button type="button" class="btn btn-success" id="run"><i class="bi bi-play-fill"></i></button>
</div>
</div>
<textarea type="text" class="form-control" aria-label="First name" id="editor"></textarea>
</div>
<div class="col d-flex flex-column bg-dark rounded px-4">
<div class="h-50">
<label for="input" class="text-light mt-3 mb-2">Input</label>
<textarea type="text" class="form-control h-75" aria-label="Last name" id="input"></textarea>
</div>
<div class="h-50">
<label for="output" class="text-light mb-2">Output</label>
<textarea type="text" class="form-control h-75" aria-label="Last name" id="output" readonly></textarea>
</div>
</div>
</div>
<footer style="background-color: #198754; color: white; text-align: center;" class="p-2 mt-2"> <i
class="bi bi-c-circle-fill"></i> QUANTUM_X</footer>
</body>
<script>
let editor = CodeMirror.fromTextArea(document.getElementById("editor"), {
lineNumbers: true,
mode: "text/x-c++src",
theme: "dracula",
autoCloseBrackets: true,
});
var width = window.innerWidth;
editor.setSize(width * 0.7, "500");
let option = document.getElementById("autoSizingSelect");
option.addEventListener("change", () => {
if (option.value == "Java") {
editor.setOption("mode", "text/x-java");
}
else if (option.value == "Python") {
editor.setOption("mode", "text/x-python");
}
else {
editor.setOption("mode", "text/x-c++src");
}
});
let run = document.getElementById("run");
let input = document.getElementById("input");
let output = document.getElementById("output");
let code;
run.addEventListener("click", async () => {
code = {
code: editor.getValue(),
input: input.value,
lang: option.value,
}
let oData = await fetch("http://localhost:8000/compile", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(code),
});
let d = await oData.json();
output.value = d.output;
});
</script>
</html>