// WoD-Lager-Sorted-Link user script
// version 0.0.2
// 2009-09-04
// Copyright (c) 2009, Daniel Hohenberger
// Released under the GPL license
// http://www.gnu.org/copyleft/gpl.html
//
// --------------------------------------------------------------------
//
// This is a Greasemonkey user script.  To install it, you need
// Greasemonkey: http://www.greasespot.net/
// Then restart Firefox and revisit this script.
// Under Tools, there will be a new menu item to "Install User Script".
// Accept the default configuration and install.
//
// To uninstall, go to Tools/Manage User Scripts,
// select "WoD-Lager-Sorted-Link", and click Uninstall.
//
// --------------------------------------------------------------------
//
// ==UserScript==
// @name          WoD-Lager-Sorted-Link
// @namespace     http://hd42.de/wod
// @description   Fuegt einen Link zum Lager, sortiert nach "Gefunden", hinzu
// @include         http*://*world-of-dungeons.*/wod/*
// ==/UserScript==
  
//<form method="post" accept-charset="UTF-8" name="the_form" action="/wod/spiel/hero/items.php">
//<input class="table_hl" type="submit" value="Gefunden" name="ITEMS_LAGER_DO_SORT[9_DESC_PAGE_1]"/>
var allLinks = document.getElementsByTagName('a');
addSortedLink('/wod/spiel/hero/items.php?menukey=hero_storage',
	'ITEMS_LAGER_DO_SORT[9_DESC_PAGE_1]',
	'(Gef.)');
addSortedLink('/wod/spiel/hero/items.php?menukey=hero_group_cellar&view=groupcellar_2',
	'ITEMS_GROUPCELLAR_DO_SORT[6_DESC_PAGE_1]',
	'(Alter)');
addSortedLink('/wod/spiel/hero/items.php?menukey=hero_group_treasure&view=groupcellar',
	'ITEMS_GROUPCELLAR_DO_SORT[6_DESC_PAGE_1]',
	'(Alter)');

function addSortedLink(href, sortKey, text){
	var found = false;
	for (var i = 0; (i < allLinks.length) && !found; i++) {
		var thisLink = allLinks[i];
	  if(thisLink.href.indexOf(href)!=-1){
	    found = true;
			var newLink = document.createElement('a');
	    newLink.setAttribute('class', thisLink.className);
	    newLink.setAttribute('onclick', thisLink.getAttribute('onclick'));
	    newLink.setAttribute('href', thisLink.href+'&'+sortKey+'=1');
	    newLink.appendChild(document.createTextNode(text));
	    newLink.style.display = 'inline';
	    thisLink.style.display = 'inline';
	    thisLink.style.paddingRight = '0px';
	    thisLink.parentNode.appendChild(newLink);
		  thisLink.parentNode.style.whiteSpace = 'nowrap';
		}
	}
}

