TPB Torrent Downloads

Piratebay download via torrents

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         TPB Torrent Downloads
// @namespace    pxgamer
// @version      0.5.0
// @description  Piratebay download via torrents
// @author       pxgamer
// @include      *thepiratebay.org/*
// @require      https://code.jquery.com/jquery-1.12.4.min.js
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    const userPreferredCache = 'cache_1';

    const preferredCaches = {
        cache_1: {
            name: 'BTCache',
            url: 'http://btcache.me/torrent/',
            end: ''
        },
        cache_2: {
            name: 'Torrage',
            url: 'https://torrage.info/torrent.php?h=',
            end: ''
        },
        cache_3: {
            name: 'iTorrents',
            url: 'https://itorrents.org/torrent/',
            end: '.torrent'
        }
    };

    // Download image
    const dataURI = 'iVBORw0KGgoAAAANSUhEUgAAAAwAAAALCAYAAABLcGxfAAAACXBIWXMAAAsSAAALEgHS3X78AAABfklEQVQokWWQzUsbURRHzxtfkknSYq2UKNaiYncVrdBCUAoKKuKi4EKLbioqbrpp9/07unalG1Faa0EoboQoBT+QoKAgook4mMzEySRqJvO60UjihQsXfudwL1cAhOt+aKGal05j0wudiiq6Hnv/tj571pdZAAlQW/8k8vV7jz4QDVfyoKD9XXzas3gQkFWkixqJzGMeAL8sjRLAUSJvu5C0yrkrR7H45xoV9HllQupW3ORdSN5tMPMwG1NYFy6epUCXqiT4u5bmNCH0i7wgdwlGFowr8AcFskbiKkUhEHrL+6V5TVMpqQJacmyy91t1tc6NC0oD7a6LnsAsSOSrvqcF42TE526PCgDRvzI0Nd653NwUwXTAsOHcgoQJiTTYR7uuno23OavjB+L+tqqPq68Hu5vjH6KtvqQJZyacpmEntpEJZQ8azd8TNkBJANBH10ItDc9Ohwc7nh8bRRZ+ru+Hc4dvUr+mS18qEwDCn/4KXyC4mcva27cLAzOV+X9eUpMXhNIxOAAAAABJRU5ErkJggg==';

    function getHash(element) {
        return $(element).attr('href').split(":")[3].split("&")[0];
    }

    // Add to browsing pages
    $('a[title="Download this torrent using magnet"][href^="magnet:"]').each(function () {
        let hash = getHash(this);
        $(this).after('<a href="' + preferredCaches[userPreferredCache].url + hash.toUpperCase() + preferredCaches[userPreferredCache].end + '" title="Download using torrent file"><img src="data:image/png;base64,' + dataURI + '" style="width: 12px; height: 12px;" alt="Torrent link"></a>');
    });

    // Add to torrent pages
    $('a[href^="magnet:"][title="Get this torrent"]').after(function () {
        let hash = getHash(this);
        $(this).after('<a style="background-image: url(data:image/png;base64,' + dataURI + '); background-position: left; background-size: contain; margin-left: 4px" href="' + preferredCaches[userPreferredCache].url + hash.toUpperCase() + preferredCaches[userPreferredCache].end + '" title="Download using torrent file">&nbsp;Download torrent file</a>');
    });
})();