-
Notifications
You must be signed in to change notification settings - Fork 0
/
browser_action.js
58 lines (42 loc) · 1.56 KB
/
browser_action.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
function load() {
// Get the event_list container
var event_list = document.getElementById("event_list");
// Retrieve data from local memory
chrome.storage.local.get("events", function(data) {
// If the data is updated
if(typeof(data.events) !== "undefined") {
event_list.innerHTML = "";
// Generate list for each event entry
data.events.forEach(function(event, idx, array) {
// Check if the element is the last one. Use a different css style if true.
if (idx === (array.length - 1)) {
var elmnt = document.createElement("ul")
} else {
var elmnt = document.createElement("li")
}
// Obtain the event name, venue and link.
var event_name = event.name;
var event_link = event.link;
var event_venue = event.venue;
// Container for the event venue.
var div = document.createElement("div");
div.innerHTML = event_venue;
div.setAttribute("class", "venue");
var a = document.createElement("a");
a.innerHTML = event_name;
// Open a blank tab when the link is clicked.
a.setAttribute("target", "_blank");
a.setAttribute("href", event_link);
// Put the event venue and link to the element
elmnt.appendChild(div);
elmnt.appendChild(a);
// Append the new element to the list.
event_list.appendChild(elmnt);
});
}
});
}
// Trigger the function when DOM of the pop-up is loaded.
document.addEventListener('DOMContentLoaded', function() {
load();
});