Saturday, March 3, 2012

Torrentz.eu for Your Mom


// 2012-03-03
// By bfred.it
// Released under the GPL license
// http://www.gnu.org/copyleft/gpl.html
//
// internal name: Quick Torrentz
//
// ==UserScript==
// @name          Torrentz.eu for Your Mom
// @description   Automatically adds direct .torrent and magnet links on Torrentz.eu — So easy your mom could use it. Tested in Firefox and Chrome.
// @include       *://torrentz.*
// @match         http://torrentz.eu/*
// @match         http://torrentz.com/*
// @match         https://torrentz.eu/*
// @match         https://torrentz.com/*
// @version       1.86
// @screenshot    http://f.cl.ly/items/1k3U0D2i043l0g450B1n/Torrentz%20update.png
// @screenshot    http://cl.ly/6kwz/b.png
// ==/UserScript==

(function () {

 //"hack" for chrome by mathiasbynens
 //https://gist.github.com/1143845
 window.unsafeWindow || (
  unsafeWindow = (function() {
   var el = document.createElement('p');
   el.setAttribute('onclick', 'return window;');
   return el.onclick();
  }())
 );
 
 var $ = unsafeWindow.jQuery,
 css = [
 ".qt_links a{display: inline-block; width:9px ; height: 18px; margin-left: 4px; text-align: center; -webkit-border-radius: .3em; -moz-border-radius: 3px; line-height:1em; text-decoration:none !important; vertical-align:top;}",
 ".qt_magnet,.qt_cache.Torcache{width:18px !important;}",
 ".qt_magnet:before,.qt_cache.Torcache:before{content:'⬇'; width: 100%; text-align:center; margin-top:-2px; color: white; font-size: 18px;}",
 ".qt_cache:nth-child(n+3){position: absolute; display: none}",
 "dl:hover .qt_cache{display: inline-block}",
 ".qt_cache.Zoink{right: -13px;}",
 ".qt_cache.Torrage{right: -26px;}",
 
 ".qt_magnet{background: #FFB090; }",
 ".qt_cache{background: #336699; } ",
 ".qt_links a:hover{background: #FF5511;}",
 
 ".qt_separator{color:transparent !important; cursor:default !important;}",
 "div.results > dl > dt {width: 648px !important; } ",
 "div.results > dl > dd{width: 350px !important;} ",
 ".qt_links{float: left; width: 70px; position:relative; top: -3px; opacity: .7; }",
 "dl:hover .qt_links{opacity:1}",
 ".u {background-repeat: no-repeat; background-position: 5px center}",
 "span.Magnet   {background-image: url('http://upload.wikimedia.org/wikipedia/commons/c/c2/Magnet-icon.gif')}",
 "span.Torrage {background-image: url('http://torrage.com/favicon.png')}",
 "span.Torcache {background-image: url('http://torcache.net/favicon.ico')}",
 "span.Zoink   {background-image: url('http://zoink.it/favicon.ico')}"
 ];
 css = css.join("\n");
 if (typeof GM_addStyle != "undefined") {
  GM_addStyle(css);
 } else if (typeof PRO_addStyle != "undefined") {
  PRO_addStyle(css);
 } else if (typeof addStyle != "undefined") {
  addStyle(css);
 } else {
  var heads = document.getElementsByTagName("head");
  if (heads.length > 0) {
   var node = document.createElement("style");
   node.type = "text/css";
   node.appendChild(document.createTextNode(css));
   heads[0].appendChild(node); 
  }
 }
 
 //$('.qt_cache,.qt_magnet').remove();//dev-time only
 $('.download h2').each(function(){//needed to avoid html-to-dom on unnecessary pages
  var
   $this = $(this),
   name = $this.children('span').text(),
   hex = document.location.pathname.substring(1).toUpperCase(),
   linksString = ['<dl><dt><a href="magnet:?xt=urn:btih:'+hex+'&tr=udp%3A%2F%2Ftracker.publicbt.com%2Fannounce&tr=udp%3A%2F%2Ftracker.openbittorrent.com%2Fannounce"><span class="u Magnet">Magnet Link</span> <span class="n">'+name+'</span></a></dt><dd>Magnet link</dd></dl>'],
   hosts = {
    'Torcache':'http://torcache.net/torrent/'+hex+'.torrent',
    'Zoink':'https://zoink.it/torrent/'+hex+'.torrent',
    'Torrage':'http://torrage.com/torrent/'+hex+'.torrent'
   };
   
  for(host in hosts)
   linksString.push('<dl><dt><a href="'+hosts[host]+'"><span class="u '+host+'">'+host+'</span> <span class="n">'+name+'</span></a></dt><dd>.torrent Cache</dd></dl>');
   
  //add space
  linksString.push('<dl><dt><a><span class="n qt_separator">Hey there! I didn\'t expect you here!</span></a></dt></dl>');
  $(linksString.join('')).insertAfter(this);
 })
 
 $('.results dt a').each(function(){
  var
   $link = $(this),
   hex = $link.attr('href').substring(1).toUpperCase(),
   linksString = ['<span class="qt_links">'],
   hosts = {
    'Torcache':'http://torcache.net/torrent/'+hex+'.torrent',
    'Zoink':'http://zoink.it/torrent/'+hex+'.torrent',
    'Torrage':'http://torrage.com/torrent/'+hex+'.torrent'
   };
  linksString.push('<a class="qt_magnet" href="magnet:?xt=urn:btih:'+hex+'&tr=http%3A%2F%2Ftracker.publicbt.com%2Fannounce&tr=udp%3A%2F%2Ftracker.openbittorrent.com" title="Magnet link">');
  for(host in hosts)
   linksString.push('<a class="qt_cache '+host+'" href="'+hosts[host]+'" title="'+host+': direct link to .torrent file">');
  
  linksString.push('</span">');
  $(linksString.join('')).prependTo($link.parents('dl').children('dd'))
 });
 
})();

0 comments:

Post a Comment