Permalink
Browse files

Makes JSON request to graph.fb.com to get user details. Displays name…

… instead of number. Hidden friends list can be hidden/shown. Defaults to hidden.
  • Loading branch information...
1 parent 41d27cd commit 58717ec3e98c5a8cb1cd391f204d67501ee6c2c2 @aac committed Jan 12, 2011
Showing with 78 additions and 24 deletions.
  1. +18 −3 background.js
  2. +18 −15 manifest.json
  3. +13 −0 popup.html
  4. +29 −6 popup.js
View
@@ -1,3 +1,4 @@
+var popup;
var hiddenFriends;
jQuery(document).ready(function(){
@@ -16,14 +17,23 @@ jQuery(document).ready(function(){
function addHiddenFriend(id)
{
- hiddenFriends.push(id);
- storeFriends();
+ var details = {};
+ jQuery.getJSON("http://graph.facebook.com/"+id, function(data){
+ debugger;
+ details["id"] = data.id;
+ details["name"]= data.name;
+ 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;
+ return element.id != id;
});
storeFriends();
}
@@ -36,4 +46,9 @@ function getHiddenFriends()
function storeFriends()
{
localStorage.hiddenFriends=JSON.stringify(hiddenFriends);
+}
+
+function setPopup(p)
+{
+ popup = p;
}
View
@@ -1,17 +1,20 @@
{
- "name": "Eternal Sunshine",
- "version": "0.0.1",
- "description": "Hide friends from Facebook.",
- "browser_action": {
- "default_icon": "icon.png",
- "popup": "popup.html"
- },
- "background_page": "background.html",
- "content_scripts": [
- {
- "matches": ["http://www.facebook.com/*"],
- "js": ["jquery-1.4.4.min.js", "eternal.js"],
- "run_at": "document_start"
- }
- ]
+ "name": "Eternal Sunshine",
+ "version": "0.0.1",
+ "description": "Hide friends from Facebook.",
+ "browser_action": {
+ "default_icon": "icon.png",
+ "popup": "popup.html"
+ },
+ "background_page": "background.html",
+ "content_scripts": [
+ {
+ "matches": ["http://www.facebook.com/*"],
+ "js": ["jquery-1.4.4.min.js", "eternal.js"],
+ "run_at": "document_start"
+ }
+ ],
+ "permissions": [
+ "http://graph.facebook.com/"
+ ]
}
View
@@ -30,6 +30,7 @@
list-style-type: none;
margin: 0px;
padding: 0px;
+ display: none;
}
.hidden_friend {
padding: 4px 0;
@@ -55,6 +56,17 @@
}
.uiCloseButton:hover { background-position:0px -30px; }
.uiCloseButton:active{ background-position:0px -45px; }
+ #countContainer {
+ margin-top: 4px;
+ margin-bottom: 6px;
+ }
+ #count {
+ color: #6D84B4;
+ text-decoration: none;
+ }
+ #count:hover {
+ text-decoration: underline;
+ }
</style>
</head>
<body>
@@ -67,6 +79,7 @@
</div>
</div><div id="content">
<h2 id="header">Hidden Friends</h2>
+ <div id="countContainer"><a id="count" href="#"></a></div>
<ul id="hidden_friends" />
</div>
<div id="footerContainer">
View
@@ -1,30 +1,49 @@
var backgroundPage;
+var numHiddenFriends=0;
-function createListItem(v)
+function createListItem(friend)
{
var li = document.createElement("li");
var a = document.createElement("a");
jQuery(a).attr("src", "hide_button.png");
jQuery(a).addClass("uiCloseButton");
jQuery(a).click(function() {
- backgroundPage.removeHiddenFriend(v);
+ backgroundPage.removeHiddenFriend(friend.id);
jQuery(li).remove();
+ numHiddenFriends--;
+ updateCount();
});
- li.innerHTML = v;
+ li.innerHTML = friend.name;
+ jQuery(li).data('uid', friend.id);
jQuery(li).prepend(a);
jQuery(li).attr("class", "hidden_friend");
return li;
}
+function updateCount()
+{
+ jQuery("#count").html("You have hidden " + numHiddenFriends + " friend" + (numHiddenFriends == 1 ? "" : "s") + ".");
+}
+
+function addHiddenFriend(friend)
+{
+ jQuery("#hidden_friends").append(createListItem(friend));
+ numHiddenFriends++;
+ updateCount();
+}
+
function buildList(hiddenFriends)
{
- jQuery("#hidden_friends").append(hiddenFriends.map(function(v){
- return createListItem(v);
+ jQuery("#hidden_friends").append(hiddenFriends.map(function(friend){
+ return createListItem(friend);
}));
+ numHiddenFriends=hiddenFriends.length;
+ updateCount();
}
jQuery(document).ready(function(){
backgroundPage = chrome.extension.getBackgroundPage();
+ backgroundPage.setPopup(self);
buildList(backgroundPage.getHiddenFriends());
var form = jQuery("#hide_friend_form");
//var img = document.create("img");
@@ -33,7 +52,7 @@ jQuery(document).ready(function(){
event.preventDefault();
var val = jQuery("#id").val();
backgroundPage.addHiddenFriend(val);
- jQuery("#hidden_friends").append(createListItem(val));
+ //jQuery("#hidden_friends").append(createListItem(val));
jQuery("#id").val("");
jQuery("#id").focusout();
});
@@ -52,4 +71,8 @@ jQuery(document).ready(function(){
jQuery(this).addClass("placeholder");
}
});
+ jQuery("#count").click(function(event){
+ event.preventDefault();
+ jQuery("#hidden_friends").toggle();
+ });
});

0 comments on commit 58717ec

Please sign in to comment.