SpaceX 发表于 2026-5-4 21:25:43

简单写了个油猴脚本,可以自动识别有图比链接并自动转换

<div class="blockcode"><div id="code_rIH"><ol><li>// ==UserScript==<br /><li>// @name&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;Hostloc 有图比 替换为 有图比 并转为超链接<br /><li>// @namespace&nbsp; &nbsp; http://tampermonkey.net/<br /><li>// @version&nbsp; &nbsp;&nbsp; &nbsp;2.0<br /><li>// @description&nbsp;&nbsp;将 hostloc.com 页面中的 &quot;https://www.有图比.com/...&quot; 纯文本转换为可点击的 有图比 链接<br /><li>// @author&nbsp; &nbsp;&nbsp; &nbsp; You<br /><li>// @match&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;*://hostloc.com/*<br /><li>// @match&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;*://*.hostloc.com/*<br /><li>// @icon&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;https://www.google.com/s2/favicons?sz=64&amp;domain=hostloc.com<br /><li>// @grant&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;none<br /><li>// ==/UserScript==<br /><li><br /><li>(function() {<br /><li>&nbsp; &nbsp; 'use strict';<br /><li><br /><li>&nbsp; &nbsp; const targetBase = &quot;https://www.有图比.com/&quot;;<br /><li>&nbsp; &nbsp; const replacementBase = &quot;https://www.有图比.com/&quot;;<br /><li>&nbsp; &nbsp; <br /><li>&nbsp; &nbsp; // 使用正则匹配完整链接,允许包含字母、数字及常见的URL符号,遇到空格或中文字符时自动停止<br /><li>&nbsp; &nbsp; const urlRegex = /(https:\/\/www\.有图比\.com\/@!$&amp;'()*+,;=%]*)/g;<br /><li><br /><li>&nbsp; &nbsp; function replace有图比Link(node) {<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;// 1. 处理纯文本节点<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;if (node.nodeType === Node.TEXT_NODE) {<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;let parent = node.parentNode;<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;// 如果已经在输入框、代码块,或者本身就已经是 &lt;a&gt; 标签里了,只需替换文本,不套娃生成新链接<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;if (parent &amp;&amp; ['A', 'TEXTAREA', 'CODE', 'PRE', 'SCRIPT', 'STYLE'].includes(parent.tagName)) {<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; if (node.nodeValue.includes(targetBase)) {<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;node.nodeValue = node.nodeValue.replaceAll(targetBase, replacementBase);<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; }<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; return;<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;}<br /><li><br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;// 如果是普通的纯文本,且匹配到了有图比的链接格式<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;if (urlRegex.test(node.nodeValue)) {<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; urlRegex.lastIndex = 0; // 重置正则索引<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; let fragment = document.createDocumentFragment();<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; let lastIndex = 0;<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; let match;<br /><li><br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; while ((match = urlRegex.exec(node.nodeValue)) !== null) {<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;// 截取链接前方的普通文本<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;if (match.index &gt; lastIndex) {<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;fragment.appendChild(document.createTextNode(node.nodeValue.substring(lastIndex, match.index)));<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;}<br /><li><br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;// 获取匹配到的原始完整链接,并替换域名<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;let originalUrl = match;<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;let newUrl = originalUrl.replace(targetBase, replacementBase);<br /><li><br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;// 创建 &lt;a&gt; 标签,使其变成可点击链接<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;let a = document.createElement('a');<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;a.href = newUrl;<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;a.textContent = newUrl;<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;a.target = &quot;_blank&quot;; // 在新标签页打开<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;// 可选:加个下划线和颜色,让它看起来更像个链接<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;a.style.color = &quot;#1E90FF&quot;; <br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;a.style.textDecoration = &quot;underline&quot;;<br /><li><br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;fragment.appendChild(a);<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;lastIndex = urlRegex.lastIndex;<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; }<br /><li><br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; // 补齐最后一个链接后面的剩余文本<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; if (lastIndex &lt; node.nodeValue.length) {<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;fragment.appendChild(document.createTextNode(node.nodeValue.substring(lastIndex)));<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; }<br /><li><br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; // 用拼装好的包含 &lt;a&gt; 标签的内容替换原本的纯文本节点<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; if (parent) {<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;parent.replaceChild(fragment, node);<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; }<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;}<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;}<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;// 2. 处理元素节点<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;else if (node.nodeType === Node.ELEMENT_NODE) {<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;// 跳过一些不该处理的标签,防止破坏网页原有的代码逻辑或排版<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;if (['SCRIPT', 'STYLE', 'TEXTAREA', 'CODE', 'PRE'].includes(node.tagName)) return;<br /><li><br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;// 处理已经是超链接的标签,防止其 href 跳转地址还是旧的<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;if (node.tagName === 'A' &amp;&amp; node.hasAttribute('href')) {<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; let href = node.getAttribute('href');<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; if (href.includes(targetBase)) {<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;node.setAttribute('href', href.replaceAll(targetBase, replacementBase));<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; }<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;}<br /><li><br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;// 递归检查所有子节点 (使用 Array.from 是为了防止下面动态替换文本节点时打乱遍历顺序)<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;Array.from(node.childNodes).forEach(replace有图比Link);<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;}<br /><li>&nbsp; &nbsp; }<br /><li><br /><li>&nbsp; &nbsp; // 初始化:对当前已加载的整个 body 进行一次扫描替换<br /><li>&nbsp; &nbsp; replace有图比Link(document.body);<br /><li><br /><li>&nbsp; &nbsp; // 监听器:处理动态加载的内容(如无刷新翻页、展开评论等)<br /><li>&nbsp; &nbsp; const observer = new MutationObserver((mutations) =&gt; {<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;mutations.forEach((mutation) =&gt; {<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;mutation.addedNodes.forEach((addedNode) =&gt; {<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; replace有图比Link(addedNode);<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;});<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;});<br /><li>&nbsp; &nbsp; });<br /><li><br /><li>&nbsp; &nbsp; // 开启监听,观察 body 下所有子节点的变化<br /><li>&nbsp; &nbsp; observer.observe(document.body, {<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;childList: true,<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;subtree: true<br /><li>&nbsp; &nbsp; });<br /><li><br /><li>})();</ol></div><em onclick="copycode($('code_rIH'));">复制代码</em></div><br />
<br />
<br />
<br />
tampermonkey新建脚本,全选删除,然后把以上整个代码贴进去保存即可,不放心可以让gpt review一下看有没有问题

雨后天霁 发表于 2026-5-4 21:30:06

在这个ai大爆炸的时代,依然有老手艺人坚持手搓代码

rqp 发表于 2026-5-5 10:43:36

手搓代码厉害

QQ云 发表于 2026-5-5 12:26:32

<i class="pstatus"> 本帖最后由 QQ云 于 2026-5-5 12:31 编辑 </i><br />
<div class="quote"><blockquote>元信息格式错误:<br />
你的 // @name、// <a href="https://hostloc.com/home.php?mod=space&uid=73703" target="_blank">@version</a> 这些字段被多余的 标签包裹了,油猴完全无法解析。</blockquote></div><br />
报错,豆包修改了一下<br />

<ignore_js_op>

<img src="https://hostloc.com/static/image/filetype/zip.gif" border="0" class="vm" alt="" />
<span style="white-space: nowrap" id="attach_176465" onmouseover="showMenu({'ctrlid':this.id,'pos':'12'})">

<a href="https://hostloc.com/forum.php?mod=attachment&aid=MTc2NDY1fDVhNWQ4YzIxfDE3NzgwMjAwMjN8MHwxNDc3MDAy" target="_blank">Hostloc 有图比替换为 有图比 并自动转超链接-2.0.user.zip</a>

<em class="xg1">(1.58 KB, 下载次数: 7)</em>
</span>
<div class="tip tip_4" id="attach_176465_menu" style="position: absolute; display: none" disautofocus="true">
<div class="tip_c xs0">
<div class="y"><span title="2026-5-5 12:26">昨天&nbsp;12:26</span> 上传</div>
点击文件名下载附件

</div>
<div class="tip_horn"></div>
</div>

</ignore_js_op>

卖百度众测礼券 发表于 2026-5-5 13:46:07

我记得以前很多年前,就有人干过这个事情。。。。。。。。。
页: [1]
查看完整版本: 简单写了个油猴脚本,可以自动识别有图比链接并自动转换