forked from maierfelix/3d-code-vizard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
edit.js
48 lines (40 loc) · 962 Bytes
/
edit.js
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
edit.onclick = (e) => {
code_editor.style.display = "block";
edit.style.display = "none";
};
exit.onclick = (e) => {
code_editor.style.display = "none";
edit.style.display = "block";
};
analyse.onclick = (e) => {
localStorage.setItem("code", doc.getValue());
location.reload();
};
let editor = CodeMirror(document.getElementById("input"), {
mode: "text/javascript",
lineNumbers: true,
value: "",
width: window.innerWidth
});
let doc = editor.getDoc();
editor.on("change", (e) => {
});
function loadDefaultCode() {
fetch("./input.js").then(resp => resp.text()).then(txt => {
doc.setValue(txt);
editor.scrollTo(0, 0);
localStorage.setItem("code", txt);
main(txt);
});
};
if (localStorage.getItem("code") === null) {
loadDefaultCode();
} else {
let input = localStorage.getItem("code");
if (!input.length) loadDefaultCode();
else {
doc.setValue(input);
editor.scrollTo(0, 0);
main(input);
}
}