-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
31 lines (24 loc) · 844 Bytes
/
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
const worker = new Worker("./worker.js", { type: "module" });
worker.addEventListener("message", async ({ data }) => {
document.getElementById("output").innerHTML = data;
});
worker.onerror = function (event) {
throw new Error("s" + event.message + " (" + event.filename + ":" + event.lineno + ")");
}
// define a function to send a message to the worker
window.sendMessage = function (args) {
console.log("Sending message to worker");
worker.postMessage(args);
};
async function loadFile() {
var files = document.getElementById('file').files;
var file = files[0];
// check if file was selected
if (!file) {
alert("Please select a file");
return;
}
// send the file to the worker
sendMessage(file)
}
document.getElementById("upload").addEventListener("click", loadFile, false);