DisableNewTabJump 禁止网站自动打开新标签页

阻止某些网站www.example.com、xfuliji.com 自动打开新标签页和弹出窗口, 请在脚本设置中新增用户匹配的网址或编辑源代码@match中新增填写需要阻止的域名或匹配正则表达式 Block some websites www.example.com, xfuliji.com automatically open new tabs and popup windows, please add the user match URL in the script settings or edit the source code @match to fill in the domain name to be blocked or match the regular expression

作者
kula ka
日安装量
0
总安装量
6
评分
0 0 0
版本
1.2
创建于
2025-02-04
更新于
2025-02-28
大小
2.4 KB
许可证
MIT
适用于

阻止某些网站www.example.com 自动打开新标签页和弹出窗口, 请在脚本设置中新增用户匹配的网址或编辑源代码@match中新增填写需要阻止的域名或匹配正则表达式

Block some websites www.example.com, xfuliji.com automatically open new tabs and popup windows, please add the user match URL in the script settings or edit the source code @match to fill in the domain name to be blocked or match the regular expression

脚本功能说明:

  1. 重写 window.open 方法
    完全禁用通过 JavaScript 打开新窗口/标签页的功能

  2. 拦截左键点击事件

    • 捕获所有点击事件
    • 检测是否点击了带有 target="_blank" 的链接
    • 修改链接目标为当前页打开
    • 立即进行页面跳转
  3. 阻止中键点击
    防止用户通过鼠标中键强制打开新标签页

  4. MutationObserver 监听

    • 实时监控 DOM 变化
    • 自动修改动态加载内容中的新链接
    • 确保 AJAX 加载的内容同样生效
  5. 提前执行机制
    通过 @run-at document-start 确保脚本在页面加载初期就生效

注意事项:

  1. 该脚本会强制所有链接在当前标签页打开
  2. 仍然保留正常的页面跳转功能
  3. 完全禁用任何新窗口/标签页的创建
  4. 适用于 Chrome/Firefox 等现代浏览器