|
1 | 1 | // ==UserScript== |
2 | 2 | // @name 新标签页打开链接 |
3 | | -// @version 1.0.7 |
| 3 | +// @version 1.0.8 |
4 | 4 | // @author X.I.U |
5 | 5 | // @description 将网页中所有链接改为新标签页打开~ |
6 | 6 | // @match *://*/* |
|
15 | 15 |
|
16 | 16 | (function() { |
17 | 17 | 'use strict'; |
18 | | - forceTarget(); // 修改为新标签页打开 |
| 18 | + targetBlank(); // 修改为新标签页打开 |
19 | 19 | targetDiscuz(); // 针对 Discuz! 论坛的帖子 |
20 | 20 | aObserver(); // 针对动态加载内容中的 a 标签 |
21 | 21 |
|
|
32 | 32 | if (!_this.target) {_this.target = '_self'} |
33 | 33 | }); |
34 | 34 | } |
35 | | - function forceTarget() { |
36 | | - document.body.addEventListener('click', function(e) { |
37 | | - if (e.target.tagName === 'A') { |
38 | | - forceTarget_(e.target, e); |
39 | | - } else { |
40 | | - let path = e.path || e.composedPath(); |
41 | | - for (let i = 1; i < path.length - 4; i++) { |
42 | | - //console.log(path[i]) |
43 | | - if (path[i].tagName === 'A') { |
44 | | - forceTarget_(path[i], e); |
45 | | - break; |
46 | | - } |
47 | | - } |
48 | | - } |
49 | | - }); |
50 | | - |
51 | | - function forceTarget_(target, e){ |
52 | | - if (target.href && target.target != '_blank' && !(target.getAttribute('onclick')) && target.href.slice(0,4) == 'http' && target.getAttribute('href').slice(0,1) != '#') { |
53 | | - e.preventDefault(); // 阻止默认打开链接事件 |
54 | | - e.stopImmediatePropagation(); |
55 | | - //console.log(target.href); |
56 | | - //window.top.location.href = target.href; |
57 | | - window.GM_openInTab(target.href, {active: true,insert: true,setParent: true}); |
58 | | - } |
59 | | - } |
60 | | - //document.head.appendChild(document.createElement('base')).target = '_top'; |
61 | | - } |
62 | 35 |
|
63 | 36 |
|
64 | 37 | // 针对 Discuz! 论坛的帖子 |
|
0 commit comments