forked from sollenne/bootstrap-stopwatch
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
214 lines (196 loc) · 7.27 KB
/
index.html
File metadata and controls
214 lines (196 loc) · 7.27 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
<!doctype html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html" charset="utf-8" />
<meta name="description" content>
<meta name="keywords" content>
<meta name="author" content>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>Stopwatch</title>
<link href="css/bootstrap.min.css" rel="stylesheet"/>
<link href="css/bootstrap-responsive.min.css" rel="stylesheet"/>
<link href="css/font-awesome.css" rel="stylesheet">
<link href="css/custom.css" rel="stylesheet"/>
</head>
<body>
<header>
<div class="container">
<div class="center">
<div id="stopWatch">
<div class="row">
<div class="span12">
<div id="time" class="pointable" style="font-weight:bold; width:100%; display:block;">0:00:00</div>
</div>
</div>
</div>
</div>
</div>
<div id=frame_form>
<h3>Gyorstalpaló</h3>
<p>Ez egy stopper, ami kijelzi mennyi idő van még hátra a versenyből. Ha az órára rákattintasz, akkor elindul vagy megáll. Ha szeretnéd módosítani az időt, akkor "alt+m"-mel 1 percet levonsz, "alt+shift+m"-el 1 percet hozzáadsz (hasonlóan az "alt+s", "alt+shift+s", "alt+h", "alt+shift+h").
Ha csak időt szeretnél kijelezni, csak kattints a submit gombra és minden eltűnik. </p>
<p>Ha a pontozótáblát is szeretnéd látni, akkor a pontozótáblázat linkét írd be, majd kattints a submit gombra. (pro tip: kapcsold ki a táblázatban a képlet megjelenítését, a cellák közötti vonalakat és válts teljes képernyőre. Ezeket mind megtalálod a "Nézet/View" menüpont alatt)</p>
<h3>További gyorsbillentyűk:</h3>
<p>"alt+c" és "alt+C": dark illetve white mode<br>
"alt+v" és "alt+V": kicsinyíted illetve növeled a timer alatti térközt.<br>
"alt+b" és "alt+B": kicsinyíted illetve növeled a timer méretét</p><br>
<label for="fname">A beágyazandó táblázat megfelelő munkalapjának a linkje:</label>
<input type="text" id="frame_input" name="frame_input"><br>
<label for="fname">Hány perccel a verseny vége előtt tűnjön el a beágyazás?</label>
<input type="number" value=10 id="min_fade" name="min_fade"><br>
<button type="button" onclick="submit()">Submit</button>
</div>
<div id="hint" style="display: none;">
<iframe id="result" style="display: block;" width=100% height=1000px frameborder="0" src=""&widget=true></iframe>
</div>
</header>
<!-- scripts -->
<!--
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
-->
<script type="text/javascript" src="js/jquery.1.9.1.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/custom.js"></script>
<script src="js/jquery.fittext.js"></script>
<script type="text/javascript">
function submit(){
min_fade = parseInt(document.getElementById("min_fade").value)
document.getElementById("frame_form").style.display = "None"
let link = document.getElementById("frame_input").value
if (link !== ""){
document.getElementById("result").src = document.getElementById("frame_input").value
document.getElementById("hint").style.display = "block"
}
}
$(document).ready(function(){
document.getElementById("time").style.fontSize = "10rem"
document.getElementsByClassName("center")[0].style.marginBottom = "0px"
let startTime;
let timeout;
let pauseTime = 0;
let paused = false;
let init = true
let count = 0;
let countdown = 10800
let mils = countdown*1000
let moment_of_paused = 0
let min_fade = 10
displayMil(countdown*1000)
$('#time').on('click', function(){
if (init == true){
init = false
startTime = new Date();
clock();
} else {
if(paused == false){
paused = true;
clearTimeout(timeout);
moment_of_paused = new Date();
$('#time').addClass('paused');
}else{
paused = false;
pauseTime = pauseTime + (new Date() - moment_of_paused);
clock();
}
}
});
// Add event listener on keydown
document.addEventListener('keydown', (event) => {
var name = event.key;
var code = event.code;
if (event.altKey) {
if (name === 'c'){
document.body.style.color = "rgb(255, 255, 255)"
document.body.style.backgroundColor = "rgb(19, 19, 19)"
}
if (name === 'C'){
document.body.style.backgroundColor = "rgb(255, 255, 255)"
document.body.style.color = "rgb(19, 19, 19)"
}
if (name === 'b'){
newFontSize = Math.max(0,parseInt(document.getElementById("time").style.fontSize)-1)
document.getElementById("time").style.fontSize = newFontSize+"rem"
}
if (name === 'B'){
document.getElementById("time").style.fontSize = (parseInt(document.getElementById("time").style.fontSize)+1)+"rem"
}
if (name === 'v'){
newMarginBottom = Math.max(0,(parseInt(document.getElementsByClassName("center")[0].style.marginBottom)-1))
document.getElementsByClassName("center")[0].style.marginBottom = newMarginBottom+"px"
}
if (name === 'V'){
newMarginBottom = parseInt(document.getElementsByClassName("center")[0].style.marginBottom)+1
document.getElementsByClassName("center")[0].style.marginBottom = newMarginBottom+"px"
}
if (name === 'h'){
addSecondsToTimer(-3600)
}
if (name === 'H'){
addSecondsToTimer(3600)
}
if (name === 'm'){
addSecondsToTimer(-60)
}
if (name === 'M'){
addSecondsToTimer(60)
}
if (name === 's'){
addSecondsToTimer(-1)
}
if (name === 'S'){
addSecondsToTimer(1)
}
}
}, false);
function addSecondsToTimer(sec) {
countdown = Math.max(0,countdown+sec)
console.log(mils, sec)
mils = Math.max(0, mils+sec*1000)
displayMil(mils)
}
function clock() {
$('#time').removeClass('paused');
var curTime = new Date();
mils = -(curTime - startTime) + pauseTime + countdown*1000;
mils = Math.max(mils,0) // prevent negative time
displayMil(mils)
timeout = setTimeout(clock,20);
}
function displayMil(mils){
let time = milToTime(mils);
formatTime(time);
if(time.h === 0 && time.m<min_fade){ // TODO: consider hours
document.getElementById("result").display = "None"
var hint = document.getElementById('hint');
hint.classList.add('h-hide');
}
let outStr = time.h +':'+time.m +':'+time.s;
document.getElementById('time').innerHTML=outStr;
}
function formatTime(time){
for(var i in time){
if(i == "mils"){
if(time[i] < 1){
time[i] = "000";
}else if(time[i] < 10){
time[i] = "00" + time[i];
}else if(time[i] < 100){
time[i] = "0" + time[i];
}
}else if(i != "h" && time[i] < 10){
time[i] = "0" + time[i];
}
}
return time;
}
function milToTime(mil){
mi = mil % 1000;
seconds = parseInt(mil / 1000) % 60;
minutes = parseInt(mil / 1000 / 60) % 60;
hours = parseInt( mil / 1000 / 3600);
return {s: seconds, m: minutes, h:hours, mils:mi};
}
});
</script>
</body>
</html>