-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathMMM-GoogleKeep.js
executable file
·113 lines (90 loc) · 3.01 KB
/
MMM-GoogleKeep.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/* global Module */
/* Magic Mirror
* Module: MMM-GoogleKeep
*
* By taxilof
* MIT Licensed.
*/
Module.register("MMM-GoogleKeep", {
requiresVersion: "2.1.0", // Required version of MagicMirror
start: function() {
Log.log('Starting module: ' + this.name);
var self = this;
var dataRequest = null;
var dataNotification = null;
var noteData = null;
this.sendSocketNotification('MMM-GoogleKeep-CONFIG', this.config);
this.sendSocketNotification('MMM-GoogleKeep-INITIALIZE', null);
// Flag to check if module is loaded
this.loaded = false;
Log.log("update interval is" + this.config.updateInterval);
// Schedule update timer.
setInterval(function() {
self.process();
}, this.config.updateInterval * 1000);
},
getHeader: function() {
return this.headerData ? this.headerData : "";
},
getDom: function() {
console.log("getting dom");
Log.log("11getting dom");
var self = this;
// create element wrapper for show into the module
var wrapper = document.createElement("div");
if(this.config.width){
wrapper.style.width = this.config.width + 'px';
}
if (this.noteData) {
var wrapperDataNotification = document.createElement("div");
wrapperDataNotification.style.textAlign= "left";
noteDataHTML = this.noteData.replace(
/[<>]/g, ""
).replace(
/(\n)/gm, "<br>"
).replace(/ ☐/gm, "└─ ☐");
Log.log('XXX' + noteDataHTML);
wrapperDataNotification.innerHTML = noteDataHTML;
wrapper.appendChild(wrapperDataNotification);
}
return wrapper;
},
getScripts: function() {
return [];
},
getStyles: function () {
return [
"MMM-GoogleKeep.css",
];
},
// Load translations files
getTranslations: function() {
//FIXME: This can be load a one file javascript definition
return {
en: "translations/en.json",
es: "translations/es.json"
};
},
process: function() {
this.sendSocketNotification('MMM-GoogleKeep-INITIALIZE', null);
},
processData: function(data) {
console.log("processing");
var self = this;
this.dataRequest = data;
if (this.loaded === false) { self.updateDom(self.config.animationSpeed) ; }
this.loaded = true;
// the data if load
// send notification to helper
this.sendSocketNotification("MMM-GoogleKeep-NOTIFICATION_TEST", data);
},
// socketNotificationReceived from helper
socketNotificationReceived: function (notification, payload) {
console.log('jup notify: ' + payload);
if(notification === "note_text") {
this.noteData = payload.text.join('\n');
this.headerData = payload.header;
this.updateDom();
}
},
});