-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
141 lines (119 loc) · 2.75 KB
/
Copy pathscript.js
File metadata and controls
141 lines (119 loc) · 2.75 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
var currentPoz = 0;
var textArray = "ceva";
var flag = true;
var timeSleep = 3;
var timpPauza = 0;
// var flagPlay = false;
// butoane
var buttonPlay = "#btn_play";
var buttonStop = "#btn_stop";
var buttonPause = "#btn_pause";
// input
var inputTextbox = "#i_text";
var inputFrecventa = "#i_wpm";
// output
var outputText = "#o_display";
var culoareOutput1 = "black";
var culoareOutput2 = "red";
var culoareOutput3 = "yellow";
var culoareOutput4 = "blue";
console.log($(inputTextbox).text());
function wordsPerMinute(frecventa) {
return (60 / frecventa) * 1000 ;
}
function splitText(inputText) {
textArray = inputText.split(" ");
}
function pauseRead() {
flag = false;
delayTrue();
}
function changeStateToTrue() {
flag = true;
}
function delayTrue() {
setTimeout(function(){
changeStateToTrue()
}, 1000);
}
function stopRead() {
// flagPlay = false;
flag = false;
currentPoz = 0;
clearText();
delayTrue();
setTimeout(function(){
clearText();
}, 900)
}
function clearText() {
$(inputTextbox).val("");
$(outputText).html(" ");
}
function afiseazaCuvant(cuvant) {
console.log(cuvant);
$(outputText).css("color", culoareOutput1).text(cuvant);
}
function startRead () {
if (flag == false || currentPoz >= textArray.length){
return;
}
setTimeout(function(){
afiseazaCuvant(textArray[currentPoz])
currentPoz++;
startRead();
}, wordsPerMinute($(inputFrecventa).val()) );
}
function writeWithColor(culoare, text) {
$(outputText).css("color", culoare).text(text);
}
function writeCountdown(index) {
if(index == 3)
writeWithColor(culoareOutput4, index);
else if(index == 2)
writeWithColor(culoareOutput3, index);
else if(index == 1)
writeWithColor(culoareOutput2, index);
}
function timer(index) {
if(index == 0 || currentPoz > 0){
return;
}
setTimeout(function(){
console.log(index);
writeCountdown(index);
timer(index - 1);
}, 1000);
}
function setColor(culoare) {
$(outputText).css("color", culoare).text(" ");
}
function selectTimp() {
if(currentPoz > 0){
timpPauza = 0
}else{
timpPauza = 1000 * timeSleep + 1000;
}
}
$(document).ready(function() {
$(buttonPlay).click(function()
{
// flagPlay = true;
selectTimp();
timer(timeSleep);
setTimeout(function(){
startRead(splitText($(inputTextbox).val()));
}, timpPauza)
}
);
$(buttonStop).click( function()
{
stopRead();
}
);
$(buttonPause).click( function()
{
pauseRead();
}
);
});