MCBBS 免费解锁锁帖页(Printable)

在锁帖页面添加一个跳转到Printable的链接

// ==UserScript==
// @name         MCBBS 免费解锁锁帖页(Printable)
// @namespace    io.github.msbbc
// @version      0.5.2.1a8
// @description  在锁帖页面添加一个跳转到Printable的链接
// @author       axototl
// @match        https://www.mcbbs.net/forum.php?*
// @match        https://www.mcbbs.net/thread-*
// @license      MIT
// @run-at       document-end
// @inject-into  content
// @sandbox      DOM
// @unwrap
// ==/UserScript==
'use strict';

(() => {
    const msgbox = document.getElementById("messagetext");
    if (! (msgbox?.innerText.includes("陈旧")) ) return;
    const url = new URL(location.href);
    let tid;
    if (location.pathname == "/forum.php")
        if (url.searchParams.get('mod') != 'viewthread')
            return;
        else tid = url.searchParams.get("tid");
    else {
        const tid_match = /thread-(\d+)-\d+-\d+\.html/;
        tid = tid_match.exec(location.pathname);
        if (null == tid) return;
        tid = tid[1];
    }
    url.searchParams.set("action", "printable");
    msgbox.innerHTML += `<p class="alert_btnleft"><a href=${url.href}>[ 免费解锁 (printable) ]</a></p>`;
})();