琉璃神社 自动链接

将琉璃神社的磁力链接标注出来

// ==UserScript==
// @name         琉璃神社 自动链接
// @namespace    https://js.zombie110year.top
// @version      0.2
// @description  将琉璃神社的磁力链接标注出来
// @author       zombie110year
// @match        https://www.liuli.cat/wp/*.html
// @grant        none
// ==/UserScript==

'use strict';
(async function() {
    const css_before = `{content: "神秘代码";margin: 0 1em 0 0;padding: 0 0.2em;}`;
    const css = `{display: inline-block;background: whitesmoke;color: black;font-weight: bold;}`;
    let style = document.querySelector("style#gm-insert-style") || (function () {
        let block = document.createElement("style");
        block.setAttribute("id", "gm-insert-style");
        document.head.appendChild(block);
        return block;
    })();
    style.sheet.insertRule(`.mysterious-code::before ${css_before}`);
    style.sheet.insertRule(`.mysterious-code ${css}`);
})().then(async function() {
    const MAG_RE = /[a-fA-F\d]{40,}/g;
    let PAGE_EL = document.getElementById("content");
    let output = PAGE_EL.innerHTML.replace(MAG_RE, `<a class="mysterious-code" href="magnet:?xt=urn:btih:$&">$&</a>`);
    PAGE_EL.innerHTML = output;
});