Mininova IMDb link

By lazyttrick Last update May 31, 2009 — Installed 1,340 times. Daily Installs: 1, 5, 1, 0, 0, 4, 3, 2, 3, 3, 1, 3, 5, 4, 1, 1, 4, 2, 7, 1, 0, 5, 2, 2, 0, 3, 1, 2, 1, 4, 1, 0

There are 1 previous version of this script.

// ==UserScript==
// @name           Mininova IMDb link
// @namespace      meh
// @description  Search link to IMDb movie page and open in new tab if found.
// @include        http://www.mininova.org/*
// @include        http://thepiratebay.org/*
// ==/UserScript==

var icon = createElement('img', {style:'display:inline; padding-left:5px'});
icon.src = "data:image/gif,GIF89a%10%00%0D%00%A2%00%00%FF%FF%FF%FF%FF%00%FF%CCf%FF%CC%00%04%04%04%00%00%00%00%00%00%00%00%00!%F9%04%05%14%00%00%00%2C%00%00%00%00%10%00%0D%00%00%039%08%BA%DC%1B0J%F8%84%BD%D8%06%10%C4%F0%E0'j%16!%98%A8y~%60%8A%9E'%C1%C2o%0D%7B6a%0Ez%06%FE%98%8F%EC%C7%1A%09%01*b%86%B0%D09%9FN%87%B4%91%00%00%3B";



xp('//a').forEach(
	function(a){
		var img = icon.cloneNode(false);
		
		if(location.href.search(/thepiratebay\.org/)>-1 && a.getAttribute('href').search(/torrents\.thepiratebay\.org\/\d+/) > -1 )
		{
			var td = a.parentNode;
			try{
				a = createElement('a',{href:'javascript:void(0)'}, 'click request false');
				a.appendChild(img);
				td.appendChild(a);
			}catch(e){
			}
		}
		else if(location.href.search(/mininova\.org/)>-1 && a.getAttribute('href').search(/\/tor\/\d+/) > -1 )
		{
			var td = a.parentNode;
			try{
				a = createElement('a',{href:'javascript:void(0)'}, 'click request false');
				img.setAttribute('style', 'float:right;'+img.getAttribute('style'));
				a.appendChild(img);
				td.insertBefore(a,td.firstChild);
			}catch(e){
			}
		}
	}
);



function request(evt)
{
	var url, url2, loading, a, par;

	evt.target.parentNode.removeEventListener('click',request,false);
	loading = createElement('span', {style:'display:inline; padding-left:5px'}, null, 'searching...');
	evt.target.parentNode.appendChild(loading);

	url2=null;
	if(location.href.search(/thepiratebay\.org/)>-1)
		par = evt.target.parentNode.parentNode.parentNode;
	else if(location.href.search(/mininova\.org/)>-1){
		par = evt.target.parentNode.parentNode;
		loading.setAttribute('style', 'float:right;'+loading.getAttribute('style'));
	}
	a = getTag('a',par);
	
	for(var i=0; i<a.length; i++){
		if(location.href.search(/thepiratebay\.org/)>-1 && a[i].getAttribute('href').search(/\/torrent\/\d+/) > -1)
		{
			url2 = a[i].getAttribute('href');
			break;
		}
		else if(location.href.search(/mininova\.org/)>-1 && a[i].getAttribute('href').search(/\/tor\/\d+/) > -1)
		{
			url2 = a[i].getAttribute('href');
			break;
		}
	}
	
	url = location.href.match(/^http:\/\/(www\.)?[^\.]+\.org/)[0] + url2;
	
	GM_xmlhttpRequest({
		method: 'GET',
		url: url,
		onload: function(resp) {
			try{
				url2 = resp.responseText.match(/http\:\/\/(www\.)?imdb.com\/title\/tt\d+/)[0];
			}catch(e){
				evt.target.parentNode.removeChild(evt.target);
				loading.innerHTML = "IMDb link not found.";
				return;
			}
			GM_openInTab(url2);
			evt.target.parentNode.addEventListener('click',request,false);
			loading.parentNode.removeChild(loading);
		}
	});
}


function createElement(type, attrArray, evtListener, html)
{
	var node = document.createElement(type);

	for (var attr in attrArray) if (attrArray.hasOwnProperty(attr)){
		node.setAttribute(attr, attrArray[attr]);
	}

	if(evtListener){
		var a = evtListener.split(' ');
		node.addEventListener(a[0], eval(a[1]), eval(a[2]));
	} 
 
	if(html) 
		node.innerHTML = html;
	
	return node;
}

function getId(id, parent){
	if(!parent)
		return document.getElementById(id);
	return parent.getElementById(id);	
}

function getTag(name, parent){
	if(!parent)
		return document.getElementsByTagName(name);
	return parent.getElementsByTagName(name);
}

function xp(p, context) {
  if (!context) 
	context = document;
  var i, arr = [], xpr = document.evaluate(p, context, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
  for (i = 0; item = xpr.snapshotItem(i); i++) 
	arr.push(item);
  return arr;
}

//TODO:  print debugObj with added variables
function debug(str)
{
	var d = document.getElementById('debugg');
	if(!d){
		d = document.createElement('textarea');
		d.setAttribute('id','debugg');
		d.setAttribute('style',"height:200px; width:50%; position:fixed; bottom:0px; right:0px; z-index:1000;");
		document.body.appendChild(d);
	}
	d.innerHTML += '\n'+str;
	d.scrollTop = d.scrollHeight;
}