当页开链

当前页面打开链接

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name        当页开链
// @namespace   -
// @match       *://*/*
// @exclude-match    *://www.gamer520.com/*
// @exclude-match    *://bray.tech/*
// @grant       none
// @version     5.5
// @author      -
// @description 当前页面打开链接
// ==/UserScript==

(() => {

const shouldExcludeElement = (target) => {
    const EXCLUDE_SELECTORS = [
      '[href^="javascript"]',
      '#ks',
      //
      '.bpx-player-ending-content','.carousel-wrap',//bilibili
      '#sb_form',//bing
      '.swiper-wrapper',//baidubaike
      '.win-wapper',//kook
      '[class="hidden xl:flex space-x-4 items-center"]','[class="flex items-start justify-between"]',
      '[role="button"]',
      '[class="pager__btn pager__btn__prev"]','[class="pager__btn pager__btn__next"]',//acfun
      '[id="download_tab_cont"]',
      '[class^="SourceListItem__name"]','[class^="file-tree-btn"]','[id="send_sms_code"]','[class="comment-reply-link"]','[class="download-buttons-container"]',
      '[id="rdgenconseemore"]'//bing
    ];
    return EXCLUDE_SELECTORS.some(selector => target.closest(selector));
};

  //

document.addEventListener('click', function(event) {
    // 使用Event.composedPath()获取精确目标(2025推荐)
    const preciseTarget = event.composedPath()[0];

    if (shouldExcludeElement(preciseTarget)) return true;

    // 动态节点溯源(兼容Shadow DOM)
    let node = preciseTarget;
    while (node && node.tagName !== 'A') {
        node = node.parentElement || node.host; // 处理Web Components场景
    }

    // 增强型链接处理
    if (node?.tagName === 'A') {
        // 最新安全策略(2025-04)
        event.stopImmediatePropagation(); // 防止其他监听器干扰
        event.preventDefault();

        // 异步跳转避免阻塞(2025性能优化方案)
        requestAnimationFrame(() => {
            window.location.assign(node.href); // 替代直接href赋值
        });
    }
}, true);

  //

window.open = u => (location = u);

  //

new MutationObserver(_=>document.querySelectorAll('form').forEach(f=>f.target='_self')).observe(document,{childList:1,subtree:1});

})();