This repository has been archived by the owner on Oct 22, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
Copy pathsysinfo.class.js
139 lines (129 loc) · 3.98 KB
/
sysinfo.class.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
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
class Sysinfo {
constructor(parentId) {
if (!parentId) throw "Missing parameters";
// See #255
let os;
switch (require("os").platform()) {
case "darwin":
os = "macOS";
break;
case "win32":
os = "win";
break;
default:
os = require("os").platform();
}
// Create DOM
this.parent = document.getElementById(parentId);
this.parent.innerHTML += `<div id="mod_sysinfo">
<div>
<h1>1970</h1>
<h2>JAN 1</h2>
</div>
<div>
<h1>UPTIME</h1>
<h2>0:0:0</h2>
</div>
<div>
<h1>TYPE</h1>
<h2>${os}</h2>
</div>
<div>
<h1>POWER</h1>
<h2>00%</h2>
</div>
</div>`;
this.updateDate();
this.updateUptime();
this.uptimeUpdater = setInterval(() => {
this.updateUptime();
}, 60000);
this.updateBattery();
this.batteryUpdater = setInterval(() => {
this.updateBattery();
}, 3000);
}
updateDate() {
let time = new Date();
document.querySelector("#mod_sysinfo > div:first-child > h1").innerHTML = time.getFullYear();
let month = time.getMonth();
switch(month) {
case 0:
month = "JAN";
break;
case 1:
month = "FEB";
break;
case 2:
month = "MAR";
break;
case 3:
month = "APR";
break;
case 4:
month = "MAY";
break;
case 5:
month = "JUN";
break;
case 6:
month = "JUL";
break;
case 7:
month = "AUG";
break;
case 8:
month = "SEP";
break;
case 9:
month = "OCT";
break;
case 10:
month = "NOV";
break;
case 11:
month = "DEC";
break;
}
document.querySelector("#mod_sysinfo > div:first-child > h2").innerHTML = month+" "+time.getDate();
let timeToNewDay = ((23 - time.getHours()) * 3600000) + ((59 - time.getMinutes()) * 60000);
setTimeout(() => {
this.updateDate();
}, timeToNewDay);
}
updateUptime() {
let uptime = {
raw: Math.floor(require("os").uptime()),
days: 0,
hours: 0,
minutes: 0
};
uptime.days = Math.floor(uptime.raw/86400);
uptime.raw -= uptime.days*86400;
uptime.hours = Math.floor(uptime.raw/3600);
uptime.raw -= uptime.hours*3600;
uptime.minutes = Math.floor(uptime.raw/60);
if (uptime.hours.toString().length !== 2) uptime.hours = "0"+uptime.hours;
if (uptime.minutes.toString().length !== 2) uptime.minutes = "0"+uptime.minutes;
document.querySelector("#mod_sysinfo > div:nth-child(2) > h2").innerHTML = uptime.days + '<span style="opacity:0.5;">d</span>' + uptime.hours + '<span style="opacity:0.5;">:</span>' + uptime.minutes;
}
updateBattery() {
window.si.battery().then(bat => {
let indicator = document.querySelector("#mod_sysinfo > div:last-child > h2");
if (bat.hasBattery) {
if (bat.isCharging) {
indicator.innerHTML = "CHARGE";
} else if (bat.acConnected) {
indicator.innerHTML = "WIRED";
} else {
indicator.innerHTML = bat.percent+"%";
}
} else {
indicator.innerHTML = "ON";
}
});
}
}
module.exports = {
Sysinfo
};