-
Notifications
You must be signed in to change notification settings - Fork 1
/
stats.html
94 lines (85 loc) · 3.58 KB
/
stats.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="robots" content="noindex,nofollow"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
crossorigin="anonymous">
<title>Aurora Download Stats</title>
</head>
<body class="container" data-bs-theme="dark">
<button id="refreshBtn" class="btn btn-primary">Refresh</button>
<h1>Latest Release</h1>
<h2 id="latestRelease">v---</h2>
<div class="text-secondary" id="latestReleaseTime">0000-00-00T00:00:00Z</div>
<div>
Installer downloads:
<div id="latestInstallerDiv">*</div>
Zip downloads:
<div id="latestZipDiv">*</div>
</div>
<h1>Last 15 Releases</h1>
<div id="lastFiveReleasesContainer"></div>
<script async>
async function fetchLatestRelease() {
let res = await fetch("https://api.github.com/repos/Aurora-RGB/Aurora/releases/latest");
if (res.status >= 400) {
return;
}
let githubResponse = await res.json();
document.getElementById("latestRelease").innerHTML = githubResponse.name;
document.getElementById("latestReleaseTime").innerHTML = githubResponse.created_at;
githubResponse.assets.forEach(asset => {
if (asset.name.startsWith("Aurora-setup-v")) {
document.getElementById("latestInstallerDiv").innerHTML = asset.download_count
} else if (asset.name.startsWith("Aurora-v")) {
document.getElementById("latestZipDiv").innerHTML = asset.download_count
}
})
}
async function fetchData() {
let res = await fetch("https://api.github.com/repos/Aurora-RGB/Aurora/releases?per_page=15")
if (res.status >= 400) {
return;
}
let githubResponse = await res.json();
const last5span = document.getElementById("lastFiveReleasesContainer")
last5span.innerHTML = ""
githubResponse.forEach(release => {
const releaseName = release.name;
const time = release.created_at;
const elements = release.assets.map(asset => {
if (asset.name.startsWith("Aurora-setup-v")) {
return "Installer downloads: <div>" + asset.download_count + "</div>"
} else if (asset.name.startsWith("Aurora-v")) {
return "Zip downloads: <div>" + asset.download_count + "</div>"
}
}).filter(nodeText => nodeText)
.map(nodeText => {
let element = document.createElement("div")
element.innerHTML = nodeText
return element;
})
const header = document.createElement("h2")
header.innerHTML = releaseName + (release.prerelease ? " (Prerelease)" : "")
last5span.appendChild(header)
const timeDiv = document.createElement("div")
timeDiv.classList.add("text-secondary")
timeDiv.innerHTML = time
last5span.appendChild(timeDiv)
elements.forEach(e => last5span.appendChild(e))
})
}
fetchLatestRelease();
fetchData()
let refreshBtn = document.getElementById("refreshBtn");
refreshBtn.onclick = async () => {
refreshBtn.toggleAttribute("disabled")
await Promise.all([fetchLatestRelease(), fetchData()])
refreshBtn.removeAttribute("disabled")
}
</script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>