-
Notifications
You must be signed in to change notification settings - Fork 0
/
MMM-Reddit-News-Ticker.js
90 lines (82 loc) · 2.39 KB
/
MMM-Reddit-News-Ticker.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
82
83
84
85
86
87
88
89
90
Module.register('MMM-Reddit-News-Ticker', {
defaults: {
updateInterval: 8000000, // 2.25 hours
retryDelay: 5000,
},
requiresVersion: '2.1.0', // Required version of MagicMirror
start: function () {
var home = this;
var self = this;
console.log(home.name + 'START');
const id = home.config.client_id;
const secret = home.config.secret;
const api = [id, secret];
home.getData(api);
setInterval(function () {
self.updateDom();
}, home.config.updateInterval);
},
getData: function (data) {
const retry = true;
// const data = this.data;
this.sendSocketNotification('PULL_NEWS', data);
},
getDom: function () {
const moduleDiv = document.createElement('div');
if (document.querySelector('.hwrap') === null) {
const hwrap = document.createElement('div');
const hmove = document.createElement('div');
const hitem = document.createElement('div');
moduleDiv.appendChild(hwrap);
hwrap.appendChild(hmove);
hmove.appendChild(hitem);
hwrap.classList.add('hwrap');
hmove.classList.add('hmove');
hitem.classList.add('hitem');
}
return moduleDiv;
},
getScripts: function () {
return [];
},
getStyles: function () {
return ['MMM-Reddit-News-Ticker.css'];
},
// Load translations files
getTranslations: function () {
return {
en: 'translations/en.json',
es: 'translations/es.json',
};
},
processData: function (data) {
this.loaded = true;
this.sendSocketNotification('DOM_OBJECTS_CREATED', data);
},
injectHTML: function (str) {
const hitem = document.querySelector('.hitem');
hitem.innerHTML = str;
},
socketNotificationReceived: function (notification, payload) {
const self = this;
switch (notification) {
case 'TIME':
console.log(this.name + ' ⌛');
const time = payload;
const hitem = document.querySelector('.hitem');
hitem.style.animationName = 'tickerh';
hitem.style.animationDuration = `${time}s`;
hitem.style.animationTimingFunction = 'linear';
hitem.style.animationIterationCount = 'infinite';
break;
case 'ARR':
console.log(this.name + ' 🏴☠️');
this.injectHTML(payload);
break;
case 'TITLES':
console.log(this.name + ' 📰');
this.processData(payload);
break;
}
},
});