Skip to content

Commit ec50801

Browse files
committed
新增 [游侠网] 支持; 优化 [3DM游戏网、游民星空] 规则
1 parent c24fb37 commit ec50801

1 file changed

Lines changed: 113 additions & 33 deletions

File tree

Autopage.user.js

Lines changed: 113 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
// ==UserScript==
22
// @name 自动无缝翻页
3-
// @version 1.3.1
3+
// @version 1.3.2
44
// @author X.I.U
55
// @description 自动无缝翻页,目前支持:所有 Discuz!论坛、423Down、Apphot、不死鸟、小众软件、异次元软件、微当下载、异星软件空间、豆瓣电影、3DM游戏网、游民星空、千图网、RARBG、FitGirl Repacks、AlphaCoders、PubMed...
66
// @match *://*/*
77
// @exclude *://www.423down.com/*.html
88
// @exclude *://apphot.cc/*.html
9+
// @connect www.gamersky.com
910
// @icon https://i.loli.net/2021/03/07/rdijeYm83pznxWq.png
1011
// @grant GM_xmlhttpRequest
1112
// @grant GM_registerMenuCommand
@@ -35,6 +36,7 @@
3536
'search.douban.com',
3637
'www.3dmgame.com',
3738
'www.gamersky.com',
39+
'www.ali213.net',
3840
'www.58pic.com',
3941
'rarbgprx.org',
4042
'www.yxssp.com'];
@@ -57,11 +59,23 @@
5759
// 默认 ID 为 0
5860
var curSite = {SiteTypeID: 0};
5961

60-
// 自动翻页规则
61-
// type:1 = 脚本实现自动无缝翻页,2 = 网站自带了自动无缝翻页功能,只需要点击下一页按钮即可,这时 nextText 为按钮文本,避免一瞬间加载太多次下一页
62-
// HT_insert:1 = 插入该元素本身的前面;2 = 插入该元素当中,第一个子元素前面;3 = 插入该元素当中,最后一个子元素后面;4 = 插入该元素本身的后面;
63-
// scrollDelta:数值越大,滚动条触发点越靠上(越早开始翻页),一般是访问网页速度越慢,该值就需要越大
64-
// function:before = 插入前执行函数;after = 插入后执行函数;parameter = 参数
62+
/*
63+
自动翻页规则
64+
type:
65+
1 = 脚本实现自动无缝翻页
66+
2 = 网站自带了自动无缝翻页功能,只需要点击下一页按钮即可,这时 nextText 为按钮文本,避免一瞬间加载太多次下一页
67+
3 = 依靠元素距离可视区域底部的距离来触发翻页
68+
HT_insert:
69+
1 = 插入该元素本身的前面;
70+
2 = 插入该元素当中,第一个子元素前面;
71+
3 = 插入该元素当中,最后一个子元素后面;
72+
4 = 插入该元素本身的后面;
73+
scrollDelta:数值越大,滚动条触发点越靠上(越早开始翻页),一般是访问网页速度越慢,该值就需要越大
74+
function:
75+
before = 插入前执行函数;
76+
after = 插入后执行函数;
77+
parameter = 参数
78+
*/
6579
let DBSite = {
6680
discuz_forum: {
6781
SiteTypeID: 1,
@@ -289,27 +303,65 @@
289303
_3dmgame: {
290304
SiteTypeID: 19,
291305
pager: {
292-
type: 1,
306+
type: 3,
293307
nextLink: '//li[@class="next"]/a[@href]',
294-
pageElement: 'css;.news_warp_center > p',
308+
pageElement: 'css;.news_warp_center > *',
295309
HT_insert: ['css;.news_warp_center', 3],
296310
replaceE: 'css;.pagewrap',
297-
scrollDelta: 1000
311+
scrollElement: '.pagewrap',
312+
scrollDelta: 400
298313
}
299314
},
300-
gamersky: {
315+
gamersky_ent: {
301316
SiteTypeID: 20,
302317
pager: {
303-
type: 1,
318+
type: 3,
304319
nextLink: '//div[@class="page_css"]/a[text()="下一页"][@href]',
305-
pageElement: 'css;.Mid2L_con > p',
320+
pageElement: 'css;.Mid2L_con > *:not(.gs_nc_editor):not(.pagecss):not(.page_css):not(.gs_ccs_solve):not(.post_ding)',
306321
HT_insert: ['css;.page_css', 1],
307322
replaceE: 'css;.page_css',
308-
scrollDelta: 1000
323+
scrollElement: '.page_css',
324+
scrollDelta: 100
309325
}
310326
},
311-
_58pic: {
327+
gamersky_gl: {
312328
SiteTypeID: 21,
329+
pager: {
330+
type: 3,
331+
nextLink: '//div[@class="page_css"]/a[text()="下一页"][@href]',
332+
pageElement: 'css;.Mid2L_con > *:not(.gs_nc_editor):not(.pagecss):not(.gs_ccs_solve):not(.post_ding)',
333+
HT_insert: ['css;.gs_nc_editor', 1],
334+
replaceE: 'css;.page_css',
335+
scrollElement: '.pagecss',
336+
scrollDelta: -1000
337+
}
338+
},
339+
ali213_www: {
340+
SiteTypeID: 22,
341+
pager: {
342+
type: 3,
343+
nextLink: '//a[@id="after_this_page"][@href]',
344+
pageElement: 'css;#Content >*:not(.news_ding):not(.page_fenye)',
345+
HT_insert: ['css;.page_fenye', 1],
346+
replaceE: 'css;.page_fenye',
347+
scrollElement: '.page_fenye',
348+
scrollDelta: 400
349+
}
350+
},
351+
ali213_gl: {
352+
SiteTypeID: 23,
353+
pager: {
354+
type: 3,
355+
nextLink: '//a[@class="next n"][@href]',
356+
pageElement: 'css;.c-detail >*',
357+
HT_insert: ['css;.c-detail', 3],
358+
replaceE: 'css;.page_fenye',
359+
scrollElement: '.page_fenye',
360+
scrollDelta: 400
361+
}
362+
},
363+
_58pic: {
364+
SiteTypeID: 24,
313365
pager: {
314366
type: 1,
315367
nextLink: '//div[contains(@class,"page-box")]//a[text()="下一页"][@href]',
@@ -323,7 +375,7 @@
323375
}
324376
},
325377
_58pic_c: {
326-
SiteTypeID: 22,
378+
SiteTypeID: 25,
327379
pager: {
328380
type: 1,
329381
nextLink: '//div[contains(@class,"page-box")]//a[text()="下一页"][@href]',
@@ -337,7 +389,7 @@
337389
}
338390
},
339391
rarbgprx: {
340-
SiteTypeID: 23,
392+
SiteTypeID: 26,
341393
pager: {
342394
type: 1,
343395
nextLink: '(//a[@title="next page"])[1][@href]',
@@ -348,7 +400,7 @@
348400
}
349401
},
350402
yxssp: {
351-
SiteTypeID: 24,
403+
SiteTypeID: 27,
352404
pager: {
353405
type: 1,
354406
nextLink: '//div[@class="page-nav td-pb-padding-side"]/a[last()][@href]',
@@ -422,11 +474,21 @@
422474
break;
423475
case "www.3dmgame.com":
424476
curSite = DBSite._3dmgame;
425-
document.lastChild.appendChild(document.createElement('style')).textContent = `#Comments_wrap {display: none !important;}` // 隐藏评论区
426477
break;
427478
case "www.gamersky.com":
428-
curSite = DBSite.gamersky;
429-
document.lastElementChild.appendChild(document.createElement('style')).textContent = `.Comment {display: none !important;}` // 隐藏评论区
479+
if (location.pathname.indexOf("/ent/") > -1) {
480+
curSite = DBSite.gamersky_ent;
481+
} else {
482+
curSite = DBSite.gamersky_gl;
483+
}
484+
//document.lastElementChild.appendChild(document.createElement('style')).textContent = `.Comment {display: none !important;}` // 隐藏评论区
485+
break;
486+
case "www.ali213.net":
487+
curSite = DBSite.ali213_www;
488+
break;
489+
case "gl.ali213.net":
490+
curSite = DBSite.ali213_gl;
491+
document.lastElementChild.appendChild(document.createElement('style')).textContent = `.n_show_b {display: none !important;}` // 隐藏部分碍事元素
430492
break;
431493
case "www.58pic.com":
432494
if (location.pathname.indexOf("/tupian/") > -1) {
@@ -468,19 +530,29 @@
468530
if (curSite.SiteTypeID > 0) {
469531
windowScroll(function (direction, e) {
470532
if (direction === "down") { // 下滑才准备翻页
471-
let scrollTop = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop;
472-
let scrollDelta = curSite.pager.scrollDelta;
473-
if (document.documentElement.scrollHeight <= document.documentElement.clientHeight + scrollTop + scrollDelta) {
474-
if (curSite.pager.type === 1) {
533+
let scrollTop = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop,
534+
scrollHeight = window.innerHeight || document.documentElement.clientHeight,
535+
scrollDelta = curSite.pager.scrollDelta;
536+
if (curSite.pager.type === 3) { // 翻页类型 3
537+
let scrollElement = document.querySelector(curSite.pager.scrollElement);
538+
//console.log(scrollElement.offsetTop - (scrollTop + scrollHeight), scrollDelta, curSite.SiteTypeID)
539+
if (scrollElement.offsetTop - (scrollTop + scrollHeight) <= scrollDelta) {
540+
if (curSite.SiteTypeID === 21) curSite.pager.scrollDelta -= 800 // 游民星空的比较奇葩,需要特殊处理下
475541
ShowPager.loadMorePage();
476-
} else {
477-
let autopbn = document.querySelector(curSite.pager.nextLink);
478-
if (autopbn) { // 如果正在加载,就不再点击
479-
if (!curSite.pager.nextText) { // 如果没有指定 nextText 就直接点击
480-
autopbn.click();
481-
} else if (autopbn.innerText.indexOf(curSite.pager.nextText) > -1){ // 如果指定了 nextText 就需要判断后再点击(避免已经在加载了,还重复点击)
482-
autopbn.click();
542+
}
543+
} else {
544+
if (document.documentElement.scrollHeight <= scrollHeight + scrollTop + scrollDelta) {
545+
if (curSite.pager.type === 2) { // 翻页类型 2
546+
let autopbn = document.querySelector(curSite.pager.nextLink);
547+
if (autopbn) { // 如果正在加载,就不再点击
548+
if (!curSite.pager.nextText) { // 如果没有指定 nextText 就直接点击
549+
autopbn.click();
550+
} else if (autopbn.innerText.indexOf(curSite.pager.nextText) > -1){ // 如果指定了 nextText 就需要判断后再点击(避免已经在加载了,还重复点击)
551+
autopbn.click();
552+
}
483553
}
554+
} else {
555+
ShowPager.loadMorePage();
484556
}
485557
}
486558
}
@@ -490,6 +562,14 @@
490562
}
491563

492564

565+
function getElementToPageTop(el) {
566+
if(el.parentElement) {
567+
return getElementToPageTop(el.parentElement) + el.offsetTop
568+
}
569+
return el.offsetTop
570+
}
571+
572+
493573
// 隐藏帖子内的 [下一页] 按钮
494574
function hidePgbtn() {
495575
let style_hidePgbtn = document.createElement('style');
@@ -658,8 +738,8 @@
658738
let curPageEle = getElementByXpath(curSite.pager.nextLink);
659739
var url = this.getFullHref(curPageEle);
660740
//console.log(`${url} ${curPageEle} ${curSite.pageUrl}`);
661-
if(url === '') return;
662-
if(curSite.pageUrl === url) return;// 避免重复加载相同的页面
741+
if (url === '') return;
742+
if (curSite.pageUrl === url) return;// 避免重复加载相同的页面
663743
curSite.pageUrl = url;
664744
// 读取下一页的数据
665745
curSite.pager.startFilter && curSite.pager.startFilter();

0 commit comments

Comments
 (0)