// ==UserScript==
// @name           Amazon Geizhals.at Suche
// @namespace      http://masterbootrecord.de
// @include        http://www.amazon.de*
// ==/UserScript==

// search the heading / product name
var results =
   document.evaluate("//span[@id='btAsinTitle']",
                     document, null,
                     XPathResult.FIRST_ORDERED_NODE_TYPE,
                     null);
var divnode = results.singleNodeValue;
var productname = divnode.innerHTML;
var space = document.createTextNode(' ');
divnode.insertBefore(space,
                     divnode.lastChild.nextSibling);

// create a linebreak before the froogle link
var umbruch = document.createElement('br');

// insert the created linebreak
divnode.insertBefore(umbruch,
                     divnode.lastChild.nextSibling);

// create a new link
var geizhalslink = document.createElement('a');

// set the name of the link
geizhalslink.innerHTML = 'Preis bei Geizhals.at nachschlagen';

// set the link to open up in a new window/tab
geizhalslink.target = '_blank';

divnode.insertBefore(geizhalslink, divnode.lastChild.nextSibling);

if(productname.indexOf("(") > 3)
	productname = productname.substring(0, productname.indexOf("("));
if(productname.substring(productname.length-1,productname.length) == ' ')
    productname = productname.substring(0,productname.length-1);
if(productname.lastIndexOf(" ") > 3)
	productname = productname.substring(0, productname.lastIndexOf(" "));

geizhalslink.href = "http://geizhals.at/deutschland/?fs="+productname+"&x=0&y=0&in=";


