Facebook Blocked Applications Header

While working on the next version of my Facebook Profile Cleaner, I noticed something that I was doing. Every time I would log into Facebook, I would have 3-5 new application invites. Personally, I don’t care too much about them (if you didn’t know already). I set out to see if I could come up with a way to automatically block them upon sign on/request.

That task seemed pretty easy, but it didn’t turn out to be. First of all, Facebook hides their “Block Application” button on you. The first place you see it is on the application’s page itself. Second, on the user’s request page it only shows an add and ignore. If you click ignore, it ignores that specific request, not any future ones. This gets real annoying when a ton of your friends decide to add (and send you requests) of the same application. And third, I was worried that maybe I would want to remove a block later. However Facebook was kind enough to provide a page to “remove” blocked applications. By going to http://facebook.com/privacy.php?view=platform&tab=all, the second half of the page will list applications you have blocked. Notice they are listed by the order they were blocked; most recently blocked will be on the bottom.

Facebook Blocked Applications

That being said, I set out to actually block each application invite I get. After a few hours here and there, I finally got it fully working. The code should be clean enough for anyone interested enough to walk though. But note that if you just want the application and don’t care for the actual code, then just install it and be on your merry way :).

If you have any suggestions, comments, or concerns, be sure to comment below.

To use this script, you need Greasemonkey addon. Once you have it, just go here and click install: http://userscripts.org/scripts/show/12393 or http://karbassi.com/scripts/greasemonkey/autoblockfacebookapps10.user.js.

Here’s the code:

// Auto-Block Facebook Apps
//
// Version 1.0
//
// Date Written: 2007-09-18
// Last Modified: 2007-09-19 12:51 PM (12:51)
//
// (c) Copyright 2007 Ali Karbassi.
// Released under the GPL license
// http://www.gnu.org/copyleft/gpl.html
//
// --------------------------------------------------------------------
//
// This is a Greasemonkey user script.
//
// To install, you need Greasemonkey: http://greasemonkey.mozdev.org/
// Then restart Firefox and revisit this script.
// Under Tools, there will be a new menu item to "Install User Script".
// Accept the default configuration and install.
//
// To uninstall, go to Tools/Manage User Scripts,
// select "Auto-Block Facebook Apps", and click Uninstall.
//
// --------------------------------------------------------------------
//
// WHAT IT DOES:
// After the facebook profile page is loaded, it finds all the
// applications that your friends have invited you to and blocks them.
// Do not worry though, you can go to
// http://facebook.com/privacy.php?view=platform&tab=all and unblock
// them
//
// NOTE: This does not alter, delete, edit, add, or anything else to
//       your facebook profile. Just remove or disable this script and
//       everything will be displayed the same as it used to
// --------------------------------------------------------------------
//
// ==UserScript==

// @name        Auto-Block Facebook Apps 1.0
// @author      Ali Karbassi
// @namespace   http://www.karbassi.com
// @description This script will block app invites sent to you by friends. After the facebook profile page is loaded, it finds all the applications that your friends have invited you to and blocks them. Do not worry though, you can go to http://facebook.com/privacy.php?view=platform&tab=all and unblock them.
// @include     http://facebook.com/home.php*
// @include     http://*.facebook.com/home.php*
// @include     http://facebook.com/reqs.php*
// @include     http://*.facebook.com/reqs.php*
// ==/UserScript==

// Find Subdomain
var subDomain = getSubDomain();

// Get links on the front page/request page
var anchors = document.getElementsByTagName('a');
var appReqExp = /reqs\.php#confirm_(\d*)_(.*)/;

for( var i = 0; i < anchors.length; i++ )
{
  if( appReqExp.exec( anchors[i].href ) )
  {
    prep(RegExp.$1, anchors[i]);
  }
}

// Remove any notifications about apps.
removeNotifications();

// Functions
// PLEASE DO NOT TOUCH IF YOU HAVE NO IDEA WHAT YOU'RE DOING. YOU MIGHT BREAK IT.

// Prepares everything. When things are correct, it calls BlockApp.
function prep(appID, appNode)
{
  var postformMatch = /name="post_form_id" value="(\w+)"/;
  var post_form_id = 0;

  GM_xmlhttpRequest(
    {
      method: 'GET',
      url: 'http://www.facebook.com/apps/block.php?id=' + appID + '&action=block',
      headers:
      {
        'User-Agent': window.navigator.userAgent,
        'Accept': 'text/html',
      },
      onload: function(responseDetails)
      {
        if( (responseDetails.status == 200) && (responseDetails.responseText.indexOf('This will not prevent you from seeing') != -1) )
        {
          // Show that we are working on it.
          appNode.removeAttribute('href');
          appNode.innerHTML = 'Reading confirmation page...';

          postformMatch.exec( responseDetails.responseText );

          // Calls function to block the app
          BlockApp(RegExp.$1, appID, appNode);
        }
      }
    }
  );
}

function BlockApp(post_form_id, appID, appNode)
{
  GM_xmlhttpRequest(
    {
      method: 'POST',
      url: 'http://' + subDomain + 'facebook.com/apps/block.php?id=' + appID + '&action=block',
      headers:
      {
        'User-Agent': window.navigator.userAgent,
        'Accept': 'text/xml',
        'Content-Type': 'application/x-www-form-urlencoded',
      },
      data:'post_form_id=' + post_form_id + '&save=1',
      onload: function (responseDetails)
      {
        if( (responseDetails.status == 200) && (responseDetails.responseText.indexOf('You have blocked this application') != -1) )
        {
          appNode.innerHTML = 'App Blocked!'
          appNode.href = 'http://facebook.com/reqs.php';
        }
      },
      onerror: function (responseDetails)
      {
        appNode.removeAttribute('href');
        appNode.innerHTML = 'App Block failed!';
      }
    }
  );
}

function removeNotifications()
{
  var inputs = document.getElementsByTagName('input');
  for (var i = 0; i < inputs.length; i++)
  {
    if( inputs[i].value == 'Ignore' )
    {
      for( var j = 0; j < inputs[i].attributes.length; j++)
      {
        if( (inputs[i].attributes[j].nodeName == 'onclick') && (inputs[i].attributes[j].nodeValue.indexOf('click_add_platform_app') != -1) )
        {
          var js = (inputs[i].attributes[j].nodeValue).split(' ');
          js.shift();
          js = js.join(' ');
          location.href = 'javascript:' + js;
        }
      }
    }
  }
}

function getSubDomain()
{
  var subDomainRegExp = /http:\/\/(.*\.)facebook\.com/;
  var subDomain = '';
  if (subDomainRegExp.exec(document.location) != 0)
  {
    subDomain = RegExp.$1;
  }
  return subDomain;
}
  • Cool.

    Did you just figure all of this removal code out by looking at the HTML and DOM for the relevant facebook pages, or did it require some knowledge of the facebook APIs (which I know very little about, so that may be a stupid question)?

    I feel your pain on this whole Facebook as an application platform issue. I sit somewhere in the middle I think. It's a really great idea, and maybe it will make Zuckerberg some money - but almost every application I've seen and been "invited" to start using is total crap, and now the usefulness of Facebook has been severely diluted. For instance, a lot of people have the "Funwall" application now - so now there are two walls to write on on their profile, and most people don't even scroll all the way down to see the original wall. Lame.

    Ah well. I still mostly use Facebook to check peoples contact info when I need it. (See, now there is a good facebook app idea - one that prints out a report of all of your friends contact info in a table format - email, phone, etc).

    I've always wanted to take a look at greasemonkey - it's like the last "nerd must have" firefox extension that I don't have. :-) Maybe this will be the spark I need.
  • @Adam:

    Well, I knew that the process that it took to block one application, so I figured out a way to do it automatically.

    Basically, I opened up the source, figured out where it was going, and well, did it. I'm not the best at explaining things, that's why the code is up there.
  • Thank you soooooo much.
    I have been incredibly frustrated by the plethora of friends who send me such absolute crap.
    I am a long time web developer and believe facebook is seriously wicked, however I fear it is in jeopardy of becoming new form of dumb chain.
    I have been toying with creating my own facebook app and an idea struck me just this evening.

    How about the "get a life" app which politely advises friends stop sending you stupid crap and do soemthing worhtwhile

    I found a great post on youtube which would be a great URL to autosend on block.

    http://www.youtube.com/watch?v=cxJIQ60KiuA
    damn funny

    peace and thanks again
  • Thank you SO much for this add-on. I...I love you...
  • I found this via a Google search, and I just want to thank you so much for providing a solution for the most annoying aspect of "new Facebook." Finally!
  • That is such a brilliant solution, thanks for that. I love facebook except for the application requests...nice work.
  • M
    AWESOME! I'm going to friend you just for this. Or not.

    Anyways, I just keep facebook so that old friends can find me, since I share a name with a very famous film producer and am un-googleable unless you know my online nick-name.

    I was considering closing my Facebook account before I found this!
  • Andy
    That's absolutely fabulous - thanks so much, I now have a very tidy facebook, just the way I like it! Best wishes, Andy.
  • Will
    I tried to install the code but I cant. Im using Internet explorer..
  • Brilliant! Now I don't have to waste time going through the rigmarole of clicking on the reject button over and over again. Thanks a lot! :)
  • Othman
    Man, this is just awesome
    Good job, thanx!

    Duke of Fleed
  • There's nothing I can say to emphasize this any better: THANK YOU!
  • I love you in a way that only an expletive can describe as an adjective.

    Thanks for this fantastic script!
  • Cynthia Sanderson
    I don't want to block all apps, is that possible?
  • Gail
    Thank you sooo much!!
    you have saved my sanity!!
    (just one question, if I log into FB from a computer that doesn't run on Mazilla... will i get invites again??
    : )
  • @Gail: You will get invites only if the application isn't already blocked. I would suggest not clicking "Ignore" and letting the program block it next time you log in with your Firefox browser.
  • Words cannot express my gratitude for this.
    Im so happy now that I can use FB and not be barraged with silly nonsense apps .

    Your app gets a big THANKS from me

    John Piercy
  • CJ
    Hi Ali

    Great script. Will you be updating it to accomodate the changes FB have made?

    They now have BLOCK on the same page as the notification. It should simplify your extension?
  • CJ: I took a look at the updates and nothing new for me to do. They just did what I did, but moved it to a notification/request page. My script will still work and no real updates is needed.

    We'll see when they'll have an option to actually not allow any requests for new apps.
  • squiggly
    YOU ARE MY HERO. Thank you. You took my pain away.
  • will not except any knind od apps aaplication on my space. put a block on it please. only on my space
  • steve jones
    Ali Karbassi
    not sure if these apps work anymore since the recent update
    any chance of a revived version that just auto blocks all stupid invites
    so i dont have to manually ignore my self ?
  • meza
    I've just finished a firefox plugin, which hides all application posts.

    I'll try to implement this block stuff and BLOCK ALL over ajax :)

    The plugin will be shortly public
blog comments powered by Disqus