This commit is contained in:
Lilith Ashley Nyx Arson 🔥 2024-11-03 21:56:08 +01:00
parent 2d3ef05071
commit 70b92ce0fc
Signed by: lilith
SSH key fingerprint: SHA256:LAjgsAMyT3LO2JVtr6fQ4N3RTYoRRlIm5wAKsbDife4
3 changed files with 140 additions and 1 deletions

57
css/style.css Normal file
View file

@ -0,0 +1,57 @@
body {
width: 100vw;
height: 100vh;
margin: 0;
padding: 0;
display: flex;
align-items: center;
justify-content: center;
background: #eff1f5;
color: #4c4f69;
}
@media (prefers-color-scheme: dark) {
body {
background: #1e1e2e;
color: #cdd6f4;
}
}
fieldset {
border: 1px solid currentColor;
}
.container {
width: auto;
height: auto;
display: inline;
}
legend {
margin: 0 auto;
}
.nf-spin {
display: inline-block;
animation-delay: 0;
animation-direction: normal;
animation-name: spin;
animation-duration: 2s;
animation-iteration-count: infinite;
animation-timing-function: linear
}
@keyframes spin {
0% {
transform: rotate(0deg)
}
to {
transform: rotate(1turn)
}
}

View file

@ -1 +1,33 @@
hi <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>opentracker</title>
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="css/nerd-fonts.min.css">
</head>
<body>
<fieldset class="container">
<legend>opentracker</legend>
<table>
<tr>
<th id="s"><i class="nf nf-fa-spinner nf-spin"></i></th>
<td>Seeder(s)</td>
</tr>
<tr>
<th id="l"><i class="nf nf-fa-spinner nf-spin"></i></th>
<td>Leecher(s)</td>
</tr>
</table>
<small id="footer"><i class="nf nf-fa-spinner nf-spin"></i> Loading...</small>
</fieldset>
<script defer src="js/script.js"></script>
</body>
</html>

50
js/script.js Normal file
View file

@ -0,0 +1,50 @@
function xml2json(xml) {
var obj = {};
if (xml.nodeType == 1) {
if (xml.attributes.length > 0) {
obj["@attributes"] = {};
for (var j = 0; j < xml.attributes.length; j++) {
var attribute = xml.attributes.item(j);
obj["@attributes"][attribute.nodeName] = attribute.nodeValue;
}
}
} else if (xml.nodeType == 3) {
obj = xml.nodeValue.trim();
}
var textNodes = [].slice.call(xml.childNodes).filter(function (node) {
return node.nodeType === 3;
});
if (xml.hasChildNodes() && xml.childNodes.length === textNodes.length) {
obj = [].slice.call(xml.childNodes).reduce(function (text, node) {
return text + node.nodeValue.trim();
}, "");
} else if (xml.hasChildNodes()) {
for (var i = 0; i < xml.childNodes.length; i++) {
var item = xml.childNodes.item(i);
var nodeName = item.nodeName;
if (nodeName == "#text") continue;
if (typeof obj[nodeName] == "undefined") {
obj[nodeName] = xml2json(item);
} else {
if (typeof obj[nodeName].push == "undefined") {
var old = obj[nodeName];
obj[nodeName] = [];
obj[nodeName].push(old);
}
obj[nodeName].push(xml2json(item));
}
}
}
return obj;
}
const parser = new DOMParser();
fetch("stats?mode=everything").then(r => r.text()).then(r => {
var data = xml2json(parser.parseFromString(r, "text/xml")).stats;
document.querySelector("#s").textContent = data.seeds.count;
document.querySelector("#l").textContent = data.completed.count;
document.querySelector("#footer").textContent = `serving ${data.torrents.count_mutex} torrents`;
});