-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
139 lines (123 loc) · 4.3 KB
/
index.html
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<html>
<head>
<title>Webscripter</title>
<link rel="stylesheet" href="webconsole/webconsole.css">
<link rel="stylesheet" href="codemirror/codemirror.css">
<link rel="stylesheet" href="codemirror/material-darker.css">
<link rel="stylesheet" href="styles.css">
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Source+Code+Pro&display=swap" rel="stylesheet">
<!-- <link rel="stylesheet" href="https://reeceyang.github.io/luce.css/luce.css"> -->
</head>
<body>
<div class="split" id="one">
<button id="run-button">Run</button>
<button id="clear-button">Clear</button>
<button id="get-button">Get Code Link</button>
<input id="url-box"></input><span id="message-box"></span>
<br>
</div>
<div class="split" id="two"></div>
<span id="bruh"></span>
</body>
<html>
<script src="codemirror/codemirror.js"></script>
<script src="codemirror/javascript.js"></script>
<script src="webconsole/webconsole.js"></script>
<script src="split.min.js"></script>
<script src="lzma.js"></script>
<script>
Webconsole.addTo(document.getElementById("two"));
Webconsole.addDarkModeTo(document.body);
Split(['#one', '#two']);
var editor = CodeMirror(document.getElementById("one"), {
value: "println(\"hello world!\");",
mode: "javascript",
theme: "material-darker",
lineNumbers: true,
lineWrapping: true
});
editor.setOption("extraKeys", {
Tab: function(cm) {
var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
cm.replaceSelection(spaces);
}
});
var lzma = new LZMA("lzma_worker.js");
var base64 = location.hash.substr(1);
if (base64 !== "") {
fetch("data:application/octet-stream;base64," + base64).then(r => r.blob()).then(function (blob) {
reader = new FileReader();
reader.onload = function () {
var compressedData = Array.from(new Uint8Array(reader.result));
lzma.decompress(compressedData, function(plaintext, error) {
if (error) {
alert("Failed to decompress data: " + error);
return;
}
editor.setValue(plaintext);
});
};
reader.readAsArrayBuffer(blob);
});
}
function updateUrl() {
var plaintext = editor.getValue();
lzma.compress(plaintext, 1, function (compressed, error) {
if (error) {
alert("Failed to compress data: " + error);
return;
}
var reader = new FileReader();
reader.onload = function () {
var base64 = reader.result.substr(reader.result.indexOf(",") + 1);
location.hash = base64;
};
reader.readAsDataURL(new Blob([new Uint8Array(compressed)]));
});
}
if (base64 === "") {
updateUrl();
}
editor.on("change", () => {
updateUrl();
});
let AsyncFunction = Object.getPrototypeOf(async function(){}).constructor;
document.getElementById("run-button").addEventListener("click", async function () {
document.getElementById("run-button").disabled = true;
await println("===RESTARTING===");
var start = (new Date()).getTime();
var main = new AsyncFunction(editor.getValue() + `\ndocument.getElementById("bruh").click();`);
//waited = false;
var bruhPressed = new Promise(function(resolve, reject) { // HACK: this is so scuffed but it works
document.getElementById("bruh").addEventListener("click", function() {
resolve();
//waited = true;
});
});
main();
await bruhPressed;
//console.log(waited);
println();
println("======DONE======");
println("TIME ELAPSED: ", (new Date()).getTime() - start, " ms");
document.getElementById("run-button").disabled = false;
});
document.getElementById("clear-button").addEventListener("click", () => {clear();});
document.getElementById("get-button").addEventListener("click", () => {
document.getElementById("url-box").value = location;
document.getElementById("url-box").select();
document.execCommand("copy");
// only add the message if the box is empty
if (document.getElementById("message-box").innerHTML == "") {
var defNode = document.createElement("span");
defNode.appendChild(document.createTextNode("copied link to clipboard!"));
defNode.classList.add("message");
defNode.classList.add("startfadeout");
defNode.addEventListener("animationend", () => {
defNode.parentNode.removeChild(defNode);
});
document.getElementById("message-box").appendChild(defNode);
}
});
</script>