-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy patheventData.js
44 lines (38 loc) · 1.02 KB
/
eventData.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
function httpGetAsync(theUrl, callback) {
fetch(theUrl)
.then(function(response) {
return response.json();
})
.then(function(response) {
callback(response);
});
};
//Updates the eventData variable and resets the popup's html document
function setEventData(data) {
if (eventData != data) {
eventData = data;
chrome.browserAction.setPopup({popup: "events.html"});
}
};
function getEventData() {
httpGetAsync("https://api.lambdaspace.gr/api/v2.0/events", setEventData);
};
//Stores the latest JSON response from discourse
var eventData;
//Stores content of the latest generated HTML body
var HTMLbodyData;
getEventData();
setInterval(getEventData, 300000);
chrome.runtime.onConnect.addListener(function(port) {
if (port.name == "HTMLData") {
port.onMessage.addListener(function(msg) {
if (msg == "get") {
port.postMessage(HTMLbodyData);
} else {
HTMLbodyData = msg;
}
});
} else if (port.name == "eventData") {
port.postMessage(eventData);
}
});