Skip to content

Commit d28edfd

Browse files
committed
新增 [百度贴吧] 支持; 优化 [千图网] 翻页效果(屏蔽末尾的很大的 [下一页] 按钮,完全无缝了~)
1 parent 1291276 commit d28edfd

1 file changed

Lines changed: 90 additions & 31 deletions

File tree

Autopage.user.js

Lines changed: 90 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// ==UserScript==
22
// @name 自动无缝翻页
3-
// @version 1.5.3
3+
// @version 1.5.4
44
// @author X.I.U
5-
// @description 自动无缝翻页,目前支持:[所有使用「Discuz!、Flarum、DUX(WordPress)」的网站]、百度、谷歌、豆瓣、微博、千图网、3DM、游侠网、游民星空、Steam 创意工坊、423Down、不死鸟、小众软件、微当下载、异次元软件、老殁殁漂遥、异星软件空间、古风漫画网、砂之船动漫家、RARBG、PubMed、AfreecaTV、GreasyFork、AlphaCoders、Crackhub213、FitGirl Repacks...
5+
// @description 自动无缝翻页,目前支持:[所有使用「Discuz!、Flarum、DUX(WordPress)」的网站]、百度、谷歌、贴吧、豆瓣、微博、千图网、3DM、游侠网、游民星空、Steam 创意工坊、423Down、不死鸟、小众软件、微当下载、异次元软件、老殁殁漂遥、异星软件空间、古风漫画网、砂之船动漫家、RARBG、PubMed、AfreecaTV、GreasyFork、AlphaCoders、Crackhub213、FitGirl Repacks...
66
// @match *://*/*
77
// @connect www.gamersky.com
88
// @icon https://i.loli.net/2021/03/07/rdijeYm83pznxWq.png
@@ -23,7 +23,7 @@
2323
'use strict';
2424
var webType, curSite = {SiteTypeID: 0};
2525
// 目前支持的网站
26-
const websiteList = ['www.baidu.com', 'www.google.com', 'movie.douban.com', 'weibo.com', 'www.58pic.com',
26+
const websiteList = ['www.baidu.com', 'www.google.com', 'tieba.baidu.com', 'movie.douban.com', 'weibo.com', 'www.58pic.com',
2727
'www.3dmgame.com', 'www.ali213.net', 'gl.ali213.net', 'www.gamersky.com', 'steamcommunity.com',
2828
'www.423down.com', 'iao.su', 'www.appinn.com', 'www.weidown.com', 'www.iplaysoft.com', 'www.mpyit.com', 'www.yxssp.com',
2929
'www.gufengmh8.com', 'www.szcdmj.com',
@@ -188,6 +188,20 @@
188188
scrollDelta: 1500
189189
}
190190
},
191+
baidu_tieba: {
192+
SiteTypeID: 0,
193+
pager: {
194+
type: 1,
195+
nextLink: '//a[@class="next pagination-item "][@href]',
196+
pageElement: 'css;#thread_list > li',
197+
HT_insert: ['css;#thread_list', 3],
198+
replaceE: 'css;#frs_list_pager',
199+
scrollDelta: 1500
200+
},
201+
function: {
202+
before: baidu_tieba_beforeFunction
203+
}
204+
},
191205
douban_subject_comments: {
192206
SiteTypeID: 0,
193207
pager: {
@@ -564,8 +578,8 @@
564578
pager: {
565579
type: 1,
566580
nextLink: '//a[@id="next_page"][@href]',
567-
pageElement: 'css;.thumb-container-big, .avatar-thumb, .thumb-element',
568-
HT_insert: ['css;.thumb-container-big:nth-last-child(1), .avatar-thumb:nth-last-child(1), .thumb-element:nth-last-child(1)', 4],
581+
pageElement: 'css;.page_container > .center > div',
582+
HT_insert: ['css;.page_container > .center', 3],
569583
replaceE: '//div[@class="hidden-xs hidden-sm"]/..',
570584
scrollDelta: 1000
571585
}
@@ -588,6 +602,7 @@
588602
// 用于脚本判断(针对部分特殊的网站)
589603
const SiteType = {
590604
GOOGLE: DBSite.google.SiteTypeID,
605+
BAIDU_TIEBA: DBSite.baidu_tieba.SiteTypeID,
591606
GAMERSKY_GL: DBSite.gamersky_gl.SiteTypeID,
592607
STEAMCOMMUNITY: DBSite.steamcommunity.SiteTypeID
593608
};
@@ -602,6 +617,13 @@
602617
case 'www.google.com': // < 谷歌搜索 >
603618
if (location.pathname === '/search') curSite = DBSite.google;
604619
break;
620+
case 'tieba.baidu.com': // < 百度贴吧 >
621+
if (location.pathname === '/f') {
622+
// 修复帖子列表中预览图片,在切换下一个/上一个图片时,多出来的图片上下边距
623+
document.lastElementChild.appendChild(document.createElement('style')).textContent = 'img.j_retract {margin-top: 0 !important;margin-bottom: 0 !important;}';
624+
curSite = DBSite.baidu_tieba;
625+
}
626+
break;
605627
case 'movie.douban.com': // < 豆瓣评论 >
606628
if (location.pathname.indexOf('/subject') > -1 && location.pathname.indexOf('/comments') > -1) { // 短评列表
607629
curSite = DBSite.douban_subject_comments;
@@ -616,6 +638,8 @@
616638
break;
617639
case 'www.58pic.com': // < 千图网 >
618640
if (location.pathname.indexOf('/tupian/') > -1) {
641+
// 隐藏末尾很大的 [下一页] 按钮
642+
document.lastElementChild.appendChild(document.createElement('style')).textContent = '.qtw-card.place-box.is-two {display: none !important;}';
619643
curSite = DBSite._58pic;
620644
} else if (location.pathname.indexOf('/c/') > -1) {
621645
curSite = DBSite._58pic_c;
@@ -628,8 +652,9 @@
628652
curSite = DBSite.ali213_www;
629653
break;
630654
case 'gl.ali213.net': // < 游侠网 - 攻略页 >
655+
// 隐藏部分碍事元素
656+
document.lastElementChild.appendChild(document.createElement('style')).textContent = '.n_show_b {display: none !important;}';
631657
curSite = DBSite.ali213_gl;
632-
document.lastElementChild.appendChild(document.createElement('style')).textContent = '.n_show_b {display: none !important;}' // 隐藏部分碍事元素
633658
break;
634659
case 'www.gamersky.com': // < 游民星空 >
635660
if (location.pathname.indexOf('/ent/') > -1) {
@@ -710,11 +735,11 @@
710735
curSite = DBSite.alphacoders_art;
711736
setTimeout(alphacoders_art_beforeFunction_0, 1000);
712737
break;
713-
case 'wall.alphacoders.com':
738+
/*case 'wall.alphacoders.com': // 已经原生支持自动无缝翻页了
714739
case 'avatars.alphacoders.com':
715740
case 'mobile.alphacoders.com':
716741
curSite = DBSite.alphacoders_wall;
717-
break;
742+
break;*/
718743
case 'crackhub.site': // < 游戏下载网站 >
719744
curSite = DBSite.fitgirl;
720745
document.lastElementChild.appendChild(document.createElement('style')).textContent = 'html.wp-dark-mode-active .inside-article {background-color: var(--wp-dark-mode-bg);}'
@@ -788,9 +813,19 @@
788813
function dux_beforeFunction(pageElems) {
789814
pageElems.forEach(function (one) {
790815
let now = one.querySelector('img.thumb[data-src]')
791-
if (now) {
792-
now.setAttribute('src', now.dataset.src)
793-
}
816+
if (now) {now.src = now.dataset.src;}
817+
});
818+
return pageElems
819+
}
820+
821+
822+
// 百度贴吧 的插入前函数(加载图片)
823+
function baidu_tieba_beforeFunction(pageElems) {
824+
pageElems.forEach(function (one) {
825+
one.querySelectorAll('img.threadlist_pic[data-original]').forEach(function (now) {
826+
now.src = now.dataset.original;
827+
now.style.display = 'inline';
828+
})
794829
});
795830
return pageElems
796831
}
@@ -799,14 +834,12 @@
799834
// 58pic 的插入前函数(加载图片)
800835
function _58pic_beforeFunction(pageElems) {
801836
let is_one = document.querySelector('.qtw-card.place-box.is-one');
802-
if (is_one && is_one.style.display != 'none') {
803-
is_one.setAttribute('style', 'display: none;')
804-
}
837+
if (is_one && is_one.style.display != 'none') {is_one.style.display = 'none';}
805838
pageElems.forEach(function (one) {
806839
let now = one.querySelector('img.lazy')
807840
if (now && now.getAttribute('src') != now.dataset.original) {
808-
now.setAttribute('src', now.dataset.original)
809-
now.setAttribute('style', 'display: block;')
841+
now.src = now.dataset.original;
842+
now.style.display = 'block';
810843
}
811844
});
812845
return pageElems
@@ -816,9 +849,7 @@
816849
// 游民星空攻略 的插入前函数(移除下一页底部的 "更多相关内容请关注:xxx" 文字)
817850
function gamersky_gl_beforeFunction(pageElems) {
818851
pageElems.forEach(function (one) {
819-
if (one.tagName === 'P' && one.textContent.indexOf('更多相关内容请关注') > -1) {
820-
one.style.display = 'none';
821-
}
852+
if (one.tagName === 'P' && one.textContent.indexOf('更多相关内容请关注') > -1) {one.style.display = 'none';}
822853
});
823854
return pageElems
824855
}
@@ -842,7 +873,7 @@
842873
pageElems.forEach(function (one) {
843874
let now = one.querySelector('img.lazyload')
844875
if (now && !now.src) {
845-
now.setAttribute('src', now.dataset.src)
876+
now.src = now.dataset.src;
846877
now.setAttribute('srcset', now.dataset.src)
847878
now.setAttribute('class', 'lazyloaded')
848879
}
@@ -854,7 +885,7 @@
854885
// alphacoders_art 的插入前函数(图片结构调整)
855886
function alphacoders_art_beforeFunction(pageElems) {
856887
pageElems.forEach(function (one) {
857-
one.setAttribute('style','float: left');
888+
one.style.float = 'left';
858889
});
859890
return pageElems
860891
}
@@ -863,7 +894,7 @@
863894
let pageElems1 = document.querySelectorAll('.container-masonry > div')
864895
document.querySelector('.container-masonry').style.height = 'auto'
865896
pageElems1.forEach(function (one) {
866-
one.setAttribute('style','float: left');
897+
one.style.float = 'left';
867898
});
868899
}
869900

@@ -939,7 +970,7 @@
939970
} else {
940971
let now = one.querySelector('img[data-original]')
941972
if (now) {
942-
now.setAttribute('src', now.dataset.original)
973+
now.src = now.dataset.original;
943974
now.style.display = 'inline';
944975
}
945976
}
@@ -1160,12 +1191,14 @@
11601191
if (curSite.pager) {
11611192
let curPageEle = getElementByXpath(curSite.pager.nextLink);
11621193
var url = this.getFullHref(curPageEle);
1163-
console.log(`${url} ${curPageEle} ${curSite.pageUrl}`);
1194+
//console.log(url, curPageEle, curSite.pageUrl);
11641195
if (url === '') return;
11651196
if (curSite.pageUrl === url) return;// 避免重复加载相同的页面
11661197
curSite.pageUrl = url;
1198+
if (curSite.SiteTypeID === SiteType.BAIDU_TIEBA) {
1199+
url = url + '&pagelets=frs-list%2Fpagelet%2Fthread&pagelets_stamp=' + new Date().getTime();
1200+
}
11671201
// 读取下一页的数据
1168-
curSite.pager.startFilter && curSite.pager.startFilter();
11691202
GM_xmlhttpRequest({
11701203
url: url,
11711204
method: 'GET',
@@ -1176,7 +1209,7 @@
11761209
var newBody = ShowPager.createDocumentByString(response.responseText);
11771210
let pageElems = getAllElements(curSite.pager.pageElement, newBody, newBody),
11781211
toElement = getAllElements(curSite.pager.HT_insert[0])[0];
1179-
console.log(curSite.pager.pageElement, pageElems)
1212+
//console.log(curSite.pager.pageElement, pageElems)
11801213

11811214
if (pageElems.length >= 0) {
11821215
// 如果有插入前函数就执行函数
@@ -1190,6 +1223,7 @@
11901223

11911224
// 插入位置
11921225
let addTo1 = addTo(curSite.pager.HT_insert[1]);
1226+
11931227
// 插入新页面元素
11941228
if (curSite.SiteTypeID === SiteType.STEAMCOMMUNITY) {
11951229
pageElems.forEach(function (one) {
@@ -1199,23 +1233,48 @@
11991233
toElement.insertAdjacentElement(addTo1, one); // 继续插入网页主体元素
12001234
}
12011235
});
1202-
} else {
1236+
} else if (curSite.SiteTypeID != SiteType.BAIDU_TIEBA) {
12031237
pageElems.forEach(function (one) {toElement.insertAdjacentElement(addTo1, one);});
12041238
}
1239+
12051240
// 对于 <script> 需要用另一种方式插入网页,以便正常运行
1206-
if(curSite.SiteTypeID === SiteType.GOOGLE) {
1241+
if (curSite.SiteTypeID === SiteType.GOOGLE) {
12071242
const scriptElems = getAllElements('//script', newBody, newBody);
12081243
let scriptText = '';
12091244
scriptElems.forEach(function (one) {scriptText += one.innerHTML;});
12101245
toElement.appendChild(document.createElement('script')).innerHTML = scriptText;
12111246
}
12121247

1248+
// 对于百度贴吧这种动态加载内容的网站需要单独处理
1249+
if (curSite.SiteTypeID === SiteType.BAIDU_TIEBA) {
1250+
const scriptElems = getAllElements('//script', newBody, newBody);
1251+
let scriptText = '';
1252+
for (let i = 0; i < scriptElems.length; i++) {
1253+
if (scriptElems[i].textContent.indexOf('Bigpipe.register("frs-list/pagelet/thread_list"') > -1) {
1254+
scriptText = scriptElems[i].textContent.replace('Bigpipe.register("frs-list/pagelet/thread_list", ','');
1255+
break
1256+
}
1257+
}
1258+
if (scriptText) {
1259+
scriptText = scriptText.slice(0, scriptText.indexOf(').')) // 获取主体内容
1260+
let scriptJSON = JSON.parse(scriptText).content; // 字符串转 JSON
1261+
var temp_baidu_tieba = document.createElement('div'); temp_baidu_tieba.innerHTML = scriptJSON; // 字符串转 Element 元素
1262+
pageElems = curSite.function.before(getAllElements(curSite.pager.pageElement, temp_baidu_tieba, temp_baidu_tieba)); // 插入前执行函数
1263+
pageElems.forEach(function (one) {toElement.insertAdjacentElement(addTo1, one);}); // 插入元素
1264+
}
1265+
//toElement.appendChild(document.createElement('script')).innerHTML = scriptText;
1266+
}
1267+
12131268
// 替换待替换元素
12141269
try {
1215-
let oriE = getAllElements(curSite.pager.replaceE);
1216-
let repE = getAllElements(curSite.pager.replaceE, newBody, newBody);
1270+
let oriE = getAllElements(curSite.pager.replaceE), repE;
1271+
if (curSite.SiteTypeID === SiteType.BAIDU_TIEBA) {
1272+
repE = getAllElements(curSite.pager.replaceE, temp_baidu_tieba, temp_baidu_tieba);
1273+
} else {
1274+
repE = getAllElements(curSite.pager.replaceE, newBody, newBody);
1275+
}
12171276
if (oriE.length === repE.length) {
1218-
for (var i = 0; i < oriE.length; i++) {
1277+
for (let i = 0; i < oriE.length; i++) {
12191278
oriE[i].outerHTML = repE[i].outerHTML;
12201279
}
12211280
}

0 commit comments

Comments
 (0)