Skip to content

Commit c3d2ebf

Browse files
committed
新增 [谷歌搜索]、[搜狗搜索]、[头条搜索]、[360 搜索] 手机版支持; 优化 [自定义翻页规则] 功能及样式(支持同一网站不同页面规则了)
1 parent ca47609 commit c3d2ebf

1 file changed

Lines changed: 73 additions & 22 deletions

File tree

Autopage.user.js

Lines changed: 73 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// @name:zh-CN 自动无缝翻页
44
// @name:zh-TW 自動無縫翻頁
55
// @name:en AutoPager
6-
// @version 4.9.1
6+
// @version 4.9.2
77
// @author X.I.U
88
// @description 无缝拼接下一页内容(瀑布流,追求小而美),目前支持:【所有「Discuz!、Flarum、phpBB、Xiuno、XenForo、NexusPHP」论坛】【百度、谷歌、必应、搜狗、微信、360、Yahoo、Yandex 等搜索引擎】、贴吧、豆瓣、知乎、微博、NGA、V2EX、B 站(Bilibili)、煎蛋网、糗事百科、龙的天空、起点中文、IT之家、千图网、Pixabay、Pixiv、3DM、游侠网、游民星空、NexusMods、Steam 创意工坊、CS.RIN.RU、BT之家、萌番组、动漫花园、樱花动漫、爱恋动漫、AGE 动漫、Nyaa、SrkBT、RARBG、SubHD、423Down、不死鸟、扩展迷、小众软件、【动漫狂、漫画猫、漫画屋、漫画 DB、动漫之家、拷贝漫画、包子漫画、Mangabz、Xmanhua 等漫画网站】、PubMed、Z-Library、GreasyFork、Github、StackOverflow(以上仅一小部分,更多的写不下了...
99
// @description:zh-TW 無縫拼接下一頁內容(瀑布流,追求小而美),支持各種論壇、搜索引擎、漫畫網站~
@@ -1176,7 +1176,7 @@
11761176
end:
11771177
for (let now in DBSite) { // 遍历 对象
11781178
if (!DBSite[now].host) continue; // 如果不存在则继续下一个循环
1179-
1179+
//console.log(DBSite[now].host)
11801180
// 如果是 数组
11811181
if (Array.isArray(DBSite[now].host)) {
11821182

@@ -1189,13 +1189,13 @@
11891189
if (DBSite[now].functionS) {
11901190
if (typeof DBSite[now].functionS == 'function') {
11911191
DBSite[now].functionS();
1192-
} else { // 自定义翻页规则时
1193-
if (new Function (DBSite[now].functionS)() === true) curSite = DBSite[now];
1192+
} else { // 自定义翻页规则时,因为同域名不同页面 functionS 分开写,所以如果没找到就需要跳出当前数组循环,继续规则循环
1193+
if (new Function (DBSite[now].functionS)() === true) {curSite = DBSite[now];} else {break;}
11941194
}
11951195
} else {
11961196
curSite = DBSite[now];
11971197
}
1198-
support = true; break; // 如果找到了就退出循环
1198+
support = true; break end; // 如果找到了就退出所有循环
11991199
}
12001200
}
12011201

@@ -1209,8 +1209,8 @@
12091209
if (DBSite[now].functionS) {
12101210
if (typeof DBSite[now].functionS == 'function') {
12111211
DBSite[now].functionS();
1212-
} else { // 自定义翻页规则时
1213-
if (new Function (DBSite[now].functionS)() === true) curSite = DBSite[now];
1212+
} else { // 自定义翻页规则时,因为同域名不同页面 functionS 分开写,所以如果没找到就需要继续规则循环
1213+
if (new Function (DBSite[now].functionS)() === true) {curSite = DBSite[now];} else {continue;}
12141214
}
12151215
} else {
12161216
curSite = DBSite[now];
@@ -1602,7 +1602,7 @@ function: {
16021602
}, // 笔趣阁 模板的小说网站
16031603
baidu: {
16041604
host: 'www.baidu.com',
1605-
functionS: ()=> {locationC = true; if (lp == '/s') {curSite = DBSite.baidu;} else if (location.pathname.slice(location.pathname.length - 2,location.pathname.length) == '/s') {location.hostname = 'm.baidu.com';}},
1605+
functionS: ()=> {locationC = true; if (lp == '/s') {curSite = DBSite.baidu;} else if (location.pathname.slice(location.pathname.length - 2,location.pathname.length) == '/s' || isMobile()) {location.hostname = 'm.baidu.com';}},
16061606
style: '.new-pmd .c-img-border {position: initial !important;} .op-bk-polysemy-video__wrap.c-gap-bottom {display: none !important;}',
16071607
pager: {
16081608
nextL: 'id("page")//a[contains(text(),"下一页")]',
@@ -1625,7 +1625,11 @@ function: {
16251625
google: {
16261626
host: /^www\.google\./,
16271627
functionS: ()=> {if (lp == '/search' && !indexOF('tbm=isch', 's')) {
1628-
curSite = DBSite.google;
1628+
if (indexOF('sclient=mobile', 's') || isMobile()) {
1629+
curSite = DBSite.google_m;
1630+
} else {
1631+
curSite = DBSite.google;
1632+
}
16291633
} else if (lp == '/scholar') {
16301634
curSite = DBSite.google_scholar;
16311635
}},
@@ -1641,6 +1645,14 @@ function: {
16411645
bF: google_bF
16421646
}
16431647
}, // 谷歌 搜索
1648+
google_m: {
1649+
pager: {
1650+
type: 2,
1651+
nextL: 'css;a[aria-label="查看更多"], a[aria-label="See more" i]',
1652+
isHidden: true,
1653+
scrollD: 1000
1654+
}
1655+
}, // 谷歌 搜索 - 手机版
16441656
bing: {
16451657
host: ['www.bing.com','cn.bing.com'],
16461658
functionS: ()=> {if (lp == '/search') {
@@ -1656,7 +1668,7 @@ function: {
16561668
replaceE: 'css;#b_results > .b_pag',
16571669
scrollD: 2000
16581670
}
1659-
}, // 必应 搜索
1671+
}, // 必应 搜索 + 手机版
16601672
sogou: {
16611673
host: 'www.sogou.com',
16621674
functionS: ()=> {if (lp != '/') {curSite = DBSite.sogou;}},
@@ -1668,6 +1680,16 @@ function: {
16681680
scrollD: 2000
16691681
}
16701682
}, // 搜狗 搜索
1683+
sogou_m: {
1684+
host: ['m.sogou.com', 'wap.sogou.com'],
1685+
functionS: ()=> {if (lp != '/') {curSite = DBSite.sogou_m;}},
1686+
pager: {
1687+
type: 2,
1688+
nextL: 'css;#ajax_next_page',
1689+
isHidden: true,
1690+
scrollD: 1000
1691+
}
1692+
}, // 搜狗 搜索 - 手机版
16711693
sogou_weixin: {
16721694
host: 'weixin.sogou.com',
16731695
functionS: ()=> {if (lp == '/') {
@@ -1692,7 +1714,13 @@ function: {
16921714
}, // 搜狗微信 - 搜索
16931715
toutiao: {
16941716
host: ['www.toutiao.com', 'so.toutiao.com'],
1695-
functionS: ()=> {if (location.hostname != 'www.toutiao.com' && lp == '/search') curSite = DBSite.toutiao;},
1717+
functionS: ()=> {if (location.hostname != 'www.toutiao.com') {
1718+
if (lp == '/search/' || isMobile()) {
1719+
curSite = DBSite.toutiao_m;
1720+
} else if (lp == '/search') {
1721+
curSite = DBSite.toutiao;
1722+
}
1723+
}},
16961724
pager: {
16971725
nextL: '//div[contains(@class, "-pagination")]/a[string()="下一页"]',
16981726
pageE: 'css;div[class*="-result-list"] > .result-content[data-i]',
@@ -1706,6 +1734,14 @@ function: {
17061734
}
17071735
}
17081736
}, // 头条 搜索
1737+
toutiao_m: {
1738+
pager: {
1739+
nextL: 'css;#page-bottom a[class*="containerRight_"], #page-bottom a[class*="container_"]',
1740+
pageE: 'css;#results > div',
1741+
replaceE: 'css;#page-bottom',
1742+
scrollD: 2000
1743+
}
1744+
}, // 头条 搜索 - 手机版
17091745
so: {
17101746
host: 'www.so.com',
17111747
functionS: ()=> {if (lp != '/') {curSite = DBSite.so; insStyle('img {opacity: 1 !important;}')}},
@@ -1721,6 +1757,16 @@ function: {
17211757
bFp: [0, 'img[data-isrc]', 'data-isrc']
17221758
}
17231759
}, // 360 搜索
1760+
so_m: {
1761+
host: 'm.so.com',
1762+
functionS: ()=> {if (lp != '/') {curSite = DBSite.so_m;}},
1763+
pager: {
1764+
type: 2,
1765+
nextL: 'css;#load-more',
1766+
isHidden: true,
1767+
scrollD: 1000
1768+
}
1769+
}, // 360 搜索 - 手机版
17241770
duckduckgo: {
17251771
host: 'duckduckgo.com',
17261772
functionS: ()=> {
@@ -7637,6 +7683,10 @@ function: {
76377683
function isHidden(el){
76387684
return (el.offsetParent === null);
76397685
}
7686+
// 判断是否为手机版(是则返回 true)
7687+
function isMobile(){
7688+
return (/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|MicroMessenger|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i.test(navigator.userAgent) || (window.screen.width < 500 && window.screen.height < 800));
7689+
}
76407690
// 判断 URL 是否存在指定文本
76417691
function indexOF(e, l = 'p', low = false){
76427692
switch (l) {
@@ -7717,15 +7767,15 @@ function: {
77177767
// 插入网页
77187768
let _html = `<div id="Autopage_customRules" style="left: 0 !important; right: 0 !important; top: 0 !important; bottom: 0 !important; width: 100% !important; height: 100% !important; margin: auto !important; padding: 25px 10px 10px 10px !important; position: fixed !important; opacity: 0.9 !important; z-index: 99999 !important; background-color: #eee !important; color: #222 !important; font-size: 14px !important;">
77197769
<h3><strong>自定义翻页规则(优先于脚本内置规则)</strong></h3>
7720-
<ul style="list-style: disc !important; margin-left: 35px !important;">
7721-
<li>翻页规则为 JSON 格式,因此大家需要先去了解一下 JSON 的基本格式(如:两边都需要双引号、最后一个末尾不能加逗号等)。</li>
7722-
<li>具体的翻页规则说明、示例,为了方便更新及补充,我都写到 <a href="https://github.com/XIU2/UserScript/issues/176" target="_blank">Github</a> 及 <a href="https://greasyfork.org/scripts/419215" target="_blank">Greasyfork</a> 里面了。</li>
7723-
<li>该脚本最初只是自用的,没有考虑到自定义翻页规则,因此我只能勉强实现该功能,但局限性比较多,只适用于简单的网站。</li>
7724-
<li>脚本会自动格式化规则,因此无需手动缩进、换行。</li>
7725-
</ul>
7726-
<p style="color: #ff3535 !important;">注意:不要完全照搬脚本内置规则,因为和标准 JSON 格式有所差别,如:必须两边内容都加双引号(不能用单引号)。</p>
77277770
<details>
77287771
<summary><kbd><strong>「 点击展开 查看示例 」(把常用规则都放在一起了,方便需要的时候可复制一份修改使用)</strong></kbd></summary>
7772+
<ul style="list-style: disc !important; margin-left: 35px !important;">
7773+
<li>翻页规则为 JSON 格式,因此大家需要先去<strong>了解一下 JSON 的基本格式</strong>。</li>
7774+
<li>具体的翻页规则说明、示例,为了方便更新及补充,我都写到 <strong><a href="https://github.com/XIU2/UserScript/issues/176" target="_blank">Github</a> 及 <a href="https://greasyfork.org/scripts/419215" target="_blank">Greasyfork</a></strong> 里面了。</li>
7775+
<li>该功能只适用于<strong>简单的网站</strong>,当然这类网站占<strong>大多数</strong>,我写的数百规则里大部分都是这类网站。</li>
7776+
<li>脚本会自动格式化规则,因此<strong>无需手动缩进、换行</strong>。</li>
7777+
</ul>
7778+
<p style="color: #ff3535 !important;">注意:不要完全照搬脚本内置规则,因为和标准 JSON 格式等有所差别。</p>
77297779
<pre>
77307780
"aaa": {
77317781
"host": "aaa",
@@ -7762,26 +7812,27 @@ function: {
77627812
</pre>
77637813
</details>
77647814
7765-
<textarea id="Autopage_customRules_textarea" style="min-width:95% !important; min-height:300px !important; display: block !important; margin: 10px 0 10px 0; white-space:nowrap !important; overflow:scroll !important; resize: auto !important;" placeholder="留空等于默认的 {}">${JSON.stringify(GM_getValue('menu_customRules', {}), null, '\t')}</textarea>
7815+
<textarea id="Autopage_customRules_textarea" style="min-width:95% !important; min-height:75% !important; display: block !important; margin: 10px 0 10px 0; white-space:nowrap !important; overflow:scroll !important; resize: auto !important;" placeholder="留空等于默认的 {}">${JSON.stringify(GM_getValue('menu_customRules', {}), null, '\t')}</textarea>
77667816
<button id="Autopage_customRules_save">保存并刷新</button><button id="Autopage_customRules_cancel">取消</button>
77677817
</div>`
77687818
document.documentElement.insertAdjacentHTML('beforeend', _html);
7819+
document.body.style.overflow = 'hidden';
77697820
// 点击事件
77707821
getCSS('#Autopage_customRules_save').onclick = function () {
77717822
let rules = getCSS('#Autopage_customRules_textarea').value;
7772-
console.log(rules)
7823+
//console.log(rules)
77737824
if (!rules) rules = '{}'
77747825
try {
77757826
rules = JSON.parse(rules)
7776-
console.log(rules)
7827+
//console.log(rules)
77777828
GM_setValue('menu_customRules', rules)
77787829
location.reload();
77797830
} catch (e) {
77807831
console.error('自定义规则存在格式错误:\n' + e + '\n\n注意事项:\n规则中冒号 : 左右的内容都需要加上双引号 " 而不能用单引号 \',如果内容中含有双引号则需要对双引号转义(即 \" 这样)或者改用单引号')
77817832
window.alert('自定义规则存在格式错误:\n' + e + '\n\n注意事项:\n规则中冒号 : 左右的内容都需要加上双引号 " 而不能用单引号 \',如果内容中含有双引号则需要对双引号转义(即 \" 这样)或者改用单引号');
77827833
}
77837834
}
7784-
getCSS('#Autopage_customRules_cancel').onclick = function () {getCSS('#Autopage_customRules').remove();}
7835+
getCSS('#Autopage_customRules_cancel').onclick = function () {document.body.style.overflow = ''; getCSS('#Autopage_customRules').remove();}
77857836
}
77867837
// 显示页码
77877838
function pageNumber(type) {

0 commit comments

Comments
 (0)