-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
98 lines (91 loc) · 2.29 KB
/
script.js
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
let utc = false;
let date = false;
let stopwatch = false;
function displayTime() {
let now = new Date();
let h, m, s;
if (utc) {
h = now.getUTCHours();
m = now.getUTCMinutes();
s = now.getUTCSeconds();
} else {
h = now.getHours();
m = now.getMinutes();
s = now.getSeconds();
}
printTime(h, m, s);
setTimeout(displayTime, 500);
}
function displayDate() {
let now = new Date();
let y, m, d;
if (utc) {
y = now.getUTCFullYear();
m = now.getUTCMonth() + 1;
d = now.getUTCDate();
} else {
y = now.getFullYear();
m = now.getMonth() + 1;
d = now.getDate();
}
m = formatNumber(m);
d = formatNumber(d);
document.getElementById('date').innerHTML = y + "-" + m + "-" + d;
setTimeout(displayDate, 500);
}
function displayStopwatch() {
let diff = (new Date() - stopwatch) / 1000;
let h, m, s;
h = Math.floor((diff / 3600) % 24) ;
m = Math.floor((diff / 60) % 60);
s = Math.floor(diff % 60);
printTime(h, m, s);
setTimeout(displayStopwatch, 500);
}
function printTime(h, m, s) {
h = formatNumber(h);
m = formatNumber(m);
s = formatNumber(s);
document.getElementById('time').innerHTML = h + ":" + m + ":" + s;
}
function formatNumber(i) {
if (i < 10) {
i = "0" + i;
}
return i;
}
function showDate() {
document.getElementById('flex-time').classList.add('flex-time');
document.getElementById('flex-date').style.display = 'flex';
}
window.onload = function () {
if (window.location.href.includes('stopwatch=true')) {
stopwatch = new Date();
}
if (window.location.href.includes('utc=true')) {
utc = true;
}
if (window.location.href.includes('date=true')) {
date = true;
}
if (stopwatch) {
document.title = 'stopwatch';
} else if (utc && date) {
document.title = 'utcdatetime';
} else if (utc && !date) {
document.title = 'utctime';
} else if (!utc && date) {
document.title = 'localdatetime';
} else {
document.title = 'localtime';
}
if (stopwatch) {
displayStopwatch();
} else {
displayTime();
if (date) {
showDate();
displayDate();
}
}
};