Greasy Fork

Greasy Fork is available in English.

当页开链

2025/4/8 14:51:16

当前为 2025-04-08 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        当页开链
// @namespace   Violentmonkey Scripts
// @match       *://*/*
// @exclude-match    *://www.gamer520.com/*
// @grant       none
// @version     5.0
// @author      -
// @description 2025/4/8 14:51:16
// ==/UserScript==

(() => {

const shouldExcludeElement = (target) => {
    const EXCLUDE_SELECTORS = [
      '[href="javascript:;"]',
      '[href="javascript:"]',
      '.nav-content',
      '.views',
      '.presentation',
      '.pay-box',
      '[role="group"]',
      '#ks',
      '.bpx-player-ending-related-item-cover',
      '#qs_searchBox',
      '.actions',
      '.swiper-wrapper',
      '#sb_form',
      '.channel-info'
    ];
    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);

})();