// ==UserScript==
// @name           Facebook - Add Recent Friends To Mafia Wars
// @namespace      http://facebook.com
// @description    Adds a Mafia Wars link to recently added friends page.  Originally http://userscripts.org/scripts/show/40981.
// @version        1.0
// @date           2009-04-03
// @include        http://*.facebook.com/*friends/?added*
// ==/UserScript==

(function() {
    var lastid = "";

    // Get all of the links on the page.
    var userids=document.getElementsByTagName('a');
    for( idx=0; idx < userids.length; idx++ )
    {
        // Look for links to the user's profile and extract their user id from that.
        var re = new RegExp("http://www.facebook.com/profile.php.id=([0-9]+)$");
        var id = re.exec(userids[idx]);

        // If the link was to a user's profile and this is the first of the two links 
        // on the friend page then add a new span to go under the picture.  The second
        // link is in the person's name.
        if ( id != null && id[1] != lastid )
        {
            lastid = id[1];
            var span = document.createElement("span");
            span.innerHTML = "[<a href='http://apps.facebook.com/inthemafia/status_invite.php?from=" + id[1] + "' target='_blank'>Add to Mafia Wars</a>]";
            userids[idx].appendChild(span);
        }
    }
})();


