Magnet2Torrent

Magnet to Torrent converter using itorrents.org

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name        Magnet2Torrent
// @match        *://*/*
// @grant       none
// @version     1.0
// @author      SH3LL
// @description Magnet to Torrent converter using itorrents.org
// @namespace https://greasyfork.org/users/762057
// ==/UserScript==

(function() {
    'use strict';

    // Extract HASH from magnet link
    function getHashFromMagnetLink(magnetLink) {
        var match = magnetLink.match(/magnet:\?xt=urn:btih:([a-fA-F0-9]+)/);
        return match ? match[1] : null;
    }

    // Click Action
    function handleButtonClick(hash) {
        var torrentLink = 'https://itorrents.org/torrent/' + hash + '.torrent';
        window.open(torrentLink, '_blank');
    }

    // Scrape al magnets in the page
    var magnetLinks = document.querySelectorAll('a[href^="magnet:"]');

    // Loop for all magnets
    magnetLinks.forEach(function(link) {
        // GET HASH
        var hash = getHashFromMagnetLink(link.href);

        // CREATE THE BUTTON
        if (hash) {
            var button = document.createElement('button');
            button.innerHTML = '📥️';
            button.style.marginLeft = '5px';
            button.style.marginRight = '5px';
            button.addEventListener('click', function() {
                handleButtonClick(hash);
            });


            link.parentNode.insertBefore(button, link);
        }
    });
})();