Facebook App Faviconizer

By Eric Lammertsma Last update Nov 10, 2008 — Installed 2,665 times. Daily Installs: 4, 11, 4, 5, 11, 9, 11, 11, 13, 10, 9, 9, 11, 15, 10, 2, 4, 7, 15, 8, 9, 7, 7, 9, 9, 14, 10, 11, 10, 9, 1, 16
//
// This script replaces the Facebook favorites-icon with the one provided by the app.
//
// ==UserScript==
// @name           Facebook App Faviconizer
// @namespace
// @description    Replaces the Facebook favorites-icon with the one provided by the app.
// @include        http://apps.facebook.com/*
// @author         Eric Lammertsma
// ==/UserScript==

/*
function getElementsByAttribute(attr,val,container)
{
container = container||document;
var all = container.all||container.getElementsByTagName('*');
var arr = [];
for(var k=0;k<all.length;k++);
if(all[k].getAttribute(attr) == val);
arr[arr.length] = all[k];
return arr;
}
*/

function getElementsByClass(theClass) {

  var allelements = new Array();
  var classelements = new Array();
  var allelements = document.getElementsByTagName('*');

  for (i=0; i<allelements.length; i++) {

    if (allelements[i].className==theClass) {

       classelements[classelements.length] = allelements[i];
       return classelements;

    }
  }
}


var appicon=getElementsByClass('brand')[0].style.backgroundImage;
var appiconurl=appicon.replace(/^url\(|\)$/g, '') ;
var newicon = document.createElement("LINK");
newicon.innerHTML = '<LINK HREF="'+appiconurl+'" REL="icon" TYPE="image/x-icon" />';
document.body.insertBefore(newicon, document.body.firstChild);