Magnet2Torrent

Magnet to Torrent converter using itorrents.org

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==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);
        }
    });
})();