当页开链

全站通用型页内增强脚本,Bing兼容,bili兼容.添加kook按钮排除

  1. // ==UserScript==
  2. // @name 当页开链
  3. // @version 4.3
  4. // @description 全站通用型页内增强脚本,Bing兼容,bili兼容.添加kook按钮排除
  5. // @author none
  6. // @match *://*/*
  7. // @grantunsafeWindow
  8. // @run-at document-body
  9. // @exclude-match *://www.gamer520.com/*
  10. // @namespace
  11. // @namespace
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. const shouldExcludeElement = (target) => {
  18. const EXCLUDE_SELECTORS = [
  19. '.nav-content',
  20. '.views',
  21. '.presentation',
  22. '.pay-box', // 支付相关容器
  23. '[target="_self"]',
  24. '[role="group"]',
  25. '#ks',
  26. '.bpx-player-ending-related-item-cover',
  27. '#qs_searchBox',
  28. '.actions'
  29. ];
  30. return EXCLUDE_SELECTORS.some(selector => target.closest(selector));
  31. };
  32.  
  33. document.addEventListener('click', function(event) {
  34. var target = event.target;
  35.  
  36. if (shouldExcludeElement(target)) {
  37. return true; // 保留所有原生交互逻辑
  38. }
  39.  
  40. // 检查点击元素及其父元素链
  41. while (target && target.tagName !== 'A') {
  42. target = target.parentElement;
  43. }
  44.  
  45. if (target && target.tagName === 'A') {
  46. event.preventDefault();
  47. // 内联改写(2025-04-01最新推荐写法)
  48. window.location.href = target.href; // 直接替换函数调用
  49. }
  50. });
  51.  
  52. // 协议安全名单
  53.  
  54.  
  55. // 动态白名单(2025-03-01更新)
  56.  
  57.  
  58. // 智能链接处理
  59.  
  60.  
  61. // 增强事件监听(修复Bing搜索提交问题)
  62. const initEventHandlers = () => {
  63. // 拦截点击事件时排除表单元素
  64. document.addEventListener('click', function(event) {
  65. const target = event.composedPath()[0];
  66.  
  67.  
  68. if (shouldExcludeElement(target)) {
  69. return true; // 保留所有原生交互逻辑
  70. }
  71.  
  72. // 白名单处理逻辑
  73.  
  74.  
  75. // 常规链接处理
  76. let node = target;
  77. while (node && node.tagName !== 'A') {
  78. node = node.parentElement;
  79. }
  80.  
  81. if (node && node.tagName === 'A') {
  82. event.preventDefault();
  83. window.location.href = node.href;
  84. }
  85. }, true); // 使用捕获阶段
  86.  
  87. // 兼容Bing的AJAX搜索(2025-03-01新增)
  88.  
  89. };
  90.  
  91. // 核心初始化
  92. const main = () => {
  93. if (window.self !== window.top) return;
  94.  
  95. // 设置基础标签
  96.  
  97.  
  98. // 初始化事件处理器
  99. initEventHandlers();
  100.  
  101. // 处理window.open
  102. unsafeWindow.open = function(url) {
  103. window.location.href = url;
  104. };
  105. };
  106.  
  107. // 启动逻辑
  108. document.readyState === 'complete' ? main() :
  109. document.addEventListener('DOMContentLoaded', main);
  110. })();

QingJ © 2025

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