forked from newbfg/shri-performance
-
Notifications
You must be signed in to change notification settings - Fork 0
/
clock.html
148 lines (123 loc) · 4.81 KB
/
clock.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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<link href="https://fonts.googleapis.com/css2?family=Roboto+Condensed&display=swap" rel="stylesheet">
<title>Theme Clock</title>
</head>
<body>
<div class="clocks">
<div class="moscow">
<h2>Moscow</h2>
<div class="clock">
<div class="clock-face">
<div class="clock-hand hour-hand"></div>
<div class="clock-hand minute-hand"></div>
<div class="clock-hand second-hand"></div>
<div class="pin"></div>
</div>
</div>
<div class="info">
<div class="time-day"> </div>
<div class="date"> </div>
</div>
</div>
<div class="london">
<h2>London</h2>
<div class="clock">
<div class="clock-face">
<div class="clock-hand hour-hand"></div>
<div class="clock-hand minute-hand"></div>
<div class="clock-hand second-hand"></div>
<div class="pin"></div>
</div>
</div>
<div class="info">
<div class="time-day"> </div>
<div class="date"> </div>
</div>
</div>
<div class="new-york">
<h2>New York</h2>
<div class="clock">
<div class="clock-face">
<div class="clock-hand hour-hand"></div>
<div class="clock-hand minute-hand"></div>
<div class="clock-hand second-hand"></div>
<div class="pin"></div>
</div>
</div>
<div class="info">
<div class="time-day"> </div>
<div class="date"> </div>
</div>
</div>
</div>
<button class="switch">switch theme</button>
<script src="script.js"></script>
<script src="send.js"></script>
<script>
const counter = new Counter();
counter.init('9b2714be-bf3c-4a10-96bb-1ddaf1f09399', String(Math.random()).substr(2, 12), 'clock');
counter.setAdditionalParams({
platform: navigator.userAgentData.mobile ? 'touch' : 'desktop',
browser: navigator.userAgent.indexOf('Chrome') !== 1 ? 'chrome' : 'other',
experiment: parseInt(Math.random() * 10) % 3 ? 'experiment #1' : 'experiment #2',
});
counter.send('connect', performance.timing.connectEnd - performance.timing.connectStart);
counter.send('ttfb', performance.timing.responseEnd - performance.timing.requestStart);
new PerformanceObserver((entryList) => {
for (const entry of entryList.getEntriesByName('first-contentful-paint')) {
counter.send('fcp', entry.startTime);
}
}).observe({type: 'paint', buffered: true});
new PerformanceObserver((entryList) => {
for (const entry of entryList.getEntries()) {
counter.send('lcp', entry.startTime);
}
}).observe({type: 'largest-contentful-paint', buffered: true});
new PerformanceObserver((entryList) => {
for (const entry of entryList.getEntries()) {
const delay = entry.processingStart - entry.startTime;
counter.send('fid', delay);
}
}).observe({type: 'first-input', buffered: true});
let clsValue = 0;
let clsEntries = [];
let sessionValue = 0;
let sessionEntries = [];
new PerformanceObserver((entryList) => {
for (const entry of entryList.getEntries()) {
// Only count layout shifts without recent user input.
if (!entry.hadRecentInput) {
const firstSessionEntry = sessionEntries[0];
const lastSessionEntry = sessionEntries[sessionEntries.length - 1];
// If the entry occurred less than 1 second after the previous entry and
// less than 5 seconds after the first entry in the session, include the
// entry in the current session. Otherwise, start a new session.
if (sessionValue &&
entry.startTime - lastSessionEntry.startTime < 1000 &&
entry.startTime - firstSessionEntry.startTime < 5000) {
sessionValue += entry.value;
sessionEntries.push(entry);
} else {
sessionValue = entry.value;
sessionEntries = [entry];
}
// If the current session value is larger than the current CLS value,
// update CLS and the entries contributing to it.
if (sessionValue > clsValue) {
clsValue = sessionValue;
clsEntries = sessionEntries;
// Log the updated value (and its entries) to the console.
counter.send('cls', clsValue);
}
}
}
}).observe({type: 'layout-shift', buffered: true});
</script>
</body>
</html>