强制新标签页打开链接

让所有网页链接都在新标签页中打开,提升浏览效率。

  1. // ==UserScript==
  2. // @name Force Link Open in New
  3. // @name:zh-CN 强制新标签页打开链接
  4. // @namespace http://tampermonkey.net/
  5. // @version 0.3
  6. // @description Opens all web links in new tabs, enhancing browsing efficiency and preventing loss of work progress.
  7. // @description:zh-CN 让所有网页链接都在新标签页中打开,提升浏览效率。
  8. // @author Yearly
  9. // @license AGPL-v3.0
  10. // @match *://*/*
  11. // @exclude *://*.gf.qytechs.cn/*
  12. // @grant none
  13. // ==/UserScript==
  14.  
  15. (function() {
  16. 'use strict';
  17.  
  18. // Capture all click events and open links in a new tab
  19. document.addEventListener('click', function(event) {
  20. let anchor = event.target.closest('a');
  21. if (anchor && anchor.href) {
  22. event.preventDefault();
  23. window.open(anchor.href, '_blank');
  24. }
  25. }, true);
  26.  
  27. // Override window.open method to open URLs in a new tab
  28. const originalOpen = window.open;
  29. window.open = function(url, target = '_blank', features) {
  30. if (['_self', '_parent', '_top'].includes(target)) {
  31. target = '_blank';
  32. }
  33. return originalOpen.call(window, url, target, features);
  34. };
  35.  
  36. })();

QingJ © 2025

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