topical media & game development
mashup-flickr-09-jumptoflickrpage.user.js / js
// ==UserScript==
// @name Jump to Flickr Page
// @namespace http://www.dopiaza.org/flickr/greasemonkey/
// @description Jump to a specific Flickr page in a paginated set of pages.
// @include http://www.flickr.com/*
// @include http://flickr.com/*
// ==/UserScript==
var paginators = document.evaluate(
"//div[@class='Paginator']",
document,
null,
XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
null);
for (var i = 0; i < paginators.snapshotLength; i++)
{
var paginator = paginators.snapshotItem(i);
// Place the text box immediately before the "Next" item, which is the last
// non-text element in the paginator (There is whitespace after it, which shows
// up as a text node). It may be an anchor or a span, depending on whether we are
// at the last page or not.
var paginatorChildren = paginator.childNodes;
var nextElement;
for (var j = paginatorChildren.length - 1; j >= 0; j--)
{
if (paginatorChildren[j].nodeType == 1) // Element Node
{
nextElement = paginatorChildren[j];
break;
}
}
var inputBox = document.createElement('input');
inputBox.setAttribute("type", "text");
inputBox.setAttribute("size", "3");
paginator.insertBefore(inputBox, nextElement);
inputBox.addEventListener('keypress', function(evt)
{
var keyVal = evt.which;
var key = String.fromCharCode(keyVal);
if (key == '\r')
{
var pageNum = evt.target.value;
// So, where are we now?
var loc = window.location.href;
// Remove any existing page number
loc = loc.replace(/page\d+(\/)?
(C) Æliens
20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.