forked from Gismo150/MMM-GoogleShoppingList
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMMM-GoogleShoppingList.js
76 lines (64 loc) · 1.8 KB
/
MMM-GoogleShoppingList.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
//
// MMM-GoogleShoppingList
//
Module.register("MMM-GoogleShoppingList", {
defaults: {
creds: {
email: "",
password: "",
},
scanInterval: 1000*60*10,
displayImage: true,
// don't care about belows;
useCookies: true,
browser: {
headless: true, // Set to false for debugging purposes (will start your chromium browser ui)
executablePath: "/usr/bin/chromium-browser" //If you are using OSX or other system, remove this line or change.
}
},
getStyles: function() {
return ["MMM-GoogleShoppingList.css"]
},
start: function() {
this.sendSocketNotification("START", this.config)
},
getDom: function() {
var wrapper = document.createElement("ul")
wrapper.id = "GSL_WRAPPER"
var loading = document.createElement("div")
loading.id = "GSL_LOADING"
loading.innerHTML = "loading..."
wrapper.appendChild(loading)
return wrapper
},
socketNotificationReceived: function(noti, payload) {
if (noti == "REFRESHED") {
this.drawItems(payload)
}
},
drawItems: function(items) {
var wrapper = document.getElementById("GSL_WRAPPER")
wrapper.innerHTML = ""
if (items.length > 0) {
items.forEach(item => {
var d = document.createElement("li")
d.className = "GSL_ITEM"
var v = document.createElement("div")
v.innerHTML = item
if (this.config.displayImage) {
var i = v.querySelector("img.itemImage")
if (i) {
var img = document.createElement("img")
img.src = i.src
d.appendChild(img)
}
}
var t = v.querySelector(".title").innerHTML
var title = document.createElement("span")
title.innerHTML = t
d.appendChild(title)
wrapper.appendChild(d)
})
}
}
})