// ==UserScript==
// @name           Increase/decrease URL
// @namespace      http://www.lysator.liu.se/~jhs/userscript
// @description    Drops big chunks of signatures/poster stats in phpBB forums
// @include        *.jpg
// @include        *.png
// ==/UserScript==

alert("!");

(function()
{
  function detectKey( e )
  {
    var keyCode, keyChar;
    if( !e ) e = window.event;
    keyCode = e.keyCode || e.which;
    keyChar = String.fromCharCode( keyCode );
    if( (keyChar == ",") || (keyCode == 37)) { return add(); } 
    if( (keyChar == ".") || (keyCode == 39)) { return sub(); }
  }

  document.onkeypress = detectKey;

  function add( i )
  {
    var u, n, l;
    with( location )
    {
      u=(/(.*\D)(\d+)(\D*)/).exec(href);
      if(u)
      {
	n=u[2];
	l=n.length;
	n=String(parseInt(n,10)+(i||1));
	if(/^0/.test(u[2]))
	  while(n.length<l)
	    n='0'+n;
	u[2]=n;
	u[0]='';
	href=u.join('');
	return false;
      }
    }
    return true;
  }

  function sub( i )
  {
    with( location )
    {
      u=(/^(.*\D)(0*[1-9]\d*)([^1-9]*)$/).exec(href);
      if(u)
      {
	n=u[2];
	l=n.length;
	n=String(parseInt(n,10)-(i||1));
	if(/^0/.test(u[2]))
	  while(n.length<l)
	    n='0'+n;
	u[2]=n;
	u[0]='';
	href=u.join('');
	return false;
      }
    }
    return true;
  }

  function get( path )
  {
    var type = XPathResult.ORDERED_NODE_SNAPSHOT_TYPE;
    var nodes = document.evaluate( path, document.body, null, type, null );
    var result = new Array( nodes.snapshotLength );
    for( var i=0; i<result.length; i++ )
      result[i] = nodes.snapshotItem( i );
    return result;
  };

  function purge( c, re )
  {
    var divs = get( '//span[@class="'+c+'"]' ), div, i, m;
    for( i=0; i<divs.length; i++ )
      with( div=divs[i] )
	if( m = re.exec( innerHTML ) )
	{
	  innerHTML = innerHTML.substr( 0, m.index );
	  while( nextSibling )
	    parentNode.removeChild( nextSibling );
	}
  };
})();

