// ==UserScript== // @name UC网盘免客户端下载 // @namespace http://tampermonkey.net/ // @version 250810 // @description UC网盘分享链接免客户端下载 // @author Magiclyan // @copyright M // @license GPL-3.0 License // @match *://*/* // @grant none // ==/UserScript== (function() { 'use strict'; const driveRegex = /https:\/\/drive\./g; // 处理当前页面URL,如果是drive域名则替换为fast并刷新 function handleCurrentPageUrl() { if (driveRegex.test(window.location.href)) { const newUrl = window.location.href.replace(driveRegex, 'https://fast.'); // 避免无限循环刷新 if (newUrl !== window.location.href) { window.location.href = newUrl; } } } // 替换页面中所有链接的函数 function replaceLinks() { // 获取页面中所有的链接元素 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); } // 首先处理当前页面URL handleCurrentPageUrl(); // 页面加载完成后执行链接替换 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 }); })();