Skip to content

Commit 5c41a7b

Browse files
committed
优化 规则
1 parent 6e5ee24 commit 5c41a7b

2 files changed

Lines changed: 37 additions & 11 deletions

File tree

TargetBlank.user.js

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

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

@@ -32,6 +32,33 @@
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+
}
3562

3663

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

other/Autopage/rules.json

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,7 +1037,7 @@
10371037
},
10381038
"Pixiv - 分类页": {
10391039
"host": "www.pixiv.net",
1040-
"url": "fun.isUrlC(); if (fun.isMobile()) {return false}; if (fun.lp() == '/') {fun.forceTarget();} else if (fun.indexOF('/tags/')) {return true;} else if (fun.indexOF('/artworks/')) {setTimeout(function(){fun.getXpath('//button[contains(string(), \"查看全部\") or contains(string(), \"See all\") or contains(string(), \"すべて見る\") or contains(string(), \"모두 보기\")]').click();}, 3000)}",
1040+
"url": "fun.isUrlC(); if (fun.isMobile()) {return false}; if (fun.lp() == '/') {fun.blank();} else if (fun.indexOF('/tags/')) {return true;} else if (fun.indexOF('/artworks/')) {setTimeout(function(){fun.getXpath('//button[contains(string(), \"查看全部\") or contains(string(), \"See all\") or contains(string(), \"すべて見る\") or contains(string(), \"모두 보기\")]').click();}, 3000)}",
10411041
"blank": 2,
10421042
"style": "ul[class*='-1 '] > li {display: inline !important;} #root{margin-bottom: -175px;} ul > li > button[class^='sc-'], a[href^='/premium/lead/lp'] {display: none !important;}",
10431043
"iframe": true,
@@ -1083,7 +1083,7 @@
10831083
},
10841084
"Vilipix": {
10851085
"host": "www.vilipix.com",
1086-
"url": "fun.isUrlC(); if (fun.lp() == '/') {forceTarget();} else if (fun.indexOF(/\\/(tags|user|new|ranking)/)) {return true;}",
1086+
"url": "fun.isUrlC(); if (fun.lp() == '/') {fun.blank();} else if (fun.indexOF(/\\/(tags|user|new|ranking)/)) {return true;}",
10871087
"blank": 2,
10881088
"pager": {
10891089
"type": 6,
@@ -3710,7 +3710,7 @@
37103710
},
37113711
"博客园 - 文章列表": {
37123712
"host": "www.cnblogs.com",
3713-
"url": "if (fun.getCSS('#post_list')) return true",
3713+
"url": "return (fun.getCSS('#post_list') != null)",
37143714
"pager": {
37153715
"nextL": "//div[@class='pager']//a[contains(text(), '>')]",
37163716
"pageE": "#post_list > article",
@@ -3720,7 +3720,8 @@
37203720
},
37213721
"博客园 - 文章列表 - 个人": {
37223722
"host": "www.cnblogs.com",
3723-
"url": "if (location.pathname.split('/').length === 3 && fun.getCSS('.topicListFooter')) { if (!fun.getCSS('#homepage_top_pager')) {fun.getCSS('#centercontent, .forFlow').insertAdjacentHTML('afterbegin', '<div id=\"homepage_top_pager\" class=\"topicListFooter\"></div>'); fun.getCSS('#centercontent, .forFlow').insertAdjacentHTML('beforeend', '<div id=\"homepage_bottom_pager\" class=\"topicListFooter\"></div>');}; return true}",
3723+
"url": "if (location.pathname.split('/').length === 3 && fun.getCSS('.topicListFooter') != null) { if (!fun.getCSS('#homepage_top_pager')) {fun.getCSS('#centercontent, .forFlow').insertAdjacentHTML('afterbegin', '<div id=\"homepage_top_pager\" class=\"topicListFooter\"></div>'); fun.getCSS('#centercontent, .forFlow').insertAdjacentHTML('beforeend', '<div id=\"homepage_bottom_pager\" class=\"topicListFooter\"></div>');}; return true}",
3724+
"blank": 1,
37243725
"pager": {
37253726
"nextL": "//div[@class='topicListFooter']//a[contains(text(), '下一页')]",
37263727
"pageE": "div.day",
@@ -3826,8 +3827,7 @@
38263827
"pager": {
38273828
"nextL": "//main//a[@class='navigation-tree__link' and @data-state='active']/following-sibling::a[@class='navigation-tree__link'][not(@target='_blank')] | //main//a[@class='navigation-tree__link' and @data-state='active']/following-sibling::div[@class='navigation-tree__nested']/a[@class='navigation-tree__link'][not(@target='_blank')] | //main//a[@class='navigation-tree__link' and @data-state='active']/parent::div/following-sibling::div[@class='navigation-tree__nested']/a[@class='navigation-tree__link'][not(@target='_blank')]",
38283829
"pageE": "main article > *",
3829-
"replaceE": "main navigation-tree, main .scrollbar",
3830-
"scrollD": 1500
3830+
"replaceE": "main navigation-tree, main .scrollbar"
38313831
}
38323832
},
38333833
"Gitee - Explore 列表": {
@@ -5137,8 +5137,7 @@
51375137
"pager": {
51385138
"nextL": "li.next-page > a",
51395139
"pageE": "article[class]:not(.excerpt-minic-index)",
5140-
"replaceE": ".pagination",
5141-
"scrollD": 1500
5140+
"replaceE": ".pagination"
51425141
}
51435142
},
51445143
"美女推 - 图片页": {
@@ -5212,7 +5211,7 @@
52125211
"replaceE": ".pagination"
52135212
}
52145213
},
5215-
"tvv": {
5214+
"mm.tvv.tw": {
52165215
"host": "mm.tvv.tw",
52175216
"url": "return (!fun.indexOF('.html'))",
52185217
"style": ".blog-masonry, .blog-masonry-4col {height: auto !important;} .blog-listing {position: relative !important;float: left !important;top: auto !important;left: auto !important;} .blog-title > a {white-space: nowrap;overflow: hidden;text-overflow: ellipsis;} .blog-image img {min-height: 300px;}",

0 commit comments

Comments
 (0)