Skip to content

Commit 377479e

Browse files
committed
优化 [新标签页打开链接] 功能(排除 form 标签)
1 parent 5997c03 commit 377479e

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

TargetBlank.user.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// ==UserScript==
22
// @name 新标签页打开链接
3-
// @version 1.0.5
3+
// @version 1.0.6
44
// @author X.I.U
55
// @description 将网页中所有链接改为新标签页打开~
66
// @match *://*/*
@@ -23,11 +23,14 @@
2323
// 修改为新标签页打开
2424
function targetBlank() {
2525
document.head.appendChild(document.createElement('base')).target = '_blank'; // 让所有链接默认以新标签页打开
26-
Array.from(document.links).forEach(function (_this) {
26+
Array.from(document.links).forEach(function (_this) { // 排除特殊链接
2727
if (_this.onclick || _this.href.slice(0,4) != 'http' || _this.getAttribute('href').slice(0,1) === '#') {
2828
_this.target = '_self'
2929
}
3030
})
31+
document.querySelectorAll('form').forEach(function (_this) { // 排除 form 标签
32+
if (!_this.target) {_this.target = '_self'}
33+
});
3134
}
3235

3336

V2ex-Enhanced.user.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// ==UserScript==
22
// @name V2EX 增强
3-
// @version 1.1.3
3+
// @version 1.1.4
44
// @author X.I.U
55
// @description 自动签到、链接转图片、自动无缝翻页、回到顶部(右键点击两侧空白处)、快速回复(左键双击两侧空白处)、新标签页打开链接、标签页伪装为 Github(摸鱼)
66
// @match *://v2ex.com/*
@@ -320,6 +320,11 @@
320320
_this.target = '_self'
321321
}
322322
})
323+
document.querySelectorAll('form').forEach(function (_this) {
324+
if (!_this.target) {
325+
_this.target = '_self'
326+
}
327+
});
323328

324329
const callback = (mutationsList, observer) => {
325330
for (const mutation of mutationsList) {

0 commit comments

Comments
 (0)