-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstopwatch.php
More file actions
281 lines (240 loc) · 6.13 KB
/
stopwatch.php
File metadata and controls
281 lines (240 loc) · 6.13 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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
<!DOCTYPE html>
<html>
<head>
<script type='text/javascript' src='jquery-1.7.1.js'></script>
<script type="text/javascript">
document.onload=function(){
sessionStorage.clear();
localStorage.clear();
};
var flagclock = 0;
var flagstop = 0;
var stoptime = 0;
var splitcounter = 0;
var currenttime;
var splitdate = '';
var output;
var clock; function startstop()
{
var startstop = document.getElementById('startstopbutton');
var startdate = new Date();
var starttime = startdate.getTime();
if(flagclock==0)
{
startstop.value = 'Stop';
flagclock = 1;
counter(starttime);
// output.value = ''; // Needed only to clear the output field. Usefull when there are unnecessary tags left in it.
}
else
{
startstop.value = 'Start';
flagclock = 0;
flagstop = 1;
splitdate = '';
}
}
function counter(starttime)
{
output = document.getElementById('output');
clock = document.getElementById('clock');
currenttime = new Date();
var timediff = currenttime.getTime() - starttime;
if(flagstop == 1)
{
timediff = timediff + stoptime
}
if(flagclock == 1)
{
clock.value = formattime(timediff,'');
refresh = setTimeout('counter(' + starttime + ');',10);
}
else
{
window.clearTimeout(refresh);
stoptime = timediff;
}
}
function formattime(rawtime,roundtype)
{
if(roundtype == 'round')
{
var ds = Math.round(rawtime/100) + '';
}
else
{
var ds = Math.floor(rawtime/100) + '';
}
var sec = Math.floor(rawtime/1000);
var min = Math.floor(rawtime/60000);
ds = ds.charAt(ds.length - 1);
if(min >= 60)
{
startstop();
}
sec = sec - 60 * min + '';
if(sec.charAt(sec.length - 2) != '')
{
sec = sec.charAt(sec.length - 2) + sec.charAt(sec.length - 1);
}
else
{
sec = 0 + sec.charAt(sec.length - 1);
}
min = min + '';
if(min.charAt(min.length - 2) != '')
{
min = min.charAt(min.length - 2)+min.charAt(min.length - 1);
}
else
{
min = 0 + min.charAt(min.length - 1);
}
return min + ':' + sec;
}
function resetclock()
{
flagstop = 0;
stoptime = 0;
splitdate = '';
window.clearTimeout(refresh);
output.value = '';
splitcounter = 0;
if(flagclock == 1)
{
var resetdate = new Date();
var resettime = resetdate.getTime();
counter(resettime);
sessionStorage.clear();
localStorage.clear();
}
else
{
clock.value = "00:00";
}
}
function splittime()
{
if(flagclock == 1)
{
if(splitdate != '')
{
var splitold = splitdate.split(':');
var splitnow = clock.value.split(':');
var numbers = new Array();
var i = 0
for(i;i<splitold.length;i++)
{
numbers[i] = new Array();
numbers[i][0] = splitold[i]*1;
numbers[i][1] = splitnow[i]*1;
}
if(numbers[1][1] < numbers[1][0])
{
numbers[1][1] += 60;
numbers[0][1] -= 1;
}
var mzeros = (numbers[0][1] - numbers[0][0]) < 10?'0':'';
var szeros = (numbers[1][1] - numbers[1][0]) < 10?'0':'';
//output.value += '\n\t+' + mzeros + (numbers[0][1] - numbers[0][0]) + ':' + szeros + (numbers[1][1] - numbers[1][0]) + ':' + (numbers[2][1] - numbers[2][0]) + 'aaaaa\n';
}
splitdate = clock.value;
output.value += clock.value + " \n";
}
}
</script>
<style type="text/css">
*
{
margin: 0;
padding: 0;
}
textarea
{
width: 100%;
font: normal 12px verdana;
height: 75px;
}
</style>
</head>
<body>
<input id="clock" value="00:00:0" style="text-align: center;" readonly type="text"><br>
<input id="startstopbutton" value="Start" onClick="startstop();storeInArray();" type="button">
<br>
<input id="splitbutton" value="Split time" onClick="splittime();" type="button">
<br>
<input id="resetbutton" value="Reset" onClick="resetclock();" type="button">
<br>
<form action="./" method="post">
<textarea id="output" style="height:150px;"></textarea>
</form>
<script type="text/javascript">
function storeInArray() { // places timetags into array
var lines = $('#output').val().split(/\n/);
var texts = [];
for (var i=0; i < lines.length; i++) {
// only push this line if it contains a non whitespace character.
if (/\S/.test(lines[i])) {
texts.push($.trim(lines[i]));
}
}
var a = texts;
if (typeof(Storage) != "undefined"){
// store all timetag array values into web storage
sessionStorage.clear();
localStorage.clear();
for (var arrayNumber = 0; arrayNumber < a.length; arrayNumber++) {
localStorage.setItem(arrayNumber, a[arrayNumber]);
document.getElementById("result").innerHTML+= a[arrayNumber] + '\n';
}
}
else{
document.getElementById("result").innerHTML="Sorry, your browser does not support Web Storage...";
}
}
function getStorageValues(){
if (typeof(Storage) != "undefined") // If browser supports web storage
{
var myform=document.createElement("FORM"); // Create form in html
myform.method = "post"; //with these attributes
myform.action = "timetags.php";
myform.name = "myform";
document.body.appendChild(myform); // Attach form into body
for (var i = 0; i < localStorage.length; i++) { // For each of the local storage value (timetag)
var myinput=document.createElement("INPUT"); //create an input field with name "tag*"
myinput.setAttribute('value', localStorage.getItem(i));
myinput.name = "tag" + i;
//myinput.type = "hidden"; // Hide the fields so that user won't bother seeing them.
document.myform.appendChild(myinput); // Attach input fields into form
}
var button=document.createElement("INPUT"); // Create button
button.type = "submit"; //with these attributes
button.name = "submit";
button.value = "Save";
document.myform.appendChild(button); // Attach button into form
}
else // If browser does not support web storage
{
document.getElementById("result").innerHTML="Sorry, your browser does not support Web Storage...";
}
}
function clearstorages() { // Clear the web storages
sessionStorage.clear();
localStorage.clear();
output.value = '';
document.getElementById("result").innerHTML = '';
function remove(id)
{
return (elem=document.getElementById(id)).parentNode.removeChild(elem);
}
myform.remove();
}
</script>
<p><button id="buttontest" onclick="getStorageValues()" type="button">Get storage values</button></p>
<p><button id="clearstorage" onclick="clearstorages()" type="button">Clear storages</button></p>
<div id="result" style="height:30px;"></div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.0/jquery.min.js"></script>
<script src="jquery.generateFile.js"></script>
<script src="script.js"></script>
</body>
</html>