您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
新标签打开第三方链接,当前标签打开第一方链接。
// ==UserScript== // @name 新标签打开第三方链接,当前标签打开第一方链接 // @version 1.3 // @author ChatGPT // @description 新标签打开第三方链接,当前标签打开第一方链接。 // @match *://*/* // @run-at document-end // @namespace https://greasyfork.org/users/452911 // ==/UserScript== function handleLinks() { const currentDomain = window.location.hostname; // 处理外部链接 document.querySelectorAll('a').forEach(link => { if (link.href.startsWith("http") && new URL(link.href).hostname !== currentDomain) { link.setAttribute('target', '_blank'); } else { link.setAttribute('target', '_self'); } }); // 处理内部链接 document.querySelectorAll('a[href^="/"]').forEach(link => { link.setAttribute('target', '_self'); }); } // 执行函数 handleLinks(); (function() { const observer = new MutationObserver(mutations => { mutations.forEach(mutation => { if (mutation.addedNodes.length > 0) { mutation.addedNodes.forEach(addedNode => { if (addedNode.nodeType === Node.ELEMENT_NODE) { handleLinks(); } }); } }); }); const config = { childList: true, subtree: true }; observer.observe(document.body, config); })();