-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
60 lines (55 loc) · 1.6 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
</head>
<body>
<script type="text/javascript">
//document.getElementById('message').addEventListener('keypress', function(event) {
// if (event.keyCode == 13) {
// event.preventDefault();
// }
//});
function stopRKey(evt) {
var evt = (evt) ? evt : ((event) ? event : null);
var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
if ((evt.keyCode == 13) && (node.type=="text")) {return false;}
}
document.onkeypress = stopRKey;
// helper function: log message to screen
function log(msg) {
// document.getElementById('engine').textContent = msg;
document.getElementById('engine').textContent = msg;
}
// setup websocket with callbacks
var sock = new WebSocket('ws://localhost:6400/socket');
sock.onopen = function() {
log('CONNECT');
};
sock.onclose = function() {
log('DISCONNECT');
};
sock.onmessage = function(event) {
log('MESSAGE: ' + event.data);
};
function send() {
var msg = document.getElementById('message').value;
sock.send(msg);
};
function sendVal(cmd) {
sock.send(cmd);
};
</script>
<h1>♞ Harpa Chess</h1>
<form>
<p>
Message: <input id="message" type="text" value="uci">
</p>
</form>
<button onclick="send();">Send Message</button>
<button onclick="sendVal('uci');">uci</button>
<button onclick="sendVal('go infinite');">go infinite</button>
<button onclick="sendVal('stop');">stop</button>
<p id="engine"></p>
</body>
</html>