-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmock_input.html
59 lines (53 loc) · 1.37 KB
/
mock_input.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>🥐 mock input</title>
<style>
.node {
display: inline-block;
padding: 1rem;
}
.node input {
display: block;
}
</style>
</head>
<body>
<h1>🥐 mock input</h1>
<button onclick="addNode()">add node</button>
<br>
<script type="text/javascript">
const addNode = () => {
const div = document.createElement("div");
div.id = `node${document.getElementsByClassName("node").length}`;
div.className = "node";
const title = document.createElement("span");
title.innerText = div.id;
div.appendChild(title);
for (let i = 0; i < 3; i++) {
const input = document.createElement("input");
input.type = "range";
input.min = 0;
input.max = 20;
input.value = 0;
input.step = 0.1;
div.appendChild(input);
}
const button = document.createElement("button");
button.innerText = "remove";
button.onclick = () => document.body.removeChild(div);
div.appendChild(button);
document.body.appendChild(div);
};
const ws = new WebSocket("ws://localhost:1338");
ws.onopen = () => setInterval(() => {
for (let node of document.getElementsByClassName("node")) {
const id = node.id;
const values = Array.from(document.querySelectorAll(`#${id} input`)).map(i => i.value);
ws.send(`${id} ${values.join(" ")}`);
}
}, 100);
</script>
</body>
</html>