Remember links to my hero profile in my hero group wall

By LangLingLung Last update Mar 25, 2008 — Installed 68 times.
// Author 	  Lang ling lung 
// ==UserScript==
// @name          Remember hero profile, for Spirits Group
// @namespace     http://userscript.org
// @description   This script remembers when a user posted their profile in group wall, link to user profile will be replaced with hero profile.
// @include	  http://apps.facebook.com/ability/group
// ==/UserScript==
//
// Use it at your own risk :). 
// It is not fully tested

var allLink, curLink, userID, lastUserID, lastLink;

// Gather all <a href's link, possible there is a better way than this, for example focusing only on comment areas.
// Anyway this one work, though maybe rather slow
allLink = document.evaluate( '//a[@href]', document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);


lastUserID = null;
for (var i = 0; i < allLink.snapshotLength; i++) {
    curLink = allLink.snapshotItem(i);

    // Those link to facebook user page in every post in group wall have this k=100000080, 
    // if the code on facebook changes, this should be changed :)
    if(curLink.href.indexOf('k=100000080')>=0 || curLink.href.indexOf('http://www.facebook.com/profile.php')>=0){
    	userID = curLink.href.split('id='); // Split the userID
	heroID = GM_getValue(userID[1],"Empty"); // Check in persistent database if we have heroID of this user
	if(heroID != "Empty"){
    	   curLink.href = 'http://apps.facebook.com/ability/profile/'+heroID; // Modify the link to userID into heroID
	   lastUserID = null;						      // Avoid reassignment of userID
	} else{
	   lastUserID = userID[1];	// Keep this user ID as new hero, just in case he posted hero profile
	   lastLink   = curLink;
	}
    }
    else
    // If lastUserID is not null, we have new hero
    // Assuming new hero posted profile links, asking for buffs
    // This hero link will be associated with lastUserID and lastLink found 
    if(lastUserID != null && curLink.href.indexOf('http://apps.facebook.com/ability/profile/')>=0){
	newHeroID = curLink.href.split('profile/'); // split the newHeroID
	GM_setValue(lastUserID, newHeroID[1]);
    	lastLink.href = 'http://apps.facebook.com/ability/profile/'+newHeroID[1];
	lastUserID = null; // Avoiding multiple hero profile during raid messages
    }
}