所有链接在当前页面打开

求求你不要跳转了。Force Links to Open in Current Tab

  1. // ==UserScript==
  2. // @name 所有链接在当前页面打开
  3. // @namespace https://gf.qytechs.cn/users/1171320
  4. // @version 0.1
  5. // @description 求求你不要跳转了。Force Links to Open in Current Tab
  6. // @author yzcjd
  7. // @author2 Lama AI 辅助
  8. // @match *://*/*
  9. // @grant GM_xmlhttpRequest
  10. // @grant none
  11.  
  12. // @license MIT
  13.  
  14.  
  15. // ==/UserScript==
  16.  
  17. (function () {
  18. 'use strict';
  19.  
  20. // 遍历页面中的所有链接
  21. function updateLinks() {
  22. const links = document.querySelectorAll('a'); // 获取所有 <a> 标签
  23. links.forEach(link => {
  24. // 将 target 属性设置为 "_self",强制在当前页面打开
  25. link.setAttribute('target', '_self');
  26. });
  27. }
  28.  
  29. // 初始运行一次,处理当前页面的所有链接
  30. updateLinks();
  31.  
  32. // 监听 DOM 的动态变化,处理异步加载的内容或单页应用
  33. const observer = new MutationObserver(() => {
  34. updateLinks(); // 每次检测到 DOM 变化时重新检查链接
  35. });
  36.  
  37. observer.observe(document.body, { childList: true, subtree: true }); // 监听 DOM 变化
  38. })();

QingJ © 2025

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