// ==UserScript== // @name [52PJ]灌水举报贴回复页文本链转超链 // @namespace http://tampermonkey.net/ // @version 20260504 // @description 吾爱论坛回复页文本链转超链 // @author M // @match https://www.52pojie.cn/thread-2105755-1-1.html // @note 本脚本面向吾爱破解(52pj.cn)论坛开发因此使用比较严格的 Apache-2.0协议 // @tag 吾爱破解 52PJ // @license Apache-2.0 // ==/UserScript== (function () { 'use strict'; const linkReg = /https?:\/\/www\.52pojie\.cn\/home\.php\?[^"\s<>]*mod=space[^"\s<>]*uid=\d+[^"\s<>]*/gi; // 排除标签 const ignoreTags = ['A', 'SCRIPT', 'STYLE', 'IFRAME', 'TEXTAREA', 'CODE', 'PRE']; // 替换文本链接为a标签 function textToLink(node) { if (ignoreTags.includes(node.parentElement.tagName)) return; if (node.nodeType !== 3) return; const txt = node.textContent; if (!linkReg.test(txt)) return; const newHtml = txt.replace(linkReg, url => { return `${url}`; }); const temp = document.createElement('span'); temp.innerHTML = newHtml; node.replaceWith(...temp.childNodes); } // 遍历所有文本节点 function scanTextNodes(el = document.body) { const childNodes = Array.from(el.childNodes); childNodes.forEach(child => { if (child.nodeType === 3) { textToLink(child); } else if (child.nodeType === 1) { scanTextNodes(child); } }); } // 初始执行 scanTextNodes(); // 监听页面动态加载(帖子回复、滚动加载等) const observer = new MutationObserver(() => { scanTextNodes(); }); observer.observe(document.body, { childList: true, subtree: true }); })();