mirror of
https://github.com/nuttylmao/nutty.gg.git
synced 2026-09-19 12:10:59 -04:00
40 lines
976 B
JavaScript
40 lines
976 B
JavaScript
////////////////////
|
|
// URL PARAMETERS //
|
|
////////////////////
|
|
|
|
const queryString = window.location.search;
|
|
const urlParams = new URLSearchParams(queryString);
|
|
const twitchUsername = urlParams.get("username") || '';
|
|
|
|
///////////////
|
|
// FUNCTIONS //
|
|
///////////////
|
|
|
|
async function UpdateUptime() {
|
|
document.getElementById("uptimeLabel").innerHTML = await GetUptime();
|
|
|
|
setTimeout(UpdateUptime, 30000);
|
|
}
|
|
|
|
UpdateUptime();
|
|
|
|
async function GetUptime() {
|
|
const response = await fetch(`https://decapi.me/twitch/uptime/${twitchUsername}`);
|
|
const metric = await response.text();
|
|
|
|
if (metric.includes("second"))
|
|
{
|
|
return removeTextAfterLastComma(metric);
|
|
}
|
|
else
|
|
return metric;
|
|
}
|
|
|
|
function removeTextAfterLastComma(str) {
|
|
const lastCommaIndex = str.lastIndexOf(',');
|
|
if (lastCommaIndex !== -1) {
|
|
return str.substring(0, lastCommaIndex);
|
|
} else {
|
|
return str; // No comma found, return the original string
|
|
}
|
|
} |