SH1NU11B1
11/28/2018 - 9:43 AM

Rutracker Magnet + trackers addon for GreaseMonkey

Rutracker Magnet + trackers addon for GreaseMonkey

// ==UserScript==
// @name        Rutracker.org Magnet URLs
// @namespace   rutrackerorg-magnet-urls
// @description Transforms torrent hash into a magnet url
// @include     https://rutracker.org/*
// @include     https://rutracker.cr/*
// @include     https://rutracker.net/*
// @include     https://rutracker.nl/*
// @include     http://rutrackerripnext.onion/*
// @version     9
// @grant       none
// ==/UserScript==

// No longer using udp://tracker.opentrackr.org:1337/announce - it has hash blacklists
// No longer using udp://open.demonii.com:1337 - stopped operation
var trackers = [
    "udp://tracker.coppersurfer.tk:6969/announce",
    "udp://tracker.leechers-paradise.org:6969/announce",
    "udp://tracker.internetwarriors.net:1337/announce",
    "udp://exodus.desync.com:6969/announce",
    "udp://tracker.openbittorrent.com:80/announce",
    "udp://tracker.sktorrent.net:6969/announce",
    "udp://tracker.zer0day.to:1337/announce",
    "udp://tracker.pirateparty.gr:6969/announce"
]

if (window.BB.IS_GUEST) {
    var e = document.getElementsByClassName('magnet-link')[0];
    
    if (e) {
        var magnet_link = e.getAttribute("href");
        var hash = magnet_link.match(/^magnet:\?xt=urn:btih:([0-9A-F]{40})&tr=.*/)[1];
        
        if (hash) {
            
            var rutracker_tracker = decodeURIComponent(magnet_link.match(/.*\&tr=(.*)$/)[1]);
            trackers.unshift(rutracker_tracker);
        
            var urlencoded_trackers = trackers.map(function(tracker) {
                return "&tr=" + encodeURIComponent(tracker);
            });
            
            e.innerText = hash;
            e.innerHTML = "<a href='magnet:?xt=urn:btih:" + hash + urlencoded_trackers.join('') + "'>" + hash + "</a>";
        }
    }
}
else {
    var e = document.getElementById("tor-hash");

    if (e) {
        var hash = e.innerText;
    
        if (/^[0-9A-F]{40}$/.test(hash)) {
            
            var parent_href = document.getElementsByClassName('med magnet-link magnet-link-16')[0];
            var magnet_link = decodeURIComponent(parent_href.getAttribute("href"));
            var rutracker_tracker = decodeURIComponent(magnet_link.match(/.*\&tr=(.*)$/)[1]);
            
            if(rutracker_tracker)
                trackers.unshift(rutracker_tracker);

            var urlencoded_trackers = trackers.map(function(tracker) {
                return "&tr=" + encodeURIComponent(tracker);
            });
        
            e.innerHTML = "<a href='magnet:?xt=urn:btih:" + hash + urlencoded_trackers.join('') + "'>" + hash + "</a>";
            //e.innerHTML = rutracker_tracker;
        }
    }
}