-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathMMM-JsonValue.js
72 lines (61 loc) · 1.63 KB
/
MMM-JsonValue.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
/* Magic Mirror
* Module: MMM-JsonValue
*
* By Chris Klinger, http://chrisklinger.de
* MIT Licensed.
*/
Module.register("MMM-JsonValue", {
defaults: {
apiBase: 'https://api.quotable.io/random',
method: "GET",
title: "MM API TEST",
icon: "fa-quote-right",
prefix: "Quote: \"",
suffix: "\" (from https://api.quotable.io/random)",
jsonPath: "content",
headers: {},
refreshInterval: 1000 * 60, // refresh every minute
},
getStyles: function () {
return ["font-awesome.css"];
},
start: function () {
this.loaded = false;
this.value = "";
this.config.instanceID = this.identifier
this.sendSocketNotification('CONFIG', this.config);
},
getHeader: function () {
return this.config.title ? this.config.title : "";
},
getDom: function() {
var wrapper = document.createElement("div");
if (!this.loaded) {
wrapper.innerHTML = this.translate("LOADING");
wrapper.className = "dimmed light small";
return wrapper;
}
wrapper.innerHTML = this.config.prefix + this.value + this.config.suffix;
if(this.config.icon) {
wrapper.innerHTML = "<span class=\"" + this.config.icon + "\"></span>" + wrapper.innerHTML;
}
if(this.config.skipPadding) {
wrapper.style = "margin-block-end: -30px;";
}
return wrapper;
},
notificationReceived: function() {},
socketNotificationReceived: function(notification, payload) {
if(payload.instanceID === this.config.instanceID) {
if (notification === "STARTED") {
this.updateDom();
}
else if (notification === "DATA") {
this.loaded = true;
Log.info(payload);
this.value = payload.data;
this.updateDom();
}
}
}
})