// ==UserScript==
// @name           isohunt In NetFlix
// @namespace      http://www.rhyley.org/gm/
// @description    Add an isohunt search link to every movie link in NetFlix
// @include        http://*.netflix.com/*
// @include        http://netflix.com/*
// ==/UserScript==

var allLinks, thisLink, a, d;
var links = new Array();
allLinks = document.evaluate(
    "//a[contains(@href,'MovieDisplay?movieid=')]",
    document,
    null,
    XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
    null);
    
for (var i = 0; i < allLinks.snapshotLength; i++) {
    thisLink = allLinks.snapshotItem(i);
    title = thisLink.innerHTML;
    links[i] = "http://isohunt.com/torrents.php?ihq=" + encodeURIComponent(title) + "&ihs1=2&iho1=d";
    a = document.createElement('a');
    a.setAttribute('href', links[i]);
    a.setAttribute('target', "_blank");
    a.setAttribute('title', title + " on isohunt");
    a.setAttribute('style', "color:#006 !important;text-size:.9em;font-weight:bold");
    
    a.innerHTML = '[i]';

    thisLink.parentNode.insertBefore ( a, thisLink.nextSibling);
    thisLink.parentNode.insertBefore ( document.createTextNode(" "), thisLink.nextSibling);
}

unsafeWindow.openAll = function(){
	for (i in links) {
		window.open(links[i]);
	}
}

d = document.createElement('div');
d.setAttribute('style', "z-index:999; position:fixed; top:1em; left:1em; border:1px solid #777;background:rgb(250, 234, 197);color:#600;padding:.3em;");
d.innerHTML = '<a href="javascript:openAll();" title="open allconsuming links for *all* movies on this page">[All]</a>';
document.getElementsByTagName('body')[0].appendChild(d);
