自动无缝翻页

自动无缝翻页,目前支持:423Down、Apphot、不死鸟、小众软件、异次元软件、AlphaCoders、三国杀论坛、PubMed

当前为 2021-04-02 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name 自动无缝翻页
  3. // @version 1.1.7
  4. // @author X.I.U
  5. // @description 自动无缝翻页,目前支持:423Down、Apphot、不死鸟、小众软件、异次元软件、AlphaCoders、三国杀论坛、PubMed
  6. // @match *://www.423down.com/*
  7. // @exclude *://www.423down.com/*.html
  8. // @match *://apphot.cc/*
  9. // @exclude *://apphot.cc/*.html
  10. // @match *://iao.su/*
  11. // @match *://www.appinn.com/
  12. // @match *://www.appinn.com/*/*/
  13. // @match *://www.appinn.com/?s=*
  14. // @match *://www.iplaysoft.com/*
  15. // @match *://*.alphacoders.com/*
  16. // @match *://club.sanguosha.com/*
  17. // @match *://pubmed.ncbi.nlm.nih.gov/?term=*
  18. // @icon https://i.loli.net/2021/03/07/rdijeYm83pznxWq.png
  19. // @grant GM_xmlhttpRequest
  20. // @grant GM_registerMenuCommand
  21. // @grant GM_openInTab
  22. // @license GPL-3.0 License
  23. // @run-at document-end
  24. // @namespace https://github.com/XIU2/UserScript
  25. // ==/UserScript==
  26.  
  27. (function() {
  28. // 注册(不可用)脚本菜单
  29. GM_registerMenuCommand('反馈 & 欢迎申请支持', function () {window.GM_openInTab('https://github.com/XIU2/UserScript#xiu2userscript', {active: true,insert: true,setParent: true});window.GM_openInTab('https://gf.qytechs.cn/zh-CN/scripts/419215/feedback', {active: true,insert: true,setParent: true});});
  30.  
  31. // 默认 ID 为 0
  32. var curSite = {SiteTypeID: 0};
  33.  
  34. // 自动翻页规则
  35. // type:1 = 脚本实现自动无缝翻页,2 = 网站自带了自动无缝翻页功能,只需要点击下一页按钮即可,这时 nextText 为按钮文本,避免一瞬间加载太多次下一页
  36. // HT_insert:1 = 插入该元素本身的前面;2 = 插入该元素当中,第一个子元素前面;3 = 插入该元素当中,最后一个子元素后面;4 = 插入该元素本身的后面;
  37. // scrollDelta:数值越大,滚动条触发点越靠上(越早开始翻页),一般是访问网页速度越慢,该值就需要越大
  38. // function:before = 插入前执行函数;after = 插入后执行函数;parameter = 参数
  39. let DBSite = {
  40. _423down_postslist: {
  41. SiteTypeID: 1,
  42. pager: {
  43. type: 1,
  44. nextLink: '//div[@class="paging"]//a[contains(text(),"下一页")][@href]',
  45. pageElement: 'css;div.content-wrap ul.excerpt > li',
  46. HT_insert: ['css;div.content-wrap ul.excerpt', 3],
  47. replaceE: 'css;div.paging',
  48. scrollDelta: 1500
  49. }
  50. },
  51. apphot_postslist: {
  52. SiteTypeID: 2,
  53. pager: {
  54. type: 1,
  55. nextLink: '//div[@class="pagination"]//a[contains(text(),"下一页")][@href]',
  56. pageElement: 'css;div.content > article.excerpt',
  57. HT_insert: ['css;div.pagination', 1],
  58. replaceE: 'css;div.pagination',
  59. scrollDelta: 1500
  60. }
  61. },
  62. iao_su_postslist: {
  63. SiteTypeID: 3,
  64. pager: {
  65. type: 1,
  66. nextLink: '//li[@class="btn btn-primary next"]//a[@href]',
  67. pageElement: 'css;#index > article, #archive > article',
  68. HT_insert: ['css;ol.page-navigator', 1],
  69. replaceE: 'css;ol.page-navigator',
  70. scrollDelta: 800
  71. },
  72. function: {
  73. before: iao_su_postslist_beforeFunction
  74. }
  75. },
  76. appinn_postslist: {
  77. SiteTypeID: 4,
  78. pager: {
  79. type: 1,
  80. nextLink: '//a[@class="next page-numbers"][@href]',
  81. pageElement: 'css;section#latest-posts > article',
  82. HT_insert: ['css;nav.navigation.pagination', 1],
  83. replaceE: 'css;div.nav-links',
  84. scrollDelta: 1500
  85. }
  86. },
  87. iplaysoft_postslist: {
  88. SiteTypeID: 5,
  89. pager: {
  90. type: 1,
  91. nextLink: '//div[@class="pagenavi"]//a[@title="下一页"][@href]',
  92. pageElement: 'css;#postlist > div.entry',
  93. HT_insert: ['css;#postlist > .pagenavi-button', 1],
  94. replaceE: 'css;.pagenavi-button, .pagenavi',
  95. scrollDelta: 1200
  96. },
  97. function: {
  98. before: iplaysoft_postslist_beforeFunction
  99. }
  100. },
  101. iplaysoft_postcomments: {
  102. SiteTypeID: 6,
  103. pager: {
  104. type: 2,
  105. nextLink: '#loadHistoryComments',
  106. nextText: '展开后面',
  107. scrollDelta: 1200
  108. }
  109. },
  110. sanguosha_forum: {
  111. SiteTypeID: 7,
  112. pager: {
  113. type: 2,
  114. nextLink: '#autopbn',
  115. nextText: '下一页 »',
  116. scrollDelta: 800
  117. }
  118. },
  119. sanguosha_thread: {
  120. SiteTypeID: 8,
  121. pager: {
  122. type: 1,
  123. nextLink: '//a[@class="nxt"][@href]',
  124. pageElement: 'css;div#postlist > div[id^="post_"]',
  125. HT_insert: ['css;div#postlist', 3],
  126. replaceE: 'css;div.pg',
  127. scrollDelta: 800
  128. }
  129. },
  130. sanguosha_search: {
  131. SiteTypeID: 9,
  132. pager: {
  133. type: 1,
  134. nextLink: '//a[@class="nxt"][@href]',
  135. pageElement: 'css;div#threadlist > ul',
  136. HT_insert: ['css;div#threadlist', 3],
  137. replaceE: 'css;div.pg',
  138. scrollDelta: 800
  139. }
  140. },
  141. pubmed_postslist: {
  142. SiteTypeID: 10,
  143. pager: {
  144. type: 2,
  145. nextLink: 'button.load-button.next-page',
  146. nextText: 'Show more',
  147. scrollDelta: 1500
  148. }
  149. },
  150. wall_alphacoders: {
  151. SiteTypeID: 11,
  152. pager: {
  153. type: 1,
  154. nextLink: '//a[@id="next_page"][@href]',
  155. pageElement: 'css;.thumb-container-big, .avatar-thumb, .thumb-element',
  156. HT_insert: ['css;.thumb-container-big:nth-last-child(1), .avatar-thumb:nth-last-child(1), .thumb-element:nth-last-child(1)', 4],
  157. replaceE: '//div[@class="hidden-xs hidden-sm"]/..',
  158. scrollDelta: 1000
  159. }
  160. }
  161. };
  162.  
  163.  
  164. switch (location.host) {
  165. case "www.423down.com":
  166. curSite = DBSite._423down_postslist;
  167. break;
  168. case "apphot.cc":
  169. curSite = DBSite.apphot_postslist;
  170. break;
  171. case "iao.su":
  172. curSite = DBSite.iao_su_postslist;
  173. break;
  174. case "www.appinn.com":
  175. curSite = DBSite.appinn_postslist;
  176. break;
  177. case "www.iplaysoft.com":
  178. if(location.pathname.indexOf(".html") > -1 || location.pathname.indexOf("/p/") > -1){ // 文章内
  179. curSite = DBSite.iplaysoft_postcomments;
  180. }else{ // 其他页面
  181. curSite = DBSite.iplaysoft_postslist;
  182. }
  183. break;
  184. case "wall.alphacoders.com":
  185. case "avatars.alphacoders.com":
  186. case "mobile.alphacoders.com":
  187. curSite = DBSite.wall_alphacoders;
  188. break;
  189. case "club.sanguosha.com":
  190. if(location.pathname.indexOf("forum") > -1){ // 各版块帖子列表
  191. curSite = DBSite.sanguosha_forum;
  192. }else if(location.pathname.indexOf("thread") > -1){ // 帖子内
  193. curSite = DBSite.sanguosha_thread;
  194. hidePgbtn(); // 隐藏帖子内的 [下一页] 按钮
  195. }else if(location.pathname.indexOf("search") > -1){ // 搜索结果
  196. curSite = DBSite.sanguosha_search;
  197. }
  198. break;
  199. case "pubmed.ncbi.nlm.nih.gov":
  200. curSite = DBSite.pubmed_postslist;
  201. break;
  202. }
  203. curSite.pageUrl = ""; // 下一页URL
  204. pageLoading(); // 自动无缝翻页
  205.  
  206.  
  207. // 自动无缝翻页
  208. function pageLoading() {
  209. if (curSite.SiteTypeID > 0){
  210. windowScroll(function (direction, e) {
  211. if (direction === "down") { // 下滑才准备翻页
  212. let scrollTop = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop;
  213. let scrollDelta = curSite.pager.scrollDelta;
  214. if (document.documentElement.scrollHeight <= document.documentElement.clientHeight + scrollTop + scrollDelta) {
  215. if (curSite.pager.type === 1) {
  216. ShowPager.loadMorePage();
  217. }else{
  218. let autopbn = document.querySelector(curSite.pager.nextLink);
  219. if (autopbn){ // 如果正在加载,就不再点击
  220. if (!curSite.pager.nextText){ // 如果没有指定 nextText 就直接点击
  221. autopbn.click();
  222. }else if (autopbn.innerText.indexOf(curSite.pager.nextText) > -1){ // 如果指定了 nextText 就需要判断后再点击(避免已经在加载了,还重复点击)
  223. autopbn.click();
  224. }
  225. }
  226. }
  227. }
  228. }
  229. });
  230. }
  231. }
  232.  
  233.  
  234. // 隐藏帖子内的 [下一页] 按钮
  235. function hidePgbtn(){
  236. let style_hidePgbtn = document.createElement('style');
  237. style_hidePgbtn.innerHTML = `.pgbtn {display: none;}`;
  238. document.head.appendChild(style_hidePgbtn);
  239. }
  240.  
  241.  
  242. // iplaysoft 的插入前函数
  243. function iplaysoft_postslist_beforeFunction(pageElems) {
  244. pageElems.forEach(function (one) {
  245. let now = one.querySelector("img.lazyload")
  246. if (now && !now.getAttribute('src')) {
  247. now.setAttribute("src",now.getAttribute('data-src'))
  248. now.setAttribute("srcset",now.getAttribute('data-src'))
  249. now.setAttribute("class","lazyloaded")
  250. }
  251. });
  252. return pageElems
  253. }
  254.  
  255.  
  256. // iao.su 的插入前函数
  257. function iao_su_postslist_beforeFunction(pageElems) {
  258. pageElems.forEach(function (one) {
  259. let now = one.getElementsByClassName("post-card")[0]
  260. if (now) {
  261. now.getElementsByClassName("blog-background")[0].style.backgroundImage = 'url("' + RegExp("(?<=loadBannerDirect\\(').*(?=', '',)").exec(now.getElementsByTagName("script")[0].innerText)[0]; + '")';
  262. }
  263. });
  264. return pageElems
  265. }
  266.  
  267.  
  268. // 滚动条事件
  269. function windowScroll(fn1) {
  270. var beforeScrollTop = document.documentElement.scrollTop,
  271. fn = fn1 || function () {};
  272. setTimeout(function () { // 延时执行,避免刚载入到页面就触发翻页事件
  273. window.addEventListener("scroll", function (e) {
  274. var afterScrollTop = document.documentElement.scrollTop,
  275. delta = afterScrollTop - beforeScrollTop;
  276. if (delta == 0) return false;
  277. fn(delta > 0 ? "down" : "up", e);
  278. beforeScrollTop = afterScrollTop;
  279. }, false);
  280. }, 1000)
  281. }
  282.  
  283.  
  284. var ShowPager = { // 修改自 https://gf.qytechs.cn/scripts/14178
  285. getFullHref: function (e) {
  286. if(e == null) return '';
  287. "string" != typeof e && (e = e.getAttribute("href"));
  288. var t = this.getFullHref.a;
  289. return t || (this.getFullHref.a = t = document.createElement("a")), t.href = e, t.href;
  290. },
  291. createDocumentByString: function (e) {
  292. if (e) {
  293. if ("HTML" !== document.documentElement.nodeName) return (new DOMParser).parseFromString(e, "application/xhtml+xml");
  294. var t;
  295. try {
  296. t = (new DOMParser).parseFromString(e, "text/html");
  297. } catch (e) {
  298. }
  299. if (t) return t;
  300. if (document.implementation.createHTMLDocument) t = document.implementation.createHTMLDocument("ADocument"); else try {
  301. (t = document.cloneNode(!1)).appendChild(t.importNode(document.documentElement, !1)),
  302. t.documentElement.appendChild(t.createElement("head")), t.documentElement.appendChild(t.createElement("body"));
  303. } catch (e) {
  304. }
  305. if (t) {
  306. var r = document.createRange();
  307. r.selectNodeContents(document.body);
  308. var n = r.createContextualFragment(e);
  309. t.body.appendChild(n);
  310. for (var a, o = {
  311. TITLE: !0,
  312. META: !0,
  313. LINK: !0,
  314. STYLE: !0,
  315. BASE: !0
  316. }, i = t.body, s = i.childNodes, c = s.length - 1; c >= 0; c--) o[(a = s[c]).nodeName] && i.removeChild(a);
  317. return t;
  318. }
  319. } else console.error("没有找到要转成DOM的字符串");
  320. },
  321. loadMorePage: function () {
  322. if (curSite.pager) {
  323. let curPageEle = getElementByXpath(curSite.pager.nextLink);
  324. var url = this.getFullHref(curPageEle);
  325. //console.log(`${url} ${curPageEle} ${curSite.pageUrl}`);
  326. if(url === '') return;
  327. if(curSite.pageUrl === url) return;// 避免重复加载相同的页面
  328. curSite.pageUrl = url;
  329. // 读取下一页的数据
  330. curSite.pager.startFilter && curSite.pager.startFilter();
  331. GM_xmlhttpRequest({
  332. url: url,
  333. method: "GET",
  334. timeout: 5000,
  335. onload: function (response) {
  336. try {
  337. //console.log(`${response.responseText}`)
  338. var newBody = ShowPager.createDocumentByString(response.responseText);
  339. let pageElems = getAllElements(curSite.pager.pageElement, newBody, newBody);
  340. let toElement = getAllElements(curSite.pager.HT_insert[0])[0];
  341. if (pageElems.length >= 0) {
  342. // 如果有插入前函数就执行函数
  343. if (curSite.function && curSite.function.before) {
  344. if (curSite.function.parameter) { // 如果指定了参数
  345. pageElems = curSite.function.before(curSite.function.parameter);
  346. }else{
  347. pageElems = curSite.function.before(pageElems);
  348. }
  349. }
  350. // 插入位置
  351. let addTo;
  352. switch (curSite.pager.HT_insert[1]) {
  353. case 1:
  354. addTo = "beforebegin"
  355. break;
  356. case 2:
  357. addTo = "afterbegin"
  358. break;
  359. case 3:
  360. addTo = "beforeend"
  361. break;
  362. case 4:
  363. addTo = "afterend"
  364. break;
  365. }
  366. // 插入新页面元素
  367. pageElems.forEach(function (one) {
  368. toElement.insertAdjacentElement(addTo, one);
  369. });
  370. // 替换待替换元素
  371. try {
  372. let oriE = getAllElements(curSite.pager.replaceE);
  373. let repE = getAllElements(curSite.pager.replaceE, newBody, newBody);
  374. if (oriE.length === repE.length) {
  375. for (var i = 0; i < oriE.length; i++) {
  376. oriE[i].outerHTML = repE[i].outerHTML;
  377. }
  378. }
  379. } catch (e) {
  380. console.log(e);
  381. }
  382. // 如果有插入后函数就执行函数
  383. if (curSite.function && curSite.function.after) {
  384. if (curSite.function.parameter) { // 如果指定了参数
  385. curSite.function.after(curSite.function.parameter);
  386. }else{
  387. curSite.function.after();
  388. }
  389. }
  390. }
  391. } catch (e) {
  392. console.log(e);
  393. }
  394. }
  395. });
  396. }
  397. },
  398. };
  399.  
  400.  
  401. function getElementByXpath(e, t, r) {
  402. r = r || document, t = t || r;
  403. try {
  404. return r.evaluate(e, t, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
  405. } catch (t) {
  406. return void console.error("无效的xpath");
  407. }
  408. }
  409.  
  410.  
  411. function getAllElements(e, t, r, n, o) {
  412. let getAllElementsByXpath = function(e, t, r) {
  413. return r = r || document, t = t || r, r.evaluate(e, t, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
  414. }
  415.  
  416. var i, s = [];
  417. if (!e) return s;
  418. if (r = r || document, n = n || window, o = o || void 0, t = t || r, "string" == typeof e) i = 0 === e.search(/^css;/i) ? function getAllElementsByCSS(e, t) {
  419. return (t || document).querySelectorAll(e);
  420. }(e.slice(4), t) : getAllElementsByXpath(e, t, r); else {
  421. if (!(i = e(r, n, o))) return s;
  422. if (i.nodeType) return s[0] = i, s;
  423. }
  424. return function makeArray(e) {
  425. var t, r, n, o = [];
  426. if (e.pop) {
  427. for (t = 0, r = e.length; t < r; t++) (n = e[t]) && (n.nodeType ? o.push(n) : o = o.concat(makeArray(n)));
  428. return a()(o);
  429. }
  430. if (e.item) {
  431. for (t = e.length; t;) o[--t] = e[t];
  432. return o;
  433. }
  434. if (e.iterateNext) {
  435. for (t = e.snapshotLength; t;) o[--t] = e.snapshotItem(t);
  436. return o;
  437. }
  438. }(i);
  439. }
  440. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址