// ==UserScript== // @name UC等网盘免客户端下载 // @namespace http://tampermonkey.net/ // @version 250804 // @description UC网盘等使用drive域名的链接免客户端下载、跳转 // @author Magiclyan // @copyright M // @license GPL-3.0 License // @match *://*/* // @grant none // ==/UserScript== (function() { 'use strict'; // 替换链接的函数 function replaceLinks() { const driveRegex = /https:\/\/drive\./g; // 获取页面中所有的链接元素 const links = document.getElementsByTagName('a'); for (let link of links) { if (link.href && driveRegex.test(link.href)) { link.href = link.href.replace(driveRegex, 'https://fast.'); } } // 处理可能包含链接的文本内容;这种方式可能会影响页面功能,所以只替换文本节点 function replaceInTextNodes(node) { if (node.nodeType === Node.TEXT_NODE) { if (driveRegex.test(node.textContent)) { node.textContent = node.textContent.replace(driveRegex, 'https://fast.'); } } else if (node.nodeType === Node.ELEMENT_NODE && node.tagName !== 'SCRIPT' && node.tagName !== 'STYLE') { // 递归处理子节点,跳过script和style标签 for (let child of node.childNodes) { replaceInTextNodes(child); } } } // 从body开始处理所有文本节点 replaceInTextNodes(document.body); } // 页面加载完成后执行一次 window.addEventListener('load', replaceLinks); // 监听页面动态内容变化,延迟执行以避免频繁触发 let observer = new MutationObserver(() => { // 使用setTimeout避免频繁执行 clearTimeout(window.replaceLinksTimeout); window.replaceLinksTimeout = setTimeout(replaceLinks, 500); }); // 观察整个文档的变化 observer.observe(document.body, { childList: true, subtree: true, characterData: true }); })();