|
本帖最后由 月岛花子 于 2025-7-18 19:37 编辑
新版首页图太多了,我就想进版面不想看图,调了一个脚本测试了一下应该还有用,调到开发者模式自己新建一个脚本刷新一下就可以用,需要的可以自取
- // ==UserScript==
- // [url=home.php?mod=space&uid=695501]@name[/url] COLG链接旧版替换
- // [url=home.php?mod=space&uid=5237209]@NameSpace[/url] [url=http://tampermonkey.net/]http://tampermonkey.net/[/url]
- // [url=home.php?mod=space&uid=360369]@version[/url] 1.0
- // [url=home.php?mod=space&uid=5179062]@description[/url] 精确替换COLG网站特定链接为?PCjb参数版本
- // [url=home.php?mod=space&uid=4348003]@author[/url] 月岛花子
- // [url=home.php?mod=space&uid=819389]@Match[/url] *://*/*
- // [url=home.php?mod=space&uid=2199509]@grant[/url] none
- // ==/UserScript==
- (function() {
- 'use strict';
- // 目标域名
- const TARGET_DOMAIN = 'bbs.colg.cn';
- // 目标路径
- const TARGET_PATHS = ['', '/', '/new', '/new/'];
- // 替换目标
- const REPLACEMENT_URL = 'https://bbs.colg.cn/?PCjb';
- // 主替换函数
- function replaceSpecificLinks() {
- document.querySelectorAll('a[href]').forEach(link => {
- try {
- const url = new URL(link.href);
- // 检查是否匹配目标条件
- if (url.hostname === TARGET_DOMAIN && url.protocol === 'https:' &&TARGET_PATHS.includes(url.pathname.toLowerCase())) {
- // 避免重复替换
- if (link.href !== REPLACEMENT_URL) {
- link.href = REPLACEMENT_URL;
- console.log(`已替换链接: ${link.href} -> ${REPLACEMENT_URL}`);
- }
- }
- } catch (e) {
- // 忽略无效URL
- }
- });
- }
- // 初始替换
- replaceSpecificLinks();
- // 使用MutationObserver监听动态内容变化
- const observer = new MutationObserver(mutations => {
- for (const mutation of mutations) {
- if (mutation.addedNodes.length > 0) {
- replaceSpecificLinks();
- break;
- }
- }
- });
- // 开始观察文档变化
- observer.observe(document, {
- childList: true,
- subtree: true
- });
- })();
复制代码 |
|