-
Notifications
You must be signed in to change notification settings - Fork 0
/
MMM-Hanzi.js
60 lines (57 loc) · 1.69 KB
/
MMM-Hanzi.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
let currentHanzi = {
"id": 0,
"hanzi": "",
"pinyin": "",
"translations": [
"",
""
]
};
Module.register("MMM-Hanzi",{
// Default module config.
defaults: {
hskLevel: 4,
interval: 300000,
},
start: function() {
this.getData();
},
getDom: () => {
const divElement = document.createElement("div");
divElement.style.marginLeft = "1rem";
const hanziElement = document.createElement("p");
hanziElement.style.fontSize = "6rem";
hanziElement.style.marginBottom = "0";
hanziElement.style.color = "white";
hanziElement.innerHTML = currentHanzi.hanzi;
const pinyinElement = document.createElement("p");
pinyinElement.innerHTML = "<b>"+currentHanzi.pinyin+"</b>";
pinyinElement.style.fontSize = "1.5rem";
pinyinElement.style.margin = "0";
pinyinElement.style.color = "white";
const translationElement = document.createElement("p");
translationElement.style.fontSize = "1.5rem";
translationElement.style.padding = "0";
translationElement.style.margin = "0";
translationElement.innerHTML = "<b>"+currentHanzi.translations[0]+"</b>";
divElement.appendChild(hanziElement);
divElement.appendChild(pinyinElement);
divElement.appendChild(translationElement);
return divElement;
},
getData: function() {
this.sendSocketNotification("GET_HANZI", this.config);
setInterval(() => {
this.sendSocketNotification("GET_HANZI", this.config);
}, this.config.interval);
},
socketNotificationReceived: function (notification, payload) {
switch (notification) {
case "UPDATE_HANZI":
currentHanzi = payload;
break;
default:
}
this.updateDom();
}
});