获取ehentai本子资源大小及磁链

获取ehentai本子资源信息及磁链,并显示在“Torrent Download”下方,点击后复制到剪贴板

Versión del día 2/10/2018. Echa un vistazo a la versión más reciente.

// ==UserScript==
// @name         获取ehentai本子资源大小及磁链
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  获取ehentai本子资源信息及磁链,并显示在“Torrent Download”下方,点击后复制到剪贴板
// @author       Neko_Aria
// @include      https://exhentai.org/g/*
// @include      https://e-hentai.org/g/*
// @grant        GM_xmlhttpRequest
// @connect      *
// ==/UserScript==

(function () {
    'use strict';

    var param = document.URL.slice(23, -1).split("/");
    var param_gid = param[0];
    var param_t = param[1];
    var targetNode = document.querySelector("p[class='g2']");
    targetNode.style.paddingBottom = "0px";
    var hostname = location.hostname;
    var baseURL = "https://" + hostname + "/gallerytorrents.php?gid=";

    GM_xmlhttpRequest({
        method: "GET",
        url: baseURL + param_gid + "&t=" + param_t,
        overrideMimeType: "text/html; charset=UTF-8",
        onload: function (xhr) {
            var dom = new DOMParser().parseFromString(xhr.responseText, "text/html");
            var table = dom.getElementsByTagName("table");
            var info = "";
            if (table.length == 0) {
                info = "0 torrents were found for this gallery.";
                createP(info);
            } else {
                for (let index = 0; index < table.length; index++) {
                    const element = table[index];
                    createP(element.getElementsByTagName("td")[1].innerText);
                    createP("magnet:?xt=urn:btih:" +
                        element.querySelector("a").href.match(/[\w\d]{40}/).toString());
                }
            }
        }
    })

    const copyToClipboard = str => {
        const el = document.createElement('textarea');
        el.value = str;
        document.body.appendChild(el);
        el.select();
        document.execCommand('copy');
        document.body.removeChild(el);
    };

    function createP(string) {
        var newNode = document.createElement("p");
        newNode.style.wordBreak = "break-all";
        newNode.innerText = string;
        if (string.length == 60) {
            newNode.onclick = () => {
                copyToClipboard(string);
                alert("复制成功");
            }
        }
        targetNode.appendChild(newNode);
    }

})();