Home » Favelets

Favelets

Project
favelets/bookmarklets to autoincrement/autodecrement number in current URL
Version
4/16/2005
Author
Matthew van Eerde

Purpose

Suppose you're looking at
http://channel9.msdn.com/ShowPost.aspx?PostID=51329
and want to see what post was posted just before, or just after.
You can manually change the number in the URL - or you can use these favelets.
These work generally on any URL with a number in it.

Installation

Either - drag/drop one of these onto your Links toolbar (for IE) or your Bookmarks toolbar (for Firefox) or as appropriate
Hmm... drag/drop works if you save the file locally, but not on any blog I've tried...

Or - copy a favelet url from THE FAVELETS below (they start with javascript:)
Make a new favorite/bookmark (URL doesn't matter, you'll change it soon)
Rename it to "Next" or "++" to taste.
Edit the properties of the favorite/bookmark (how depends on your browser)
Paste the favelet url over whatever you used.
Note that IE will give you a "javascript: is not a registered protocol" warning - this is normal.

Documentation

What is the number before 100? Sometimes it's 99, sometimes it's 099, depending on the site. The "Previous" favelet comes in two flavors - preserve or destroy leading zeros.

The Favelets

Note the URLs should be one, long line. Most browsers won't accept multiline URLs. If your display word-wraps the URLs make sure they are complete when you paste. They all end in void(1);

Next
javascript: var l = document.location; var h = l.href; if (/^(.*)\?PostID=(\d+)(#\d+)?$/.test(h)) { var i = RegExp.$2 * 1 + 1; l.href = RegExp.$1 + "?PostID=" + i + "#" + i; } else if (/^(.*\D0*?)((09\d*)|([1-9]\d*))(.*)$/.test(h)) { l.href = RegExp.$1 + (RegExp.$2 * 1 + 1) + RegExp.$5; } else { alert("?"); } void(1);
Previous
javascript: var l = document.location; var h = l.href; if (/^(.*)\?PostID=(\d+)(#\d+)?$/.test(h)) { var i = RegExp.$2 * 1 - 1; l.href = RegExp.$1 + "?PostID=" + i + "#" + i; } else if (/(.+\D)(\d+)(.*)/.test(h)) { l.href = RegExp.$1 + (RegExp.$2 - 1) + RegExp.$3; } else { alert("?"); } void(1);
Previous: preserve leading zeros
javascript:function z(a){return((""+a).charAt(0)=="9"?"0":"")+a;}var l=document.location;var h=l.href;if(h=/^(.*)\?PostID=(\d+)(#\d+)?$/.test(h)?RegExp.$1+"?PostID="+(RegExp.$2-1)+"#"+(RegExp.$2-1):/(.+\D0*)([1-9]\d*)(.*)/.test(h)?RegExp.$1+z(RegExp.$2-1)+RegExp.$3:alert("?")){l.href=h;}void(1);

Unwrapped Versions

Next

javascript:
var l = document.location;
var h = l.href;
if (/^(.*)\?PostID=(\d+)(#\d+)?$/.test(h))
{	var i = RegExp.$2 * 1 + 1;
	l.href = RegExp.$1 + "?PostID=" + i + "#" + i;
} else if (/^(.*\D0*?)((09\d*)|([1-9]\d*))(.*)$/.test(h))
{	l.href = RegExp.$1 + (RegExp.$2 * 1 + 1) + RegExp.$5;
} else
{	alert("?");
}
void(1);

Previous

javascript:
var l = document.location;
var h = l.href;
if (/^(.*)\?PostID=(\d+)(#\d+)?$/.test(h))
{	var i = RegExp.$2 * 1 - 1;
	l.href = RegExp.$1 + "?PostID=" + i + "#" + i;
} else if (/(.+\D)(\d+)(.*)/.test(h))
{	l.href = RegExp.$1 + (RegExp.$2 - 1) + RegExp.$3;
} else
{	alert("?");
}
void(1);

Previous: preserve leading zeros

javascript:
function z(a)
{	return
		(	("" + a).charAt(0) == "9" ?
				"0" :
				""
		) +
		a;
}
var l = document.location;
var h = l.href;
if (h =
	/^(.*)\?PostID=(\d+)(#\d+)?$/.test(h) ?
		RegExp.$1 + "?PostID=" + (RegExp.$2 - 1) + "#" + (RegExp.$2 - 1)
		:

	/(.+\D0*)([1-9]\d*)(.*)/.test(h) ?
		RegExp.$1 + z(RegExp.$2 - 1) + RegExp.$3
		:

		alert("?")
)
{	l.href = h;
}
void(1);
Hosted by www.Geocities.ws

1