var speed_limit 20000 var text var texts var elements document getElem

 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
var speed_limit = 20000;
var text = "";
var texts = [];
var elements = document.getElementsByClassName('text');
for (var el in elements) {
texts.push(elements[el].innerText)
}
var input = document.getElementById('inputtext');
var count = 0;
var element;
var flag = false;
input.addEventListener('keyup', function(e) {
var inp_text = e.target.value;
count = 0;
var reg_exp = new RegExp("^(" + inp_text + ")", "i");
for (var el in texts) {
if (reg_exp.test(texts[el])) {
count++;
element = texts[el];
console.log(texts[el]);
}
}
console.log(count);
if (count == 1 && !flag) {
flag = true;
input.value = "";
text = element;
var words = text.split(' ');
var speed = ((text.length / words.length) / (speed_limit / 60)) * 1000;
var counter = 0;
var timer = setInterval(function() {
if (counter >= words.length) {
return;
}
input.value += words[counter++] + " ";
input.onkeyup();
}, speed);
}
})