Skip to content

Instantly share code, notes, and snippets.

@koenbollen
Created October 31, 2010 18:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save koenbollen/656963 to your computer and use it in GitHub Desktop.
Save koenbollen/656963 to your computer and use it in GitHub Desktop.
A Chrome Userscript that adds direct-download-links to torrent pages of http://torrentz.com/.
// ==UserScript==
// @name Torrentz Direct Link
// @description Adds direct links to torrent pages, you won't have to go to the original index.
// @author Koen Bollen
// @match http://torrentz.com/*
// ==/UserScript==
var rxs = {
'piratebay.org': [
"thepiratebay.org/torrent/(\\d+)",
"http://torrents.thepiratebay.org/%1/%1.torrent",
"/img/20.gif"
],
'1337x.org': [
"http://1337x.org/torrent/(\\d+)/0/",
"http://1337x.org/download/%1/",
"/img/11.gif"
],
'h33t.com': [
"id=(.+)",
"http://www.h33t.com/download.php?id=%1",
"/img/30.gif"
],
'btmon.com': [
"http://(.+).html",
"http://%1",
"/img/35.gif"
],
'torrents.net': [
"http://www.torrents.net/torrent/(\\d+)",
"http://www.torrents.net/down/%1.torrent",
"/img/115.gif"
]
};
var result = {};
var as = document.getElementsByTagName( "a" );
for( var i = as.length - 1; i >= 0; i-- )
{
var a = as[i];
for( var type in rxs )
{
var rx = rxs[type][0];
var sub = rxs[type][1];
var m = a.href.match( rx );
if( m )
{
for( var j = 1; j < m.length; j++ )
{
rx = new RegExp( "%"+j, "g" );
sub = sub.replace( rx, m[j] );
}
result[type] = sub;
break;
}
}
}
var html = "Unable to parse direct links...";
var count = 0;
for( var name in result )
{
count++;
}
if( count > 0 )
{
html = "Direct download links:\n<dl>\n";
for( var type in result )
{
var href = result[type];
var img = rxs[type][2];
html += "<dt><a href=\""+href+"\" rel=\"e\">";
html += '<span class="u" style="background: transparent url(\''+img+'\') no-repeat 5px center;padding-left: 30px;">'+type+'</span>';
html += "</a></dt>\n";
}
html += "</ul>\n";
}
var divs = document.getElementsByTagName( "div" );
for( var i = divs.length - 1; i >= 0; i-- )
{
var div = divs[i];
if( div.className == "info" )
{
div.innerHTML = html;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment