-
Notifications
You must be signed in to change notification settings - Fork 1
/
MMM-MTG.js
53 lines (47 loc) · 1.38 KB
/
MMM-MTG.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
const api = "https://api.scryfall.com";
const random = '/cards/random';
const commander = '/cards/random?q=is%3Acommander';
Module.register("MMM-MTG", {
defaults: {
sizePx: '450px',
showCommandersOnly: true,
fetchInterval: 1,
},
imageUri: "",
requiresVersion: "2.25.0",
start: async function() {
this.getData();
if(this.config.fetchInterval > 0){
setInterval(() => {
this.getData();
}, this.config.fetchInterval * 60000);
}
},
getDom: async function () {
var imgContainer = document.createElement("div");
if(this.imageUri){
var imgElement = document.createElement("img");
imgElement.src = this.imageUri;
imgElement.style.maxHeight = this.config.sizePx;
imgContainer.appendChild(imgElement);
}
return imgContainer;
},
getData: async function () {
if(this.config.showCommandersOnly){
this.sendSocketNotification("GET_MTG_CARD", api + commander);
}else{
this.sendSocketNotification("GET_MTG_CARD", api + random);
}
},
socketNotificationReceived: function (notification, payload) {
switch (notification) {
case "UPDATE_CARD_DATA":
this.imageUri = payload.src;
this.updateDom();
break;
default:
break;
}
}
});