1String.prototype.toHHMMSS = function () {
2 var sec_num = parseInt(this, 10); // don't forget the second param
3 var hours = Math.floor(sec_num / 3600);
4 var minutes = Math.floor((sec_num - hours * 3600) / 60);
5 var seconds = sec_num - hours * 3600 - minutes * 60;
6
7 if (hours < 10) {
8 hours = "0" + hours;
9 }
10 if (minutes < 10) {
11 minutes = "0" + minutes;
12 }
13 if (seconds < 10) {
14 seconds = "0" + seconds;
15 }
16 return hours + ":" + minutes + ":" + seconds;
17};
18
19function formatBytes(bytes, decimals = 2) {
20 if (!+bytes) return "0 Bytes";
21
22 const k = 1024;
23 const dm = decimals < 0 ? 0 : decimals;
24 const sizes = ["Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
25
26 const i = Math.floor(Math.log(bytes) / Math.log(k));
27
28 return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}`;
29}
30
31$.ajax({
32 url: "https://yukihyou.ontake.dev/banner",
33 type: "GET",
34 dataType: "text", // added data type
35 success: function (res) {
36 console.log(res);
37 document.getElementById("ascii-banner-text").innerHTML = res
38 .replaceAll(" ", " ")
39 .replaceAll("<", "<")
40 .replaceAll(">", ">")
41 .replaceAll("\n", "<br>");
42 },
43});
44$.ajax({
45 url: "https://yukihyou.ontake.dev/status",
46 type: "GET",
47 dataType: "json", // added data type
48 success: function (res) {
49 console.log(res);
50 document.getElementById("server-system-info-text").innerHTML =
51 "Hostname: " + res.Hostname + "<br>";
52 document.getElementById("server-system-info-text").innerHTML +=
53 "Server time: " + res.CurrentTime + "<br>";
54 document.getElementById("server-system-info-text").innerHTML +=
55 "Uptime: " + String(res.UpTime).toHHMMSS() + "<br>";
56 document.getElementById("server-system-info-text").innerHTML +=
57 "Used memory: " + formatBytes(res.SystemMemory - res.FreeMemory) + "<br>";
58 document.getElementById("server-system-info-text").innerHTML +=
59 "System memory: " + formatBytes(res.SystemMemory);
60 },
61});