Source for "digg.licio.us"

By LouCypher
Has 83 other scripts.


// ==UserScript==
// @name          digg.licio.us
// @namespace     http://loucypher.wordpress.com/
// @include       http://digg.com/*
// @include       http://www.digg.com/*
// @description	  Adds links to save a Digg story to del.icio.us
// ==/UserScript==

var diggEm = document.evaluate("//li[@class='digg-it'] | " +
                               "//li[@class='dugg-it'] | " +
                               "//li[@class='undigg-it']",
                               document, null, 6, null);

if (!diggEm.snapshotLength) return;

var diggIt;
for(var i = 0; i < diggEm.snapshotLength; i++) {
  diggIt = diggEm.snapshotItem(i);
  diggIt.style.cssFloat = "none";
  addSaveIt(diggIt.parentNode);
}

function getXPathNode(aXPath) {
  return document.evaluate(aXPath, aContext, null, 0, null).iterateNext();
}

function addSaveIt(aNode) {
  var sLink = aNode.parentNode
                   .getElementsByTagName("h3")[0]
                   .getElementsByTagName("a")[0];
  var sTitle = sLink.textContent;
  var notes = sLink.parentNode.parentNode.getElementsByTagName("p");
  for (var i = 0; i < notes.length; i++) {
    if (!notes[i].hasAttribute("class"))
      var note = notes[i].textContent;
  }

  var list = aNode.appendChild(document.createElement("li"));
  list.className = "digg-it";
  list.style.marginTop = "-1px";

  var link = list.appendChild(document.createElement("a"));
  link.href = "http://del.icio.us/post?v=4" +
              "&url=" + encodeURIComponent(sLink) +
              "&title=" + encodeURIComponent(sTitle) +
              "&notes=" + encodeURIComponent(note);
  link.title = "Save this story to del.icio.us";
  link.appendChild(document.createTextNode("save it"));

  // open in new tab
  link.addEventListener("click", function(e) {
    e.preventDefault();
    GM_openInTab(e.target.href + "&jump=close");
  }, false);

}