Greasy Fork

get-magnet

query the web pages all magnet link

目前为 2023-10-03 提交的版本。查看 最新版本

// ==UserScript==
// @name         get-magnet
// @namespace    http://tampermonkey.net/
// @version      0.32
// @description  query the web pages all magnet link
// @author       You
// @match        https://fc2club.top/
// @match http://*/*
// @match https://*/*
// @license GPL
// @icon         https://www.google.com/s2/favicons?sz=64&domain=fc2club.top
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

     var orstr = "<button class='btn' id='getmagbtn'>提取磁力链</button >"
    var divObj = document.createElement("div");
    divObj.id = "magbtn";
    divObj.style.position = "fixed";
    divObj.style.right = "1%";
    divObj.style.top = "55px";
    divObj.style.textAlign = "center";
    divObj.style.width = "88px";
    divObj.style.margin = "auto";
    divObj.style.borderRadius="8px";
    divObj.style.zIndex = "888";
    divObj.style.boxShadow = "0px 0px 2px 2px rgb(0,0,0)";
    if (self != top) {
        return;
    }
    document.body.appendChild(divObj);
    document.getElementById("magbtn").innerHTML = orstr;
    function getmag() {
        var divObj = document.createElement("div");
        divObj.id = "showmagnet";
        divObj.style.position = "fixed";
        divObj.style.left = "25%";
        divObj.style.top = "2%";
        divObj.style.textAlign = "center";
        divObj.style.width = "50%";
        divObj.style.margin = "auto";
        divObj.style.zIndex = "999";
        divObj.style.background = "pink";
        divObj.style.boxShadow = "0px 0px 3px 3px rgb(0,0,0)";
        divObj.style.borderRadius="10px";
        divObj.addEventListener("dblclick",
                                function() {
            this.remove()
        });
        if (self != top) {
            return;
        }
        document.body.appendChild(divObj);
        var links = document.querySelector("body").innerHTML.match(/[0-9a-fA-F]{40}/g);
        links = links.sort();
        console.info()
        var tarstr = "magnet:?xt=urn:btih:" + links[0].toUpperCase() + "<br>";
        var textrows = 1;
        for (var i = 1,
             l = links.length; i < l; i++) {
            if (links[i].toUpperCase() !== links[i - 1].toUpperCase() && links[i].toUpperCase() !=="AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA") {
                tarstr += "magnet:?xt=urn:btih:" + links[i].toUpperCase() + "<br>";
                textrows++;
            }
        }
        document.getElementById("showmagnet").innerHTML = tarstr;
        textrows++;
        tarstr = "<button class='btn' id='clipbrdbtn'>复制到剪贴板</button ><br><textarea id = 'clipboard'  cols='64' rows='" + textrows + "' >" + document.getElementById("showmagnet").innerText + "</textarea>";
        document.getElementById("showmagnet").innerHTML = tarstr;
        document.getElementById("clipbrdbtn").addEventListener("click",
                                                               function() {
            copy2brd()
        })
    }
    function copy2brd() {
        var text = document.getElementById("clipboard").value;
        if (navigator.clipboard) {
            if (navigator.clipboard.writeText(text)) {
                document.getElementById("clipboard").value = ""
            }
        } else {
            document.getElementById("clipboard").select();
            document.execCommand("cut", true)
        }
        document.getElementById("showmagnet").remove()
    }
    document.getElementById("getmagbtn").addEventListener("click",
                                                          function() {
        getmag()
    })
    document.getElementById("getmagbtn").addEventListener("mouseenter",
                                                          function() {
        document.getElementById("getmagbtn").style.backgroundColor="green";
        document.getElementById("getmagbtn").style.color="pink";
        document.getElementById("getmagbtn").style.fontWeight="bold";
    })
    document.getElementById("getmagbtn").addEventListener("mouseleave",
                                                          function() {
        document.getElementById("getmagbtn").style.backgroundColor="";
        document.getElementById("getmagbtn").style.color="";
        document.getElementById("getmagbtn").style.fontWeight="";
    })
})();