-
Notifications
You must be signed in to change notification settings - Fork 16
/
MMM-connection-status.js
executable file
·64 lines (57 loc) · 1.62 KB
/
MMM-connection-status.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
/* Magic Mirror
* Module: MMM-connection-status
*
* By Sheya Bernstein https://github.com/sheyabernstein/MMM-connection-status
* MIT Licensed.
*/
Module.register('MMM-connection-status', {
// Default module config.
defaults: {
updateInterval: 1000 * 60, // every minute
initialLoadDelay: 0,
animationSpeed: 1000 * 0.25,
connectedColor: "var(--color-text)",
disconnectedColor: "var(--color-text)",
},
// Define required translations.
getTranslations: function() {
return {
'en': 'translations/en.json',
'es': 'translations/es.json',
'fr': 'translations/fr.json',
'fi': 'translations/fi.json',
'id': 'translations/id.json',
'it': 'translations/it.json',
};
},
// Define start sequence.
start: function() {
Log.info("Starting module: " + this.name);
// Loop infinitely
this.loop();
},
// Override dom generator.
getDom: function() {
const wrapper = document.createElement('div');
if (window.navigator.onLine) {
wrapper.className = 'small';
wrapper.style.color = this.config.connectedColor;
wrapper.innerHTML = this.translate("INET_CONN_CONNECTED");
} else {
wrapper.className = 'normal bright';
wrapper.style.color = this.config.disconnectedColor;
wrapper.innerHTML = this.translate("INET_CONN_NOTCONNECTED");
}
return wrapper;
},
// Infinite loop
loop: function() {
const self = this;
setTimeout(function() {
setInterval(function() {
// Refreshes the dom, using the getDom() function
self.updateDom(self.config.animationSpeed);
}, self.config.updateInterval); // Loop interval
}, self.config.initialLoadDelay); // First delay
}
});