forked from andrecarlucci/MMM-DailyDilbert
-
Notifications
You must be signed in to change notification settings - Fork 3
/
MMM-Comics.js
executable file
·77 lines (69 loc) · 2.6 KB
/
MMM-Comics.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
Module.register("MMM-Comics", {
// Default module config.
defaults: {
comics: ["dilbert", "xkcd", "garfield", "peanuts", "calvin+hobbes"],
// Choose one or more of ["dilbert", "xkcd", "garfield", "peanuts", "calvin+hobbes", "ruthe", "dilbert_de"]
updateInterval : 1000 * 60 * 10, // 10 minutes
coloredImage: false,
maxWidth: 500,
maxHeight: 500,
timeForDaily: [6, 9], //place start and end hour here, divided by comma, e.g. [6, 9], please use 24h format!
debug: false
},
start: function() {
var counter = 0;
this.log("Starting module: " + this.name);
this.dailyComic = "";
this.getComic(this.config.comics[counter]);
var self = this;
setInterval(function() {
counter = (counter === self.config.comics.length - 1) ? 0 : counter + 1;
self.getComic(self.config.comics[counter]);
}, self.config.updateInterval);
},
getStyles: function() {
return ["comics.css"];
},
getComic: function(comic) {
this.log("Getting comic.");
this.sendSocketNotification("GET_COMIC", {
comic: comic,
config: this.config
});
},
socketNotificationReceived: function(notification, payload) {
if (notification === "COMIC") {
this.dailyComic = payload.img;
this.log("Comic source: " + this.dailyComic);
this.updateDom(500);
}
},
// Override dom generator.
getDom: function() {
var wrapper = document.createElement("div");
var comicWrapper = document.createElement("div");
comicWrapper.className = "comic-container";
comicWrapper.style.width = this.config.maxWidth + "px";
comicWrapper.style.height = this.config.maxHeight + "px";
var img = document.createElement("img");
img.id = "comic-content";
img.src = this.dailyComic;
this.log("Original width: "+img.naturalWidth+", Original height: "+img.naturalHeight);
/*if (this.config.maxWidth) {
img.width = this.config.maxWidth;
}*/
if (this.config.coloredImage) {
img.className = 'colored-image';
} else {
img.className = 'bw-image';
};
comicWrapper.appendChild(img);
wrapper.appendChild(comicWrapper);
return wrapper;
},
log: function (msg) {
if (this.config && this.config.debug) {
console.log(this.name + ":", JSON.stringify(msg));
}
},
});