Skip to content

Instantly share code, notes, and snippets.

@oglops
Last active October 22, 2015 06:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oglops/3e42a14e09ea816a7d13 to your computer and use it in GitHub Desktop.
Save oglops/3e42a14e09ea816a7d13 to your computer and use it in GitHub Desktop.
search douban movie torrent on torrent project
// ==UserScript==
// @name doubanMovieSearch
// @namespace dbms
// @description search torrent on torrent project
// @include http://movie.douban.com/subject/*
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
// @version 0.3
// ==/UserScript==
var GM_Debug = 1;
if (unsafeWindow.console) {
var GM_log = unsafeWindow.console.log;
}
if (!GM_Debug) {
var GM_log = function() {};
}
var $ = unsafeWindow.jQuery.noConflict(true);
var titles = $('#content h1 span');
// var titleArray = titles[0].textContent.match(/([^\s][\s\u00ff-\uffff]*)\s|(.*[^\s])/g);
var titleArray = titles[0].textContent.match(/([^\s][\s\u4e00-\u9eff]*)\s|(.*[^\s])/g);
// add 又名
// $("span.pl:contains('又名:')").css("text-decoration", "underline");
var aliases = $("span.pl:contains('又名:')")[0].nextSibling.nodeValue
var aliasesArray = aliases.split("/")
aliasesArray = [$.trim(t) for each(t in aliasesArray)];
titleArray = [$.trim(t) for each(t in titleArray)];
Array.prototype.unique = function() {
var a = this.concat();
for (var i = 0; i < a.length; ++i) {
for (var j = i + 1; j < a.length; ++j) {
if (a[i] === a[j])
a.splice(j--, 1);
}
}
return a;
};
// titleArray = titleArray.concat(aliasesArray);
// var titleArray = ["摩纳哥王妃", "王菲"];
// debugger;
for (i = 0; i < titleArray.length; i++) {
// for chinese we combine the title
if (i == 0 && titleArray.length > 1)
formatedTitle = titleArray[i].split(" ").join('');
else
formatedTitle = titleArray[i].split(" ").join('+');
// GM_log("http://torrentproject.se/?s=" + formatedTitle + "&out=json&orderby=latest");
// window.setTimeout(function() {
GM_xmlhttpRequest({
method: "GET",
url: "http://torrentproject.se/?s=" + formatedTitle + "&out=json&orderby=latest",
onload: torrentAppend.bind({}),
context: formatedTitle,
});
// }, 500);
}
var tpUrl = 'http://torrentproject.se/';
var resultLimit = 10;
var titleLength = 35;
var torrentInfoDiv = '<div class="torrent_info"> <p style="clear: both;padding-top:12px;"></p></div>';
$('#dale_movie_subject_top_right').append(torrentInfoDiv);
GM_addStyle('a.truncated { float:left; display:inline-block; max-width:290px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }');
GM_addStyle('.disable_text_highlighting { \
-webkit-user-select: none; /* Webkit */ \
-moz-user-select: none; /* Firefox */ \
-ms-user-select: none; /* IE 10 */ \
/* Currently not supported in Opera but will be soon */ \
-o-user-select: none; \
user-select: none; \
}');
GM_addStyle('a.magnetlink { float:left; margin-right: 5px;} ');
function dummy() {}
function torrentAppend(response) {
res = response.responseText;
torrentJSON = eval("(" + res + ")");
var torrentHtml = '';
totalResult = Number(torrentJSON.total_found);
resultLimit = Math.min(resultLimit, totalResult)
// debugger;
if (totalResult) {
for (i = 1; i <= resultLimit; i++) {
title = torrentJSON[i].title;
url = tpUrl + torrentJSON[i].torrent_hash;
leechSeed = torrentJSON[i].leechs + '/' + torrentJSON[i].seeds;
torrentUrl = tpUrl + 'torrent/' + torrentJSON[i].torrent_hash.toUpperCase() + '.torrent';
torrentHtml += '<div><a class="magnetlink" target="_blank" title="Get this movie with torrent" href="' + torrentUrl + '"><img src="http://thepiratebay.se/static/img/icon-magnet.gif"></a>' + '<a class="truncated" target="_blank" href="' + url + '" title="' + title + ' ' + leechSeed + '">' + title + ' ' + leechSeed + '</a></div><br/>';
};
// debugger;
}
moreUrl = tpUrl + '?t=' + response.context;
torrentHtml += '<a style="float:right" target="_blank" href="' + moreUrl + '">more</a><br/>';
$('.torrent_info').append(torrentHtml);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment