Magnet Links on YTS

Converts the torrent download links to magnet links on YTS.

// ==UserScript==
// @name         Magnet Links on YTS
// @namespace    https://naeembolchhi.github.io/
// @version      0.3
// @description  Converts the torrent download links to magnet links on YTS.
// @author       NaeemBolchhi
// @license      GPL-3.0-or-later
// @match        https://yts.mx/*
// @icon         data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' viewBox='0 0 400 455' xml:space='preserve'><style>@keyframes rotate{0%{transform: rotateY(0deg)}70%{transform: rotateY(0deg)}100%{transform: rotateY(360deg)}}path{fill: red;transform-origin: 50% 50%;animation: rotate 2s linear infinite}</style><path d='M-1.185 402.672-1.083 348l67.082-.102 67.048-.068v109.48h-134.3l.068-54.638zm268.872-.102v-54.74l67.082.068 67.048.102.102 54.672.068 54.638h-134.3v-54.74zM-1.015 320.052c-.408-.374-.272-121.108.102-130.288.204-4.59.578-9.928.85-11.866.272-1.904.51-4.08.51-4.828 0-1.768 1.258-8.602 3.264-17.68.272-1.224.646-2.822.782-3.57.476-2.244 1.122-4.692 1.496-5.61.17-.476.442-1.394.612-2.04.816-3.57 2.89-9.826 5.066-15.3.408-1.02.884-2.312 1.054-2.89.306-1.088.748-2.108 1.53-3.672.272-.544.476-1.122.476-1.292 0-.748 8.466-17.918 10.03-20.366.918-1.428 1.224-1.938 2.822-4.828 1.428-2.652 9.69-14.824 12.274-18.054.85-1.088 2.312-2.924 3.196-4.08.918-1.156 2.21-2.72 2.89-3.468a33.856 33.856 0 0 0 2.176-2.584c2.448-3.332 17.34-18.054 21.42-21.216.476-.374 1.462-1.224 2.21-1.87a31.484 31.484 0 0 1 2.652-2.21c.748-.578 1.428-1.088 1.53-1.224.85-.952 14.314-10.506 14.79-10.506.136 0 .816-.442 1.53-1.02.714-.544 1.36-1.02 1.462-1.02.136 0 .782-.408 1.496-.884.714-.476 1.598-1.02 1.972-1.19.374-.17.918-.442 1.19-.612 4.658-2.958 21.658-11.594 22.78-11.594.17 0 .714-.204 1.258-.476 3.808-1.836 16.694-6.426 23.154-8.194 6.29-1.734 8.296-2.244 10.506-2.55.952-.17 1.938-.374 2.142-.51.238-.136 1.258-.374 2.312-.51a99.705 99.705 0 0 0 3.468-.612c9.044-2.006 24.65-3.468 36.38-3.468s27.336 1.462 36.38 3.468c.85.17 2.38.442 3.468.612 1.054.136 2.074.374 2.312.51.204.136 1.19.34 2.142.51 1.802.272 3.74.68 7.038 1.598 1.02.272 2.652.714 3.57.986 6.188 1.666 19.278 6.324 23.052 8.16.544.272 1.088.476 1.258.476 1.122 0 18.122 8.636 22.78 11.594.272.17.816.442 1.19.612s1.258.714 1.972 1.19 1.36.884 1.496.884c.102 0 .748.476 1.462 1.02.714.578 1.394 1.02 1.53 1.02.51 0 14.076 9.656 14.79 10.54.102.102.782.646 1.53 1.224.748.544 1.938 1.53 2.652 2.176.748.646 1.734 1.496 2.21 1.87 4.08 3.162 18.972 17.884 21.42 21.216.51.68 1.462 1.836 2.176 2.584 2.448 2.652 12.07 15.368 12.852 17 .102.17 1.224 1.938 2.55 3.91 1.292 1.972 2.618 4.08 2.958 4.658.34.612.884 1.632 1.224 2.21a61.24 61.24 0 0 0 1.598 2.652c1.564 2.448 10.03 19.618 10.03 20.366 0 .17.204.748.476 1.292.782 1.564 1.224 2.584 1.53 3.672.17.578.646 1.87 1.054 2.89 1.53 3.808 3.808 10.404 4.114 11.832.136.782.442 1.734.646 2.074.17.374.34.986.34 1.36s.204 1.19.476 1.802c.476 1.122 1.054 3.332 1.598 5.882.136.748.51 2.346.782 3.57 2.652 12.002 3.536 17.884 4.386 28.9.272 3.808.408 23.562.408 70.55v65.28l-67.048.102-67.048.068-.136-63.648c-.068-49.368-.204-64.226-.544-66.062-.748-4.318-1.462-7.446-1.938-8.84-.272-.782-.476-1.598-.476-1.87 0-1.36-4.216-10.744-6.766-14.96-5.984-10.03-17.374-20.604-27.064-25.126-1.292-.612-2.652-1.258-2.958-1.428-1.19-.612-6.63-2.618-8.602-3.162-1.122-.34-2.482-.748-3.06-.952-.544-.204-2.074-.476-3.4-.646-1.292-.17-2.992-.442-3.74-.612-1.768-.476-15.572-.476-17.34 0-.748.17-2.414.442-3.74.612-1.292.17-2.822.442-3.4.646-.544.204-1.938.612-3.06.952-1.972.544-7.412 2.55-8.602 3.162-.306.17-1.632.816-2.958 1.428-9.69 4.522-21.08 15.096-27.064 25.126-2.55 4.216-6.766 13.6-6.766 14.96 0 .272-.204 1.088-.476 1.87-.476 1.394-1.19 4.522-1.938 8.84-.34 1.836-.476 16.694-.544 66.062l-.136 63.648H66.1c-36.788 0-67.014-.102-67.116-.238z' /></svg>
// @run-at       document-end
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    function magnetify(hashkey, titlekey) {
        return `magnet:?xt=urn:btih:${hashkey}
                &dn=${titlekey}
                &tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337%2Fannounce
                &tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969%2Fannounce
                &tr=udp%3A%2F%2F9.rarbg.to%3A2710%2Fannounce
                &tr=udp%3A%2F%2Fp4p.arenabg.ch%3A1337%2Fannounce
                &tr=udp%3A%2F%2Ftracker.cyberia.is%3A6969%2Fannounce
                &tr=http%3A%2F%2Fp4p.arenabg.com%3A1337%2Fannounce
                &tr=udp%3A%2F%2Fopen.tracker.cl%3A1337%2Fannounce`;
    }

    let tLinks = document.querySelectorAll("a[href*='torrent/download/']");

    for (let x = 0; x < tLinks.length; x++) {
        let tHash = tLinks[x].href.replace(/.*download\//,"");
        let tTitle = tLinks[x].getAttribute("title").replace(/Download\s/,"").replace(/\sTorrent/,"").replace(/\s/g,"$S$");
        tLinks[x].href = magnetify(tHash, tTitle).replace(/\s/g,"").replace(/\$S\$/g," ");
    }
})();