Delicious Keys

By Mike Sugarbaker Last update Oct 25, 2005 — Installed 650 times. Daily Installs: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
/*
Delicious Keys 0.6

version history:
0.1: number keys worked
0.2: i labeled the links because counting them wasn't saving me any time
0.3: i added keys, and ugly labels, for "earlier" and "later"
0.4: hey they changed their code. so i changed mine.
0.5: i changed mine some more so it actually works.
0.6: OMG bugfix! better detection of what page you're on.

(c) Mike Sugarbaker, misuba@gibberish.com
Consider it MIT license. you're welcome
*/
// ==UserScript==
// @name           Delicious Keys
// @namespace      http://www.gibberish.com/hacks/gm/
// @description    On most del.icio.us pages, hit 'Alt + <N>' to go to the Nth link (0 = 10). Also, 'Alt + [' for earlier and 'Alt + ]' for later.
// @include        http://del.icio.us/*
// ==/UserScript==

(function(){
	// first: labels!!
	var thehits = document.evaluate(
		"//h4[@class='desc']/a",
		document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null
	);
	for (var s = 0; s < 10; s++)
	{
		var theitem = thehits.snapshotItem(s);
		theitem.innerHTML = "<b style='color: black;'>" + (s + 1) + ". </b>" + theitem.innerHTML;
	}
	var thepagers = document.evaluate(
		"//p[@class='pager']",
		document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null
	);
	for (var z = thepagers.snapshotLength; z > 0; z--)
	{
		var theitem = thepagers.snapshotItem(z - 1);
		theitem.innerHTML = theitem.innerHTML + " <b>&lt; alt-[ | alt-] &gt;</b>";
	}
	
	var thekeyup = function(e)
	{
		if (e.altKey)
		{
			var t = e.keyCode;
			//alert(t);
			if (t > 47 && t < 58)
			{
				t = (t == 48) ? 10 : t - 48;
				var hitsagain = document.evaluate(
					"//h4[@class='desc']/a",
					document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null
				);
				var thehit = hitsagain.snapshotItem(t - 1);
				window.location.href = thehit;
			}
			else if (t == 219 || t == 221)
			{
				var whichway = (t == 219) ? 1 : -1;
				
				var whereto = window.location.search;
				if (whereto == "" || whereto.indexOf("page=") == -1)
				{
					window.location.search = "?page=2";
				}
				else
				{
					var wheretoaddr = whereto.substring(whereto.indexOf("page=") + 5, whereto.length);
          wheretoaddr = wheretoaddr.replace(/([0-9]+?)*/, "$1");
					if (wheretoaddr != 1 || whichway != -1)
					{
						wheretoaddr = parseInt(wheretoaddr) + parseInt(whichway);
					}
					window.location.search = "?page=" + wheretoaddr;
				}
			}
		}
	};
	
	document.addEventListener("keyup",thekeyup,false);
})();