-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
57 lines (49 loc) · 1.91 KB
/
index.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
49
50
51
52
53
54
55
56
57
document.getElementById('progress').indeterminate = true;
var worker = new Worker('worker.js');
worker.onmessage = function (message) {
if (typeof message.data === "boolean") {
if (message.data) {
document.getElementById("text").innerText = "Please wait while executing...";
} else {
document.getElementById("text").innerText = "Launching VM...";
}
return
}
document.getElementById("progress").style.visibility = "hidden";
document.getElementById("text").innerText = message.data;
document.getElementById("file-selector").value = "";
};
const exec = function(file) {
console.clear();
document.getElementById("progress").style.visibility = "visible";
document.getElementById("text").innerText = "Reading the file...";
worker.postMessage(file);
}
const fileSelector = document.getElementById('file-selector');
fileSelector.addEventListener('change', (event) => {
if (event.target.files.length < 1) {
return
}
exec(event.target.files[0]);
});
const load_demo = function () {
document.getElementById("progress").style.visibility = "visible";
document.getElementById("text").innerText = "Downloading byte code...";
let name = document.getElementById("demo-select").value
fetch("demo/" + name + ".class").then(async (res)=>{
worker.postMessage(await res.blob());
})
fetch("demo/" + name + ".java").then(async (res)=>{
document.getElementById("src").innerText = await res.text();
})
document.getElementById("demo-switch").style.visibility = "visible";
}
const toggle_src = function () {
let a = "text";
let b = "src";
if (document.getElementById(b).style.display === "block") {
[a, b] = [b, a];
}
document.getElementById(a).style.display = "none";
document.getElementById(b).style.display = "block";
}