-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMMM-DailyStoic.js
62 lines (53 loc) · 1.88 KB
/
MMM-DailyStoic.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
Module.register("MMM-DailyStoic", {
defaults: {
updateInterval: 6 * 60 * 60 * 1000,
url: "https://dailystoic.pl/quote/text_en.json",
showTitle: true,
showQuote: true,
showDescription: true
},
start: function() {
Log.info("MMM-DailyStoic: Moduł startuje");
this.getData();
this.scheduleUpdate();
},
getData: function() {
this.sendSocketNotification("GET_DAILY_QUOTE", this.config.url);
},
getDom: function() {
var wrapper = document.createElement("div");
if (this.config.showTitle && this.title) {
var titleElement = document.createElement("h2");
titleElement.className = "bright medium";
titleElement.innerHTML = this.title;
wrapper.appendChild(titleElement);
}
if (this.config.showQuote && this.quote) {
var quoteElement = document.createElement("p");
quoteElement.className = "light small";
quoteElement.innerHTML = this.quote;
wrapper.appendChild(quoteElement);
}
if (this.config.showDescription && this.description) {
var descriptionElement = document.createElement("p");
descriptionElement.className = "small bright";
descriptionElement.innerHTML = this.description;
wrapper.appendChild(descriptionElement);
}
return wrapper;
},
socketNotificationReceived: function(notification, payload) {
if (notification === "DAILY_QUOTE_RESULT") {
this.title = payload.title;
this.quote = payload.quote;
this.description = payload.description;
this.updateDom();
}
},
scheduleUpdate: function() {
var self = this;
setInterval(function() {
self.getData();
}, this.config.updateInterval);
}
});