-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgemstones.js
81 lines (66 loc) · 1.94 KB
/
gemstones.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
78
79
80
81
/* Magic Mirror
* Module: Gemstones
*
* By Spencer6497
*
*/
Module.register("gemstones",{
// Default module config.
defaults: {
text: "Gemstones",
updateInterval: 24 * 60 * 60 * 1000 // every 24 hours
},
// Override dom generator.
getDom: function() {
var imgSrc = this.imgSrc;
var caption = this.caption;
var wrapper = document.createElement("div");
// If not yet loaded, display loading
if (!this.loaded) {
wrapper.innerHTML = '<p>Loading...</p>';
return wrapper;
}
var titleWrapper = document.createElement('div');
titleWrapper.classList.add('center'); // Add css classes here for styling
titleWrapper.innerHTML = `<h3 class=bottomMargin>Rock of the day:</h3>`
wrapper.appendChild(titleWrapper);
var imgWrapper = document.createElement('div');
imgWrapper.classList.add('center'); // Add css classes here for styling
imgWrapper.innerHTML = `<img src=${imgSrc} class=maxWidth>`
wrapper.appendChild(imgWrapper);
var captionWrapper = document.createElement('div');
captionWrapper.classList.add('center'); // Add css classes here for styling
captionWrapper.innerHTML = caption;
wrapper.appendChild(captionWrapper);
return wrapper;
},
// Start sequence
start: function() {
Log.info('Starting module: ' + this.name);
this.scheduleUpdate();
},
getStyles: function() {
return ['gemstones.css'];
},
processGemstone: function(data) {
this.loaded = true;
this.imgSrc = data.imgSrc;
this.caption = data.mineralName;
},
scheduleUpdate: function() {
setInterval(() => {
this.getGemstones();
}, this.config.updateInterval);
this.getGemstones();
},
getGemstones: function() {
this.sendSocketNotification("GET_GEMSTONES");
},
socketNotificationReceived: function(notification, payload) {
if (notification === 'GEMSTONE_RESULT') {
this.processGemstone(payload);
this.updateDom();
}
this.updateDom();
},
});