-
Notifications
You must be signed in to change notification settings - Fork 2
/
script.js
38 lines (29 loc) · 1.11 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
////////////////////
// URL PARAMETERS //
////////////////////
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
const twitchUsername = urlParams.get("username") || '';
///////////////
// FUNCTIONS //
///////////////
async function UpdateMetrics() {
document.getElementById("subCountLabel").innerHTML = await GetMetric("https://decapi.me/twitch/subcount");
document.getElementById("followerCountLabel").innerHTML = await GetMetric("https://decapi.me/twitch/followcount");
document.getElementById("viewCountLabel").innerHTML = await GetViewCount();
setTimeout(UpdateMetrics, 15000);
}
UpdateMetrics();
async function GetMetric(url) {
const response = await fetch(`${url}/${twitchUsername}`);
const metric = await response.text();
if (metric.includes("decapi.me"))
return "-";
else
return metric;
}
async function GetViewCount() {
const response = await fetch(`https://decapi.me/twitch/viewercount/${twitchUsername}`);
const viewcount = await response.text();
return isNaN(Number(viewcount)) ? 0 : Number(viewcount);
}