// ==UserScript== // @name 多平台镜像站自动转换(带标记) // @version 1.0 // @description 自动替换GreasyFork、GitHub、Chrome商店链接为镜像站,添加红色"(已转换)"标记 // @author 平凡的世界 // @match *://*/* // @grant none // @run-at document-end // ==/UserScript== (function() { 'use strict'; const PLATFORMS = [ { original: 'greasyfork.org', mirror: 'greasyfork.icu', regex: /^https:\/\/greasyfork\.org(\/.*)?$/ }, { original: 'github.com', mirror: 'kkgithub.com', regex: /^https:\/\/github\.com(\/.*)?$/ }, { original: 'chrome.google.com', mirror: 'www.crxsoso.com/webs/det', regex: /^https:\/\/chrome\.google\.com\/webstore\/detail\/[^\/]+\/([a-zA-Z0-9]+)$/ } ]; function replaceLink(link) { const href = link.href; if (link.dataset.linkReplaced) return; for (const platform of PLATFORMS) { if (platform.regex.test(href)) { let mirrorUrl; if (platform.original === 'chrome.google.com') { const match = href.match(platform.regex); const extensionId = match[1]; mirrorUrl = `https://${platform.mirror}/${extensionId}`; } else { mirrorUrl = href.replace(platform.original, platform.mirror); } link.href = mirrorUrl; const tag = document.createElement('span'); tag.textContent = '(已转换)'; tag.style.color = 'red'; tag.style.marginLeft = '5px'; tag.style.fontSize = '0.8em'; link.parentNode.insertBefore(tag, link.nextSibling); link.dataset.linkReplaced = 'true'; console.log(`已转换${platform.original}链接:${href} → ${mirrorUrl}`); break; } } } function replaceAllLinks() { document.querySelectorAll('a[href]').forEach(link => replaceLink(link)); } const observer = new MutationObserver((mutations) => { mutations.forEach(mutation => { mutation.addedNodes.forEach(node => { if (node.nodeType === 1) { if (node.tagName === 'A') { replaceLink(node); } else { node.querySelectorAll('a[href]').forEach(link => replaceLink(link)); } } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); replaceAllLinks(); })();