// ==UserScript==
// @name          digg to Spurl
// @namespace     http://loucypher.wordpress.com/
// @include       http://digg.com/*
// @include       http://www.digg.com/*
// @description	  Adds links to post story links to Spurl.net
// ==/UserScript==

var diggEm = document.evaluate('//li[@class="digg-it"]',
  document, null, 6, null);

if(!diggEm.snapshotLength) return;

function spurlIt(idx) {
  var spLink = 'http://www.spurl.net/spurl.php?v=3&url=';
  var stLink = diggEm.snapshotItem(idx).parentNode.parentNode
    .getElementsByTagName('h3')[0].getElementsByTagName('a')[0];
  var sTitle = stLink.lastChild.nodeValue;
  var sDesc = stLink.parentNode.parentNode.getElementsByTagName('p')[1].firstChild.nodeValue;

  var mLink = document.createElement('a');
  mLink.href = spLink + encodeURIComponent(stLink) + '&title=' + encodeURIComponent(sTitle) + '&blocked=' + encodeURIComponent(sDesc);
  mLink.target = '_blank'; //optional
  mLink.appendChild(document.createTextNode('spurl it'));

  var mList = document.createElement('li');
  mList.className = 'digg-it';
  mList.appendChild(mLink);

  diggEm.snapshotItem(idx).parentNode.appendChild(mList);
}

for(var i = 0; i < diggEm.snapshotLength; i++) {
  spurlIt(i);
}

