Facebook Friends Checker

By znerp Last update Nov 5, 2009 — Installed 72,615 times. Daily Installs: 390, 1079, 840, 633, 612, 644, 484, 445, 485, 767, 1115, 881, 1510, 1005, 719, 836, 741, 544, 461, 415, 379, 427, 450, 472, 520, 538, 586, 669, 548, 488, 510, 513

There are 12 previous versions of this script.

// ==UserScript==
// @name           Facebook Friends Checker
// @description    Regularly checks your Facebook friends to check whether anyone has removed you from their friends.
// @namespace      znerp
// @include        http://*.facebook.com/*
// @require        http://usocheckup.dune.net/40027.js
// ==/UserScript==

GM_registerMenuCommand("Set time interval to check for removed friends...", changeTime);
var facebookID;

window.setTimeout(
  function() {
    informOld();
    doCheck();
  }, 5000)

function informOld() {
  if(unsafeWindow.buddyList) {
    facebookID = unsafeWindow.buddyList.user;
    exFriends = eval(GM_getValue(facebookID + " ex friends", "({})"));
    for (i in exFriends)
      inform(exFriends[i]);
  }
}

function doCheck() {
  if (((GM_getValue("check time", 2)*60*60*1000) + new Date(GM_getValue("last checked", 0)).getTime() < new Date().getTime()) &&
      unsafeWindow.buddyList) {
    var oldSavedFriends = eval(GM_getValue(facebookID + " friends","[]"));
    var newSavedFriends = ({});

    GM_xmlhttpRequest({
      method: 'get',
      headers: {
        'Content-type': 'application/x-www-form-urlencoded'
      },
      url: "http://www.facebook.com/ajax/typeahead_search.php?__a=1&time=" + Math.floor((new Date()).getTime() / 1000),
      onload: function(result) {
        friends = eval('(' + result.responseText.substring(9) + ')').payload.entries;

        for (i = friends.length - 1; i >= 0; i--) {
          if (friends[i].ty == "u") {
            newSavedFriends[friends[i].i] = friends[i];
          }
        }

        for (i in oldSavedFriends) {
          if (!newSavedFriends[i]) {
            exFriends[i] = oldSavedFriends[i];
      inform(oldSavedFriends[i]);
          }
        }
        GM_setValue(facebookID + " friends", uneval(newSavedFriends));
        GM_setValue(facebookID + " ex friends", uneval(exFriends));
        GM_setValue("last checked", new Date().toGMTString());
      }
    });
  }
}

function inform(friend){
  if (document.getElementById("menubar_container")) {
    if (!document.getElementById("facebookFriendsChecker"))
      addFriendsCheckerStuff()
    personRemoved = document.createElement("div");
    personRemoved.setAttribute("class", "person");
    personRemoved.innerHTML = "<div class=\"image\"><span><img class=\"photo\" alt=\""+friend.t+"\" src=\""+friend.it+"\"/></span></div>"+
                              "<div class=\"info\"><dl class=\"clearfix\"><dt>Name:</dt><dd class=\"result_name fn\"><span class=\"url fn\">"+friend.t+"</span></dd>"+
                                                                         "<dt>Actions:</dt><dd class=\"fn\"><span class=\"url fn\"><a href=\"http://www.facebook.com/profile.php?id="+friend.i+"\">View Profile</a></span></dd>"+
                                                                         "<dt>Status:</dt><dd class=\"fn\"><span class=\"url fn\">"+(friend.pnd==1?"Rejected your friend request.":"No longer in your friends.")+"</span></dd></dl></div>"
    document.getElementById("removedFriends").appendChild(personRemoved);
  }
}

function addFriendsCheckerStuff() {
  if (foo = document.getElementById("menubar_container")) {
    ffc = document.createElement("div");
    ffc.id = "facebookFriendsChecker";
    GM_addStyle("#facebookFriendsChecker {"+
                "  top: 0px;"+
                "  padding-top: 0px;"+
                "  width: 964px;"+
                "  margin: auto;"+
                "  position: relative;"+
                "  display: block;"+
                "  height: auto;"+
                "  background-color: #3B5998;"+
                "  border-bottom: 1px solid #D8DFEA;"+
                "}"+
                ""+
                "#facebookFriendsChecker h2, #facebookFriendsChecker h3 {"+
                "  color: white;"+
                "  display: block;"+
                "  font-weight: bold;"+
                "  padding:7px 7px 7px 8px;"+
                "}"+
                ""+
                "#facebookFriendsChecker h2 {"+
                "  font-size: 16px;"+
                "}"+
                ""+
                "#facebookFriendsChecker h3 {"+
                "  font-size: 14px;"+
                "}"+
                ""+
                "#Explanation a {"+
                "  color: white;"+
                "}"+
                ""+
                "#facebookFriendsChecker .person {"+
                "  background: white none;"+
                "  border: 1px solid #CCCCCC;"+
                "  margin: 5px;"+
                "  padding: 9px 9px 0 9px;"+
                "  width: 400px;"+
                "}"+
                ""+
                ".info dt {"+
                "  color:gray;"+
                "  float:left;"+
                "  padding:0;"+
                "  width:75px;"+
                "}"+
                "#facebookFriendsChecker img {"+
                "  display: block;"+
                "  float: left;"+
                "  height: 50px;"+
                "  padding:0 9px 0 0;"+
                "}"+
                "#facebookFriendsChecker #Explanation {"+
                "  top: 20px;"+
                "  right: 0px;"+
                "  position: absolute;"+
                "  width: 510px;"+
                "}"+
                "#facebookFriendsChecker button {"+
                "  cursor: pointer;"+
                "  margin: 5px;"+
                "}")
    ffc.innerHTML = "<h2>Facebook Friends Checker greasemonkey script.</h2>"+
                    "<div id=\"RemovedFriends\">"+
                    "  <h3>The following people are no longer friends with you;</h3>"+
                    "  <div id=\"removedFriends\"></div>"+
                    "  <button id=\"button\">Click to hide this</button>"+
                    "</div>"+
                    "<div id=\"Explanation\">"+
                    "  <p>A person might be showing here for a number of reasons;</p>"+
                    "  <ul>"+
                    "    <li>They may have removed you as a friend</li>"+
                    "    <li>You may have removed them as a friend</li>"+
                    "    <li>They may have deactivated their Facebook account</li>"+
                    "    <li>They may have blocked you completely.</li>"+
                    "    <li>They may have rejected your friend request.</li>"+
                    "  </ul>"+
                    "  <p>You can change the settings for how often this script checks your friends by <a id=\"changeSettings\" href=\"#\">clicking here.</a></p>";
    foo.insertBefore(ffc, foo.firstChild);
    document.getElementById("changeSettings").addEventListener('click', changeTime, false)
    document.getElementById("button").addEventListener(
      'click',
      function() {
        document.getElementById("facebookFriendsChecker").style.display = "none";
        GM_setValue(facebookID + " ex friends", "({})")
      },
      false)
  }
}

function changeTime() {
  var time = prompt("Enter time interval to check for removed friends in hours:",GM_getValue("check time", 2));
  if (time != null && time != "") {
    GM_setValue("check time", parseInt(time));
  }
}