琉璃神社★hash2link

将琉璃神社文章页面文本中独立成行的hash值转换成可点击的magnet链接,并在其右侧展示复制按钮

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

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.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name         琉璃神社★hash2link
// @version      0.2
// @description  将琉璃神社文章页面文本中独立成行的hash值转换成可点击的magnet链接,并在其右侧展示复制按钮
// @author       不愿透露姓名的lsp
// @license      MIT
// @match        *://*/wp/all/*
// @icon         https://www.llss.fan/favicon.ico
// @run-at       document-end
// @namespace https://greasyfork.org/users/158429
// ==/UserScript==

if (['liuli','llss','hacg'].some(hSLD => window.location.host.includes(hSLD))) {
    (function () {
        function changeHashToLink(node) {
            switch(node.nodeType) {
                case 1:
                    for (let i = node.childNodes.length - 1; i >= 0; i--) {
                        changeHashToLink(node.childNodes[i]);
                    }
                    break;
                case 3:
                    if (node.length == 40 || node.length == 41) {
                        if (node.textContent.match(/^\n?\w{40}\n?$/)) {
                            let injection = document.createElement("div");

                            injection.innerHTML = `<a id="maglink" href="magnet:?xt=urn:btih:${node.textContent.replace(/\n/g, "")}" target="_blank">${node.textContent}</a><span>&nbsp;</span><button id="copyButton" style="color:gray;background:transparent">复制链接 📋</button>`;
                            node.parentNode.insertBefore(injection, node);

                            let elcopyButton = document.getElementById("copyButton");
                            let elmaglink = document.getElementById("maglink");

                            elcopyButton.onclick = () => {navigator.clipboard.writeText(elmaglink.href).then(()=>{elcopyButton.textContent="操作成功 ✔️"},()=>{elcopyButton.textContent="操作失败 ❌"}).finally(setTimeout(()=>{elcopyButton.textContent="复制链接 📋"}, 1500))};
                            elmaglink.onclick = (e) => {console.log(e);window.open(elmaglink.href, '_blank ', `width=400, height=100, left==${e.clientX}, top=${e.clientY}`); return false};

                            node.parentNode.removeChild(node);
                        }
                    }
                    break;
            }
        }
        changeHashToLink(document.getElementsByClassName("entry-content")[0]);
    })();
}