新标签页打开链接

将网页中所有链接改为新标签页打开~

目前为 2021-08-29 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name 新标签页打开链接
  3. // @version 1.0.1
  4. // @author X.I.U
  5. // @description 将网页中所有链接改为新标签页打开~
  6. // @match *://*/*
  7. // @icon https://i.loli.net/2021/03/07/rdijeYm83pznxWq.png
  8. // @grant none
  9. // @license GPL-3.0 License
  10. // @run-at document-end
  11. // @namespace https://github.com/XIU2/UserScript
  12. // @supportURL https://github.com/XIU2/UserScript
  13. // @homepageURL https://github.com/XIU2/UserScript
  14. // ==/UserScript==
  15.  
  16. (function() {
  17. 'use strict';
  18. targetBlank(); // 修改为新标签页打开
  19.  
  20. // 针对 Discuz! 论坛的帖子
  21. if (document.querySelector('meta[name="author"][content*="Discuz!"], meta[name="generator"][content*="Discuz!"]') || document.getElementById('ft') && document.getElementById('ft').textContent.indexOf('Discuz!') > -1) {
  22. let atarget = document.getElementById('atarget');
  23. if (atarget && atarget.className.indexOf('atarget_1') === -1) { // 强制勾选 [新窗]
  24. atarget.click();
  25. }
  26. }
  27.  
  28. // 修改为新标签页打开
  29. function targetBlank() {
  30. Array.from(document.links).forEach(function (_this) {
  31. _this.target = '_blank'
  32. })
  33. }
  34. })();

QingJ © 2025

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