-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjs.js
More file actions
243 lines (216 loc) · 6.02 KB
/
js.js
File metadata and controls
243 lines (216 loc) · 6.02 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
// Simple example of using private variables
//
// To start the stopwatch:
// obj.start();
//
// To get the duration in milliseconds without pausing / resuming:
// var x = obj.time();
//
// To pause the stopwatch:
// var x = obj.stop(); // Result is duration in milliseconds
//
// To resume a paused stopwatch
// var x = obj.start(); // Result is duration in milliseconds
//
// To reset a paused stopwatch
// obj.stop();
//
var clsStopwatch = function() {
// Private vars
var startAt = 0; // Time of last start / resume. (0 if not running)
var lapTime = 0; // Time on the clock when last stopped in milliseconds
var now = function() {
return (new Date()).getTime();
};
// Public methods
// Start or resume
this.start = function() {
startAt = startAt ? startAt : now();
};
// Stop or pause
this.stop = function() {
// If running, update elapsed time otherwise keep it
lapTime = startAt ? lapTime + now() - startAt : lapTime;
startAt = 0; // Paused
};
// Reset
this.reset = function() {
lapTime = startAt = 0;
};
// Duration
this.time = function() {
return lapTime + (startAt ? now() - startAt : 0);
};
};
var x = new clsStopwatch();
var $time;
var clocktimer;
function pad(num, size) {
var s = "0000" + num;
return s.substr(s.length - size);
}
function formatTime(time) {
var h = m = s = ms = 0;
var newTime = '';
h = Math.floor( time / (60 * 60 * 1000) );
time = time % (60 * 60 * 1000);
m = Math.floor( time / (60 * 1000) );
time = time % (60 * 1000);
s = Math.floor( time / 1000 );
ms = time % 1000;
newTime = pad(h, 2) + ':' + pad(m, 2) + ':' + pad(s, 2) + ':' + pad(ms, 3);
return newTime;
}
function show() {
$time = document.getElementById('time');
update();
}
function update() {
$time.innerHTML = formatTime(x.time());
}
function start() {
clocktimer = setInterval("update()", 1);
x.start();
}
function stop() {
x.stop();
clearInterval(clocktimer);
}
var tS = 0; //0 - Não Travado
//1 - Travado
function toggleStop(){
if(tS === 0){
x.stop();
tS = 1;
document.getElementById("btn").value = "Travado";
document.getElementById("btn").blur();
}
else{
x.start();
tS = 0;
document.getElementById("btn").value = "Travar";
document.getElementById("btn").blur();
}
}
function reset() {
if(state === 0){
}
else if(state === 1) {
stop();
x.reset();
update();
state = 0;
}
}
var state = 0; //0 = Cronometro parado;
//1 = rodando;
//2 = parado, mostrando resultado;
function resetSpace() {
if((event.keyCode === 32 || event.which === 32) && tS === 0){
if(state === 0){
stop();
x.reset();
update();
}
else if(state === 1){
x.stop();
clearInterval(clocktimer);
state = 2;
}
else if (state === 2){
stop();
x.reset();
update();
state = 0;
}
}
}
function startSpace() {
if((event.keyCode === 32 || event.which === 32) && tS === 0){
if(state === 0){
clocktimer = setInterval("update()", 1);
x.start();
state = 1;
}
}
}
var showPopUpRight = false;
function helpPage(){
if(!(event.keyCode === 32 || event.which === 32)){
document.getElementById("helpBtn").blur();
if(!showPopUpRight){
document.getElementById("popUp").style.right = "0";
document.getElementById("conteudo").style.transition = "0.4s ease";
document.getElementById("conteudo").style.filter = "blur(2px)";
showPopUpRight = true;
}else{
document.getElementById("popUp").style.right = "-50%";
document.getElementById("conteudo").style.transition = "0.4s ease";
document.getElementById("conteudo").style.filter = "blur(0px)";
document.getElementById("helpBtn").blur();
document.getElementById("xRight").blur();
showPopUpRight = false;
}
}
}
var showPopUpLeft = false;
function savePage(){
if(!(event.keyCode === 32 || event.which === 32)){
document.getElementById("saveBtnPage").blur();
if(!showPopUpLeft){
document.getElementById("popUpLeft").style.left = "0";
document.getElementById("conteudo").style.transition = "0.4s ease";
document.getElementById("conteudo").style.filter = "blur(2px)";
showPopUpLeft = true;
}else{
document.getElementById("popUpLeft").style.left = "-50%";
document.getElementById("conteudo").style.transition = "0.4s ease";
document.getElementById("conteudo").style.filter = "blur(0px)";
document.getElementById("saveBtnPage").blur();
document.getElementById("xLeft").blur();
document.getElementById("downBtn").blur();
showPopUpLeft = false;
}
}
}
var typeOf = "Não Identificado";
var mS = false;
function showMenu(){
if(!mS){
mS = true;
document.getElementById("dropDown").style.visibility = "visible";
document.getElementById("dropDown").style.opacity = "1";
document.getElementById("dropDown").style.top = "-10px";
}
else{
mS = false;
document.getElementById("dropDown").style.visibility = "hidden";
document.getElementById("dropDown").style.opacity = "0";
document.getElementById("dropDown").style.top = "-105px";
}
}
function typeOfFunct(typeOfThis){
typeOf = typeOfThis;
document.getElementById("spanType").textContent = typeOf;
console.log(typeOf);
showMenu();
}
var innerCounter = 1;
function saveResult(timeOf,typeOfThis){
if(!(showPopUpLeft||showPopUpRight)){
var div = document.createElement("p");
div.innerHTML =innerCounter + ". Tempo: " + formatTime(x.time()) + " com " + typeOf + "\n";
document.getElementById("saveThisText").appendChild(div);
innerCounter++;
}
}
function download(filename) {
var resultsOf = document.getElementById("saveThisText").textContent;
var element = document.createElement('a');
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(resultsOf));
element.setAttribute('download', filename);
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}