var settings lang ru speed_limit 400 var cur document getElementById t

 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
var settings = {
lang: 'ru',
speed_limit: 400
}
var cur = document.getElementById('typefocus');
var after = document.getElementById('afterfocus');
function getText(container) {
var text = "";
if (!container.querySelector("span")) {
text += container.textContent;
}
for (var el in container.childNodes) {
if (!container.childNodes.hasOwnProperty(el)) continue;
var element = container.childNodes[el];
if (element.nodeName == 'SPAN' && element.style.display != 'none') {
text += element.textContent;
}
}
return text;
}
function clearText(text, lang) {
var en = ["a", "c", "e", "o", "p", "u", "x", "y", "A", "C", "E", "O", "P", "U", "X", "Y"];
var ru = ["а", "с", "е", "о", "р", "и", "х", "у", "А", "С", "Е", "О", "Р", "И", "Х", "У"];
switch (lang) {
case 'ru':
for (var i = 0; i < en.length; ++i) {
text = text.replace(new RegExp("(" + en[i] + ")", "gi"), ru[i]);
}
break;
case 'en':
for (var i = 0; i < ru.length; ++i) {
text = text.replace(ru[i], en[i]);
}
break;
}
console.log(text);
return text;
}
var lang = settings.lang;
var text = getText(cur);
text += getText(after);
text = clearText(text, lang);
console.log(text);
var words = text.split(' ');
var input = document.getElementById('inputtext');
var speed = ((text.length / words.length) / (settings.speed_limit / 60)) * 1000;
console.log(speed);
var counter = 0;
input.value = words[3] + " ";
input.onkeyup();
var timer = setInterval(function() {
console.log(words[counter] + " ");
input.value = words[counter++] + " ";
input.onkeyup();
}, speed);