-
Notifications
You must be signed in to change notification settings - Fork 2
/
background.js
62 lines (52 loc) · 1.3 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
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
var popup;
var hiddenFriends;
jQuery(document).ready(function(){
if (!localStorage.hiddenFriends)
localStorage.hiddenFriends = JSON.stringify([]);
hiddenFriends = JSON.parse(localStorage.hiddenFriends);
chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
if (request.action == "getHiddenFriendIds")
sendResponse({hiddenFriends: getHiddenFriendIds()})
else
sendResponse({}); // snub them.
});
});
function addHiddenFriend(id)
{
var details = {};
jQuery.getJSON("http://graph.facebook.com/"+id, function(data){
debugger;
details["id"] = data.id;
details["name"]= data.name;
if (typeof(data.link) != 'undefined')
details["slug"]= data.link.substring(data.link.lastIndexOf("/")+1);
hiddenFriends.push(details);
storeFriends();
popup.addHiddenFriend(details);
});
}
function removeHiddenFriend(id)
{
hiddenFriends=jQuery.grep(hiddenFriends, function(element, index){
return element.id != id;
});
storeFriends();
}
function getHiddenFriends()
{
return hiddenFriends;
}
function getHiddenFriendIds()
{
return jQuery.map(hiddenFriends, function(element, index){
return element.id;
});
}
function storeFriends()
{
localStorage.hiddenFriends=JSON.stringify(hiddenFriends);
}
function setPopup(p)
{
popup = p;
}