All Magnet to BT

找出页面的磁力链,给出对应的种子下载地址

Versão de: 05/09/2015. Veja: a última versão.

Você precisará instalar uma extensão como Tampermonkey, Greasemonkey ou Violentmonkey para instalar este script.

You will need to install an extension such as Tampermonkey to install this script.

Você precisará instalar uma extensão como Tampermonkey ou Violentmonkey para instalar este script.

Você precisará instalar uma extensão como Tampermonkey ou Userscripts para instalar este script.

Você precisará instalar uma extensão como o Tampermonkey para instalar este script.

Você precisará instalar um gerenciador de scripts de usuário para instalar este script.

(Eu já tenho um gerenciador de scripts de usuário, me deixe instalá-lo!)

Você precisará instalar uma extensão como o Stylus para instalar este estilo.

Você precisará instalar uma extensão como o Stylus para instalar este estilo.

Você precisará instalar uma extensão como o Stylus para instalar este estilo.

Você precisará instalar um gerenciador de estilos de usuário para instalar este estilo.

Você precisará instalar um gerenciador de estilos de usuário para instalar este estilo.

Você precisará instalar um gerenciador de estilos de usuário para instalar este estilo.

(Eu já possuo um gerenciador de estilos de usuário, me deixar fazer a instalação!)

// ==UserScript==
// @name         All Magnet to BT
// @version      0.1.1
// @description  找出页面的磁力链,给出对应的种子下载地址
// @description-en  Find out all magnet links in current page and get their torrent download URLs. In theory, it supports many sites. you can add your favorites just like this //@include http://www.javbus.co
// @description-zh-CN 找出页面的磁力链,给出对应的种子下载地址 
// @author       wanghsinche @ 201509
// @include      https://btdigg.org/search*
// @include      http://btdigg.org/search*
// @include      http://www.torrentkitty.org/search*
// @require      http://cdnjs.cloudflare.com/ajax/libs/jquery/1.8.3/jquery.min.js
// @run-at      document-end
// @namespace https://greasyfork.org/users/326
// ==/UserScript==

function getAllMagnet() {
	var rawMagnets = $('a[href^="magnet"]');
	var magnetNum = rawMagnets.length;
	var rawString = "";
	var rex = new RegExp("\\w{40}", 'g'); //regular expression to match all 40 bit code 
	if (magnetNum !== 0) { //prase all magnet herf nodes into string
		for (var i = 0; i < magnetNum; i++) {
			rawString += rawMagnets[i].toString();
		}
	}
	return rawString.match(rex); //return the code list
}


function code2down1(str) {
	var s1, s2, btih, torrentURL;
	btih = str.toLocaleUpperCase();
	s1 = btih.substr(0, 2);
	s2 = btih.substr(str.length - 2);
	torrentURL = "http://bt.box.n0808.com/" + s1 + "/" + s2 + "/" + btih + ".torrent";
	return torrentURL;
}

function code2down2(str) {
	var btih, torrentURL;
	btih = str.toLocaleUpperCase();
	torrentURL = "http://torcache.net/torrent/" + btih + ".torrent";
	return torrentURL;
}



function getAllTorrents() {
	var nodes = $('a[href^="magnet"]');
	var codeList = [];
	var listLen = 0;
	var i = 0;
	codeList = getAllMagnet();
	listLen = codeList.length;
	if (listLen !== 0) { //prase all magnet herf nodes into string
		for (i = 0; i < listLen; i++) {
			$(nodes[i]).after($(nodes[i]).clone().empty().html("[BT_2]").attr("title","download torrent from torcache" ).attr("href", code2down2(codeList[i])));
			$(nodes[i]).after($(nodes[i]).clone().empty().html("[BT_1]").attr("title","download torrent from bt.box.n0808" ).attr("href", code2down1(codeList[i])));
		}
	}
}



window.setTimeout(function() { //wait 2 seconds to execute getAllTorrents() function
	getAllTorrents();
}, 2000);