-
Notifications
You must be signed in to change notification settings - Fork 12
/
TestPage.html
80 lines (68 loc) · 2.09 KB
/
TestPage.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
<html>
<head>
<title>Reload Test</title>
<style>
body {
font-family: sans-serif;
margin: 1.5rem;
}
table {
border-collapse: collapse;
}
td, th {
border: 1px solid #999;
padding: 0.5rem 0.75rem;
text-align: left;
}
td:nth-child(2), th:nth-child(2) {
text-align: right;
}
td {
font-family: monospace;
font-size: 1.2rem;
}
tr:nth-child(2) td {
color: green;
}
</style>
</head>
<body>
<h1>Reload Test</h1>
<p><button id="clear">Clear History</button></p>
<table id="history">
<tr>
<th>Reload Time</th>
<th>Difference</th>
</tr>
</table>
<script type="text/javascript">
var localStorage = window.localStorage;
var rawHistory = localStorage.getItem('history') ?? "[]";
var reloadHistory = JSON.parse(rawHistory)
var reloadDate = new Date();
var table = document.getElementById('history');
var tableData = []
reloadHistory.push(reloadDate)
localStorage.setItem('history', JSON.stringify(reloadHistory));
reloadHistory.forEach((reloadDate, idx) => {
var rowData = {'date': new Date(reloadDate), 'diff': 0}
if (idx > 0) {
prevDate = new Date(reloadHistory[idx - 1]);
rowData['diff'] = rowData['date'] - prevDate;
}
tableData.unshift(rowData)
})
tableData.forEach((rowData, idx) => {
var row = table.insertRow();
var dateCell = row.insertCell();
var diffCell = row.insertCell();
dateCell.innerHTML = rowData['date'];
diffCell.innerHTML = rowData['diff'];
})
document.getElementById('clear').onclick = () => {
localStorage.removeItem('history');
location.reload()
}
</script>
</body>
</html>