-
Notifications
You must be signed in to change notification settings - Fork 0
/
kindaSave.html
73 lines (49 loc) · 1.7 KB
/
kindaSave.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
<!DOCTYPE html>
<html>
<body>
<p>A quotation is the repetition of one expression as part of another one, particularly when the quoted expression is well-known or explicitly attributed by citation to its original source.</p>
<input type="text" id="name" value="joe" disabled>
<input type="text" id="demo">
<p id="printarr"></p>
<button type="button" onclick="sendData()">Request data</button>
<script>
var array = [];
var d = new Date();
var start_time = -1;
function sendData(){
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("demo").innerHTML = this.responseText;
}
};
xhttp.open("POST", "http://127.0.0.1:5000/api/lookup", true);
xhttp.setRequestHeader("Content-type", "application/json");
sendString = '{"name": "'+document.getElementById("name").value+'","data": ['
for (i = 0;i<array.length;i++){
sendString += '["' + array[i][0] + '",' + array[i][1] + '],'
}
sendString = sendString.substring(0,sendString.length - 1)
sendString += ']}'
console.log(sendString)
xhttp.send(sendString);
}
//this function handels the event
document.getElementById("demo").addEventListener('keydown', function(event) {
var key = event.key; // const {key} = event;
//timing is handled here?
var d = new Date();
var time = d.getTime();
if (start_time == -1){
start_time = time
}
array.push([key,time-start_time]);
//prints out for debug
document.getElementById("printarr").innerHTML = "here is " + array;
if (key == "Enter"){
sendData()
}
});
</script>
</body>
</html>