当页开链

当前页面打开链接

  1. // ==UserScript==
  2. // @name 当页开链
  3. // @namespace -
  4. // @match *://*/*
  5. // @exclude-match *://www.gamer520.com/*
  6. // @exclude-match *://bray.tech/*
  7. // @grant none
  8. // @version 5.2
  9. // @author -
  10. // @description 当前页面打开链接
  11. // ==/UserScript==
  12.  
  13. (() => {
  14.  
  15. const shouldExcludeElement = (target) => {
  16. const EXCLUDE_SELECTORS = [
  17. '[href^="javascript"]',
  18. '#ks',
  19. //
  20. '.bpx-player-ending-content','.carousel-wrap',//bilibili
  21. '#sb_form',//bing
  22. '.swiper-wrapper',//baidubaike
  23. '.win-wapper',//kook
  24. '[class="hidden xl:flex space-x-4 items-center"]','[class="flex items-start justify-between"]'
  25. ];
  26. return EXCLUDE_SELECTORS.some(selector => target.closest(selector));
  27. };
  28.  
  29. //
  30.  
  31. document.addEventListener('click', function(event) {
  32. // 使用Event.composedPath()获取精确目标(2025推荐)
  33. const preciseTarget = event.composedPath()[0];
  34.  
  35. if (shouldExcludeElement(preciseTarget)) return true;
  36.  
  37. // 动态节点溯源(兼容Shadow DOM)
  38. let node = preciseTarget;
  39. while (node && node.tagName !== 'A') {
  40. node = node.parentElement || node.host; // 处理Web Components场景
  41. }
  42.  
  43. // 增强型链接处理
  44. if (node?.tagName === 'A') {
  45. // 最新安全策略(2025-04)
  46. event.stopImmediatePropagation(); // 防止其他监听器干扰
  47. event.preventDefault();
  48.  
  49. // 异步跳转避免阻塞(2025性能优化方案)
  50. requestAnimationFrame(() => {
  51. window.location.assign(node.href); // 替代直接href赋值
  52. });
  53. }
  54. }, true);
  55.  
  56. //
  57.  
  58. window.open = u => (location = u);
  59.  
  60. //
  61.  
  62. new MutationObserver(_=>document.querySelectorAll('form').forEach(f=>f.target='_self')).observe(document,{childList:1,subtree:1});
  63.  
  64. })();

QingJ © 2025

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