-
Notifications
You must be signed in to change notification settings - Fork 5
/
background.js
33 lines (26 loc) · 1.02 KB
/
background.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
var mytoken; var cal;
chrome.identity.getAuthToken({ 'interactive': true }, function(token) {
mytoken = token;
var x = new XMLHttpRequest();
x.open('GET', 'https://www.googleapis.com/calendar/v3/users/me/calendarList?alt=json' + '&access_token=' + token);
x.onload = function(){
var jsonResponse = JSON.parse(x.response);
var obj = [];
for (var i= 0; i< jsonResponse.items.length; i++){
if (i == 0)
obj.push({"name" : jsonResponse.items[i].summary, "selected" : true, "id": jsonResponse.items[i].id});
else
obj.push({"name" : jsonResponse.items[i].summary, "selected" : false, "id": jsonResponse.items[i].id});
}
localStorage['myCals'] = JSON.stringify(obj);
cal = obj;
};
x.send();
});
chrome.extension.onMessage.addListener(function(message,sender,sendResponse){
if(message.text == "getStuff"){
var myName = localStorage['myName'];
var obj = JSON.parse(localStorage['myCals']);
sendResponse({type: mytoken, name: myName, cal: obj});
}
});