禁止打开新标签

强制所有顽固跳转的链接都在当前标签页打开

目前為 2025-07-19 提交的版本,檢視 最新版本

// ==UserScript==
// @name         禁止打开新标签
// @description  强制所有顽固跳转的链接都在当前标签页打开
// @version      1.4
// @author       WJ
// @match        *://*/*
// @license      MIT
// @grant        none
// @namespace https://gf.qytechs.cn/users/914996
// ==/UserScript==

(function() {
    'use strict';

    document.addEventListener('click', function(e) {
        const a = e.target.closest('a');
        if (a?.href && !a.href.startsWith('javascript:')) {
            e.preventDefault();
            location.href = a.href;
        }
    }, true);

    // 动态内容支持
    new MutationObserver(function() {
        document.querySelectorAll('a').forEach(function(a) {
            a.target = '_self';
        });
    }).observe(document, { childList: true, subtree: true });

    // 拦截window.open
    window.open = function(url) {
        return url ? (location.href = url, window) : window;
    };
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址