Skip to content

Commit abcb988

Browse files
committed
修复 问题
1 parent 0d94b52 commit abcb988

1 file changed

Lines changed: 2 additions & 29 deletions

File tree

TargetBlank.user.js

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// ==UserScript==
22
// @name 新标签页打开链接
3-
// @version 1.0.7
3+
// @version 1.0.8
44
// @author X.I.U
55
// @description 将网页中所有链接改为新标签页打开~
66
// @match *://*/*
@@ -15,7 +15,7 @@
1515

1616
(function() {
1717
'use strict';
18-
forceTarget(); // 修改为新标签页打开
18+
targetBlank(); // 修改为新标签页打开
1919
targetDiscuz(); // 针对 Discuz! 论坛的帖子
2020
aObserver(); // 针对动态加载内容中的 a 标签
2121

@@ -32,33 +32,6 @@
3232
if (!_this.target) {_this.target = '_self'}
3333
});
3434
}
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-
}
6235

6336

6437
// 针对 Discuz! 论坛的帖子

0 commit comments

Comments
 (0)