Bitly Link Info

By Jauder Ho Last update Oct 30, 2008 — Installed 101 times.

There are 3 previous versions of this script.

// ==UserScript==
// @name           Bitly Link Info
// @namespace      http://userscripts.org/users/60534
// @description    Shows information about all bit.ly urls found on Twitter and other sites.
// @include        http://twitter.com/*
// @include        http://friendfeed.com/*
// @include        http://identi.ca/*
// @include        http://www.facebook.com/*
// @include        http://www.flickr.com/*
// @author         jauderho (orignial script from thefluffanutta) v0.4
// ==/UserScript==

var links = document.getElementsByTagName('a');
var domParser = new DOMParser();

// find all bitly urls on the page
for (var i=0,j=links.length; i<j; i++) {
  if (links[i].href.indexOf('http://bit.ly/') == 0) {
    var code = links[i].href.substring(14);
    getInfo(links[i],code);
  }
}

function getInfo(link, code)
{
  GM_xmlhttpRequest({
   method:"GET",
   url:"http://bit.ly/feed.php?format=json&url=http://bit.ly/"+code,
   headers:{
     "Accept":"text/xml"
   },
   onload:function(response) {
     if (response.status == 200) {
       var json = eval('(' + response.responseText + ')');

       // add target URL as link tooltip
       link.title = "Goes to "+json.shortenedUrl.long;

       // create a link to the stats page for bitly
       var stats = document.createElement('a');
       stats.setAttribute("href", "http://bit.ly/info/"+code);
       stats.setAttribute("title", "Stats for "+json.shortenedUrl.long);
       stats.setAttribute("target", "_blank");
       stats.appendChild(document.createTextNode(json.shortenedUrl.clicks));

       // stuff the new link into the tweet
       var nextNode = link.nextSibling;
       link.parentNode.insertBefore(document.createTextNode(' ['), nextNode);
       link.parentNode.insertBefore(stats, nextNode);
       link.parentNode.insertBefore(document.createTextNode(']'), nextNode);
     }
   }
 });
}