一半君的总结纸

听话只听一半君

在豆瓣电影页面显示torrent链接的Greasemonkey script

继之前乱搞的在ThePirateBay显示豆瓣电影影评的Greasemonkey script, 反之……在豆瓣电影页面用torrent project的api查询下载链接 … 事先声明lz没有下载这些电影,lz只是对电影”流出”的时机感兴趣,请勿跨省 …

一般情况下会是这样

good

但有时候会出现意料之外的”惊喜” orz …

bad

右上角的广告部位lz用Adblock plus 隐藏了,取而代之的是这些种子链接, 此script的下载链接在userscripts.org / github,需要Firefox的Greasemonkey Addon

// ==UserScript==
// @name        doubanMovieSearch
// @namespace   dbms
// @description search torrent on torrent project
// @include     http://movie.douban.com/subject/*
// @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);

// 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");

    GM_xmlhttpRequest({
        method: "GET",
        url: "http://torrentproject.se/?s=" + formatedTitle + "&out=json&orderby=latest",
        onload: torrentAppend.bind({}),
        context: formatedTitle,
    });

}

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 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);
}
Advertisements

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s

%d 博主赞过: