-
Notifications
You must be signed in to change notification settings - Fork 10
/
MMM-DailyDilbert.js
67 lines (54 loc) · 1.67 KB
/
MMM-DailyDilbert.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
Module.register("MMM-DailyDilbert", {
// Default module config.
defaults: {
updateInterval : 10000 * 60 * 60, // 10 hours
},
start: function() {
Log.info(this.config);
Log.info("Starting module: " + this.name);
this.dailyComic = "";
this.getComic();
self = this;
if(self.config.updateInterval < 60000) {
self.config.updateInterval = 60000;
}
setInterval(function() {
self.getComic();
}, self.config.updateInterval);
},
// Define required scripts.
getScripts: function() {
return [];
},
getStyles: function() {
return ["dilbert.css"];
},
getComic: function() {
Log.info("Dilbert: Getting comic.");
this.sendSocketNotification("GET_COMIC", {
config: this.config
});
},
socketNotificationReceived: function(notification, payload) {
if (notification === "COMIC") {
Log.info('Dilbert url return: ' + payload.img);
this.dailyComic = payload.img;
this.updateDom(1000);
}
},
notificationReceived: function(notification, payload, sender) {
},
// Override dom generator.
getDom: function() {
var wrapper = document.createElement("div");
var comicWrapper = document.createElement("div");
comicWrapper.className = "dilbert-container";
var img = document.createElement("img");
img.id = "dilbert-content";
img.src = this.dailyComic;
img.classList.add('dilbert-image');
comicWrapper.appendChild(img);
wrapper.appendChild(comicWrapper);
return wrapper;
}
});