// ==UserScript==
// @name Sinfest prev/next links
// @version 1.1
// @namespace http://www.lysator.liu.se/~jhs/userscript
// @description Adds links the previous and next Sinfest strip by clicking the left/right portion of the present strip, and adds access keys P and N (or . and ,) too for concenience (Alt+* on Windows, Command+* on Mac, Shift+Escape followed by * in Opera).
// @include http://www.sinfest.net/archive_page*
// @include http://www.sinfest.net/*
// ==/UserScript==
function $x( xpath, root )
{
var doc = root ? root.evaluate ? root : root.ownerDocument : document, next;
var got = doc.evaluate( xpath, root||doc, null, 0, null ), result = [];
while( next = got.iterateNext() )
result.push( next );
return result;
}
function link_surrounding_strips()
{
var img = $x( '//img[contains(@src, "comics")]' )[0];
var m = document.createElement( 'map' ); m.name = 'prev-next';
var p = document.createElement( 'area' ); p.shape = 'rect';
var n = document.createElement( 'area' ); n.shape = 'rect';
var w = img.width, W = Math.floor( w/2 ), h = img.height, u;
if( (u = $x( '//a[img[@alt="Previous"]]' )).length )
{
u[0].accessKey = ',';
p.accessKey = 'P';
p.coords = '0,0,'+ W +','+ h;
//p.title = 'Previous strip';
p.href = u[0].href;
m.appendChild( p );
}
if( (u = $x( '//a[img[@alt="Next"]]' )).length )
{
u[0].accessKey = '.';
n.accessKey = 'N';
n.coords = W +',0,'+ (--w) +','+ h;
//n.title = 'Next strip';
n.href = u[0].href;
m.appendChild( n );
}
document.body.appendChild( m );
img.setAttribute( 'usemap', '#prev-next' );
}
function hook_up_strip()
{
var i = $x( '//img[contains(@src, "comics")]' );
if( !i.length ) return;
if( i[0].width * i[0].height > 1e5 )
link_surrounding_strips();
else
i[0].addEventListener( 'load', link_surrounding_strips, false );
}
hook_up_strip();