Torrenter

Dodaje odnośniki do stron z torrentami.

目前为 2015-09-16 提交的版本,查看 最新版本

// ==UserScript==
// @name           Torrenter
// @namespace      http://www.google.com/search?q=mabakay
// @description    Dodaje odnośniki do stron z torrentami.
// @include        http://release24.pl/*
// @include        http://www.filmweb.pl/*
// @grant          none
// @copyright      2010 - 2015, mabakay
// @date           15 September 2015
// @version        1.49
// @license        GPL version 3 or any later version; http://www.gnu.org/copyleft/gpl.html
// ==/UserScript==

var Engines = ["https://thepiratebay.mk/search/{0}/0/7/0",
                "https://kat.cr/usearch/{0}/?field=seeders&sorder=desc",
                "https://torrentz.eu/search?f={0}",
                "http://extratorrent.cc/search/?search={0}",
		        "https://yts.to/browse-movies/{0}/all/all/0/seeds",
                "http://bitsnoop.com/search/all/{0}/s/d/1/",
                "https://isohunt.to/torrents/?ihq={0}&Torrent_sort=-seeders"];

var hostName = window.location.hostname;

if (hostName === "release24.pl") {
    var titleElement = document.getElementById("mainwindow");
    loopCount = titleElement.childElementCount > 3 ? titleElement.childElementCount - 3 : 2;

    for (i = 1; i < loopCount; i++) {
        var elem = titleElement.children[i];

        if (elem.className === "wpis") {
            var title_regex = /\"(.*)\"\s*(\(([0-9]{4})\))?/;
            match = elem.children[0].children[0].innerHTML.match(title_regex);

            if (match != null) {
                var title = match[1];

                if (match.length === 4 && match[3]) {
                    title += " " + match[3];
                }

                var span = createLinkSpan("span", title, "margin-left: 3em; font-weight: normal;");

                elem.children[2].children[0].children[0].children[0].children[0].children[1].children[0].children[0].children[0].appendChild(span);
            }
        }
    }
}
else if (hostName === "www.filmweb.pl") {
    var style = "margin-top: 0.5em; font-size: 0.7em;";
    var titleElement = $(".filmMainHeader .hdr:first");
    var title, hasSmallTitle = false;

    if (titleElement.length === 1) {
        var smallTitleElement = titleElement.siblings(".cap:first");

        if (smallTitleElement.length === 1) {
            style = "margin-left: 1.5em; font-size: 0.7em;";
            titleElement = smallTitleElement;
            hasSmallTitle = true;

            title = smallTitleElement.text();
        } else {
            title = titleElement.find("a").text();
        }
        
        var year = $(".filmMainHeader .hdr:first .filmTitle").next().text();
        var yearRegexp = /\(([0-9]{4})\)/;
        var match = year.match(yearRegexp);

        if (match != null) {
            title += " " + match[1];
        }
    }

    if (titleElement.length && title) {
        if (hasSmallTitle) {
            titleElement.append(createLinkSpan("span", title, style));
        } else {
            titleElement.parent().append(createLinkSpan("div", title, style));
        }
    }
}

function createLinkSpan(tag, title, style) {
    var span = document.createElement(tag);
    span.setAttribute("id", "Torrenter");
    span.setAttribute("style", style);

    for (var i = 0; i < Engines.length; i++) {
        var link = document.createElement("a");
        link.setAttribute("href", format(Engines[i], encodeURIComponent(title)));
        link.setAttribute("style", "position: relative; top: 5px;");

        var urlRegex = /(https?:\/\/)(.+\....)/;
        var regexResult = Engines[i].match(urlRegex);
        link.innerHTML = getFavIconImg(regexResult[2]);

        if (i > 0) {
            var separator = document.createElement("span");
            separator.innerHTML = "&nbsp;|&nbsp;";

            span.appendChild(separator);
        }

        span.appendChild(link);
    }

    return span;
}

function getFavIconImg(url) {
    var imgurl = "<img src=\"http://www.google.com/s2/favicons?domain=" + url + "\" width=\"16px\" height=\"16px\">";

    return imgurl;
}

function format(str) {
    for (var i = 1; i < arguments.length; i++) {
        var argNum = "{" + (i - 1) + "}";

        str = str.replace(argNum, arguments[i]);
    }

    return str;
}