This repository has been archived by the owner on Sep 29, 2022. It is now read-only.
forked from mrmookie/obsninja
-
Notifications
You must be signed in to change notification settings - Fork 0
/
timer.html
98 lines (87 loc) · 3.04 KB
/
timer.html
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
<!DOCTYPE HTML>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@100;300;400;500;700;900&display=swap" rel="stylesheet">
<style>
html {
width:100%;
height:100%;
}
body {
width:100%;
height:100%;
}
p {
text-align: center;
font-size: 60px;
margin-top: 0px;
font-family: 'Roboto', sans-serif;
background-color: rgba(255,255,255,0)
}
</style>
</head>
<body onmousedown="buttonPress(event)" oncontextmenu="event.preventDefault();" onload="start();">
<p id="demo"></p>
<script>
// Set the date we're counting down to
var countDownDate = null;
var x = null;
var isReset = false;
var isPaused = true;
document.getElementById("demo").innerHTML = "00:00:00<small><small><small><small>.000</small></small></small></small>"; //set timer to 00:00:00
function buttonPress(event) {
//alert("You pressed button: " + event.button);
if (isPaused) { //if paused
if (event.button==0) { //left click
isPaused = false; //unpause current timer
}
if (event.button==2) { //right click
if (isReset) { //is reset
isReset = false;
isPaused = false;
start(); //run timer
} else { //is running
if(x) {clearInterval(x);}
isReset = true;
document.getElementById("demo").innerHTML = "00:00:00<small><small><small><small>.000</small></small></small></small>"; //set timer to 00:00:00
}
}
} else { //if isPaused = false
if (event.button==0) { //left click
isPaused = true; //pause current timer
}
if (event.button==2) { //right click
if (isReset) { //is reset
isReset = false;
start(); //run timer
} else { //is running
if(x) {clearInterval(x);}
isReset = true;
document.getElementById("demo").innerHTML = "00:00:00<small><small><small><small>.000</small></small></small></small>"; //set timer to 00:00:00
}
}
}
}
// Update the count down every 1 second
function start(){
countDownDate = new Date().getTime();
x = setInterval(function() {
if (!isPaused) {
// Get today's date and time
var now = new Date().getTime();
// Find the distance between now and the count down date
var distance = now - countDownDate ;
// Time calculations for days, hours, minutes and seconds
var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((distance % (1000 * 60)) / 1000);
var milliseconds = Math.floor((distance % (1000)) );
// Output the result in an element with id="demo"
document.getElementById("demo").innerHTML = ("00" + hours).slice (-2) + ":" + ("00" + minutes).slice (-2) + ":" + ("00" + seconds).slice (-2) + "<small><small><small><small>." + ("000" + milliseconds).slice (-3)+"</small></small></small></small>";
}
}, 10);
}
</script>
</body>
</html>