-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
53 lines (46 loc) · 1.41 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Microsecond resolution clock</title>
<style>
body {
font-family: monospace;
font-size: 6vw;
font-weight: 700;
text-align: center;
text-shadow: 0px 0px 3px white;
}
</style>
</head>
<body>
<div id="clock"></div>
<script>
const parseIntDefault = (str, def) => {
const num = parseInt(str, 10);
if (isFinite(num)) {
return num;
}
return def;
};
const throttle = Math.max(0, parseIntDefault(window.location.search.slice(1), 0));
const div = document.getElementById('clock');
const text = document.createTextNode('');
div.appendChild(text);
const zeroPad = (value, length = 2) => {
return String(value).padStart(length, '0');
};
const displayTime = (frame) => {
if (frame < throttle) {
return window.requestAnimationFrame(() => displayTime(frame + 1));
}
const microtime = performance.timing.navigationStart + performance.now();
const now = new Date(microtime);
const microseconds = Math.trunc((microtime - now.getTime()) * 100);
text.nodeValue = `${now.getUTCFullYear()}-${zeroPad(now.getUTCMonth() + 1)}-${zeroPad(now.getUTCDate())} ${zeroPad(now.getUTCHours())}:${zeroPad(now.getUTCMinutes())}:${zeroPad(now.getUTCSeconds())}.${zeroPad(now.getUTCMilliseconds(), 3)}.${zeroPad(microseconds)}`;
return window.requestAnimationFrame(() => displayTime(0));
};
displayTime(0);
</script>
</body>
</html>