自动无缝翻页

无缝拼接下一页内容,目前支持:[所有使用「Discuz!、Flarum、DUX(WordPress)」的网站]、百度、谷歌、必应、贴吧、豆瓣、微博、千图网、Pixabay、3DM、游侠网、游民星空、Steam 创意工坊、423Down、Sordum、不死鸟、小众软件、六音软件、微当下载、异次元软件、老殁殁漂遥、异星软件空间、漫画DB、HiComic(嗨漫画)、古风漫画网、砂之船动漫家、RARBG、PubMed、AfreecaTV、GreasyFork、AlphaCoders、CS.RIN.RU、Crackhub213、FitGirl Repacks...

当前为 2021-08-21 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name 自动无缝翻页
  3. // @version 1.6.7
  4. // @author X.I.U
  5. // @description 无缝拼接下一页内容,目前支持:[所有使用「Discuz!、Flarum、DUX(WordPress)」的网站]、百度、谷歌、必应、贴吧、豆瓣、微博、千图网、Pixabay、3DM、游侠网、游民星空、Steam 创意工坊、423Down、Sordum、不死鸟、小众软件、六音软件、微当下载、异次元软件、老殁殁漂遥、异星软件空间、漫画DB、HiComic(嗨漫画)、古风漫画网、砂之船动漫家、RARBG、PubMed、AfreecaTV、GreasyFork、AlphaCoders、CS.RIN.RU、Crackhub213、FitGirl Repacks...
  6. // @match *://*/*
  7. // @connect www.gamersky.com
  8. // @icon https://i.loli.net/2021/03/07/rdijeYm83pznxWq.png
  9. // @grant GM_xmlhttpRequest
  10. // @grant GM_registerMenuCommand
  11. // @grant GM_openInTab
  12. // @grant GM_getValue
  13. // @grant GM_setValue
  14. // @grant GM_notification
  15. // @noframes
  16. // @license GPL-3.0 License
  17. // @run-at document-end
  18. // @namespace https://github.com/XIU2/UserScript
  19. // @supportURL https://github.com/XIU2/UserScript
  20. // @homepageURL https://github.com/XIU2/UserScript
  21. // ==/UserScript==
  22.  
  23. (function() {
  24. 'use strict';
  25. var webType, curSite = {SiteTypeID: 0}, pausePage = true;
  26. // 目前支持的网站(仅单独规则的,不包含通用规则的网站)
  27. const websiteList = ['www.baidu.com', 'www.google.com', 'www.bing.com', 'cn.bing.com', 'tieba.baidu.com', 'movie.douban.com', 'weibo.com', 'www.58pic.com', 'pixabay.com',
  28. 'www.3dmgame.com', 'www.ali213.net', 'gl.ali213.net', 'www.gamersky.com', 'steamcommunity.com',
  29. 'www.423down.com', 'www.sordum.org', 'iao.su', 'www.appinn.com', 'www.sixyin.com', 'www.weidown.com', 'www.iplaysoft.com', 'www.mpyit.com', 'www.yxssp.com',
  30. 'www.manhuadb.com', 'www.hicomic.net', 'www.gufengmh8.com', 'www.szcdmj.com',
  31. 'rarbgprx.org', 'pubmed.ncbi.nlm.nih.gov', 'www.afreecatv.com', 'greasyfork.org',
  32. 'art.alphacoders.com', 'wall.alphacoders.com', 'avatars.alphacoders.com', 'mobile.alphacoders.com',
  33. 'cs.rin.ru', 'crackhub.site', 'fitgirl-repacks.site'];
  34.  
  35. if (GM_getValue('menu_disable') == null){GM_setValue('menu_disable', [])};
  36. if (GM_getValue('menu_discuz_thread_page') == null){GM_setValue('menu_discuz_thread_page', true)};
  37. if (GM_getValue('menu_pause_page') == null){GM_setValue('menu_pause_page', true)};
  38. // 注册脚本菜单
  39. if (menu_disable('check')) { // 当前网站是否已存在禁用列表中
  40. GM_registerMenuCommand('❌ 已禁用 (点击对当前网站启用)', function(){menu_disable('del')});
  41. return
  42. } else {
  43. if (websiteList.indexOf(location.host) > -1) {
  44. webType = 1; console.info('[自动无缝翻页] - 其他网站(独立规则)'); // 其他网站(独立规则)
  45. } else if (document.querySelector('meta[name="author"][content*="Discuz!"], meta[name="generator"][content*="Discuz!"]') || document.getElementById('ft') && document.getElementById('ft').textContent.indexOf('Discuz!') > -1) {
  46. webType = 2; console.info('[自动无缝翻页] - Discuz! 论坛'); // 所有 Discuz! 论坛
  47. } else if (document.getElementById('flarum-loading')) {
  48. webType = 3; console.info('[自动无缝翻页] - Flarum 论坛'); // 所有 Flarum 论坛
  49. } else if (document.querySelector('link[href*="themes/dux" i], script[src*="themes/dux" i]')) {
  50. webType = 4; console.info('[自动无缝翻页] - 使用 WordPress DUX 主题的网站'); // 所有使用 WordPress DUX 主题的网站
  51. } else {
  52. GM_registerMenuCommand('❌ 当前网站暂不支持 [点击申请支持]', function () {window.GM_openInTab('https://github.com/XIU2/UserScript#xiu2userscript', {active: true,insert: true,setParent: true});window.GM_openInTab('https://greasyfork.org/zh-CN/scripts/419215/feedback', {active: true,insert: true,setParent: true});});
  53. console.info('[自动无缝翻页] - 不支持当前网站,欢迎申请支持:https://github.com/XIU2/UserScript / https://greasyfork.org/zh-CN/scripts/419215/feedback');
  54. return
  55. }
  56. GM_registerMenuCommand('✅ 已启用 (点击对当前网站禁用)', function(){menu_disable('add')});
  57. if (webType === 2) {
  58. GM_registerMenuCommand(`${GM_getValue('menu_discuz_thread_page')?'✅':'❌'} 帖子内自动翻页 (仅论坛)`, function(){menu_switch(GM_getValue('menu_discuz_thread_page'), 'menu_discuz_thread_page', 'Discuz! 论坛帖子内翻页')});
  59. }
  60. GM_registerMenuCommand(`${GM_getValue('menu_pause_page')?'✅':'❌'} 左键双击网页空白处暂停翻页`, function(){menu_switch(GM_getValue('menu_pause_page'), 'menu_pause_page', '左键双击网页空白处暂停翻页')});
  61. }
  62. GM_registerMenuCommand('💬 反馈 & 欢迎申请支持', function () {window.GM_openInTab('https://github.com/XIU2/UserScript#xiu2userscript', {active: true,insert: true,setParent: true});window.GM_openInTab('https://greasyfork.org/zh-CN/scripts/419215/feedback', {active: true,insert: true,setParent: true});});
  63.  
  64.  
  65. /*
  66. 自动翻页规则
  67. type:
  68. 1 = 由脚本实现自动无缝翻页
  69. 2 = 网站自带了自动无缝翻页功能,只需要点击下一页按钮即可
  70. nextText: 按钮文本,当按钮文本 = 该文本时,才会点击按钮加载下一页(避免一瞬间加载太多次下一页)
  71. nextTextOf: 按钮文本的一部分,当按钮文本包含该文本时,才会点击按钮加载下一页(避免一瞬间加载太多次下一页)
  72. nextHTML: 按钮内元素,当按钮内元素 = 该元素内容时,才会点击按钮加载下一页(避免一瞬间加载太多次下一页)
  73. intervals: 点击间隔时间,对于没有按钮文字变化的按钮,可以手动指定间隔时间,单位:ms
  74. 3 = 依靠元素距离可视区域底部的距离来触发翻页
  75. 4 = 部分简单的动态加载类网站(暂时)
  76. HT_insert:
  77. 1 = 插入该元素本身的前面;
  78. 2 = 插入该元素当中,第一个子元素前面;
  79. 3 = 插入该元素当中,最后一个子元素后面;
  80. 4 = 插入该元素本身的后面;
  81. scrollDelta:数值越大,滚动条触发点越靠上(越早开始翻页),一般是访问网页速度越慢,该值就需要越大(如果 Type = 3,则相反)
  82. function:
  83. before = 插入前执行函数;
  84. after = 插入后执行函数;
  85. parameter = 参数
  86. */
  87. let DBSite = {
  88. discuz_forum: {
  89. SiteTypeID: 0,
  90. pager: {
  91. type: 2,
  92. nextLink: '#autopbn',
  93. nextText: '下一页 »',
  94. scrollDelta: 1000
  95. }
  96. },
  97. discuz_thread: {
  98. SiteTypeID: 0,
  99. pager: {
  100. type: 1,
  101. nextLink: '//a[@class="nxt"][@href]',
  102. pageElement: 'css;div#postlist > div[id^="post_"]',
  103. HT_insert: ['css;div#postlist', 3],
  104. replaceE: 'css;div.pg',
  105. scrollDelta: 1000
  106. }
  107. },
  108. discuz_search: {
  109. SiteTypeID: 0,
  110. pager: {
  111. type: 1,
  112. nextLink: '//a[@class="nxt"][@href]',
  113. pageElement: 'css;div#threadlist > ul',
  114. HT_insert: ['css;div#threadlist', 3],
  115. replaceE: 'css;div.pg',
  116. scrollDelta: 1000
  117. }
  118. },
  119. discuz_guide: {
  120. SiteTypeID: 0,
  121. pager: {
  122. type: 1,
  123. nextLink: '//a[@class="nxt"][@href]',
  124. pageElement: 'css;div#threadlist div.bm_c table > tbody',
  125. HT_insert: ['css;div#threadlist div.bm_c table', 3],
  126. replaceE: 'css;div.pg',
  127. scrollDelta: 1000
  128. }
  129. },
  130. discuz_youspace: {
  131. SiteTypeID: 0,
  132. pager: {
  133. type: 1,
  134. nextLink: '//a[@class="nxt"][@href]',
  135. pageElement: 'css;tbody > tr:not(.th)',
  136. HT_insert: ['css;tbody', 3],
  137. replaceE: 'css;div.pg',
  138. scrollDelta: 1000
  139. }
  140. },
  141. discuz_collection: {
  142. SiteTypeID: 0,
  143. pager: {
  144. type: 1,
  145. nextLink: '//a[@class="nxt"][@href]',
  146. pageElement: 'css;div#ct div.bm_c table > tbody',
  147. HT_insert: ['css;div#ct div.bm_c table', 3],
  148. replaceE: 'css;div.pg',
  149. scrollDelta: 1000
  150. }
  151. },
  152. flarum: {
  153. SiteTypeID: 0,
  154. pager: {
  155. type: 2,
  156. nextLink: '.DiscussionList-loadMore > button[title]',
  157. scrollDelta: 1000
  158. }
  159. },
  160. dux: {
  161. SiteTypeID: 0,
  162. pager: {
  163. type: 1,
  164. nextLink: '//li[@class="next-page"]/a[@href]',
  165. pageElement: 'css;.content > article',
  166. HT_insert: ['css;.content > .pagination', 1],
  167. replaceE: 'css;.content > .pagination',
  168. scrollDelta: 1500
  169. },
  170. function: {
  171. before: dux_beforeFunction
  172. }
  173. },
  174. baidu: {
  175. SiteTypeID: 0,
  176. pager: {
  177. type: 1,
  178. nextLink: '//div[@id="page"]//a[contains(text(),"下一页")][@href]',
  179. pageElement: 'css;#content_left > *',
  180. HT_insert: ['css;#content_left', 3],
  181. replaceE: 'css;#page',
  182. scrollDelta: 1200
  183. }
  184. },
  185. google: {
  186. SiteTypeID: 0,
  187. pager: {
  188. type: 1,
  189. nextLink: '//a[@id="pnnext"][@href]',
  190. pageElement: 'css;#res > *',
  191. HT_insert: ['css;#res', 3],
  192. replaceE: '//div[@id="navcnt"] | //div[@id="rcnt"]//div[@role="navigation"]',
  193. scrollDelta: 1500
  194. }
  195. },
  196. bing: {
  197. SiteTypeID: 0,
  198. pager: {
  199. type: 1,
  200. nextLink: '//a[contains(@class,"sb_pagN")][@href]',
  201. pageElement: 'css;#b_results > li:not(.b_msg):not(.b_pag):not(#mfa_root)',
  202. HT_insert: ['css;#b_results > .b_pag', 1],
  203. replaceE: 'css;#b_results > .b_pag',
  204. scrollDelta: 1500
  205. }
  206. },
  207. baidu_tieba: {
  208. SiteTypeID: 0,
  209. pager: {
  210. type: 1,
  211. nextLink: '//a[@class="next pagination-item "][@href]',
  212. pageElement: 'css;#thread_list > li',
  213. HT_insert: ['css;#thread_list', 3],
  214. replaceE: 'css;#frs_list_pager',
  215. scrollDelta: 1500
  216. },
  217. function: {
  218. before: baidu_tieba_beforeFunction
  219. }
  220. },
  221. baidu_tieba_post: {
  222. SiteTypeID: 0,
  223. pager: {
  224. type: 1,
  225. nextLink: '//li[contains(@class,"pb_list_pager")]/a[contains(text(),"下一页")][@href]',
  226. pageElement: 'css;#j_p_postlist > div',
  227. HT_insert: ['css;#j_p_postlist', 3],
  228. replaceE: 'css;li.pb_list_pager',
  229. scrollDelta: 1000
  230. }
  231. },
  232. baidu_tieba_search: {
  233. SiteTypeID: 0,
  234. pager: {
  235. type: 1,
  236. nextLink: '//a[@class="next"][@href]',
  237. pageElement: 'css;.s_post_list > .s_post',
  238. HT_insert: ['css;.s_post_list', 3],
  239. replaceE: 'css;.pager.pager-search',
  240. scrollDelta: 1000
  241. }
  242. },
  243. douban_subject_comments: {
  244. SiteTypeID: 0,
  245. pager: {
  246. type: 1,
  247. nextLink: '//a[@class="next"][@href]',
  248. pageElement: 'css;#comments > .comment-item',
  249. HT_insert: ['css;#paginator', 1],
  250. replaceE: 'css;#paginator',
  251. scrollDelta: 1000
  252. }
  253. },
  254. douban_subject_reviews: {
  255. SiteTypeID: 0,
  256. pager: {
  257. type: 1,
  258. nextLink: '//link[@rel="next"][@href]',
  259. pageElement: 'css;.review-list > div',
  260. HT_insert: ['css;.review-list', 3],
  261. replaceE: 'css;.paginator',
  262. scrollDelta: 1000
  263. }
  264. },
  265. douban_subject_episode: {
  266. SiteTypeID: 0,
  267. pager: {
  268. type: 1,
  269. nextLink: '//link[@rel="next"][@href]',
  270. pageElement: 'css;#comments > div',
  271. HT_insert: ['css;#comments', 3],
  272. replaceE: 'css;.paginator',
  273. scrollDelta: 1000
  274. }
  275. },
  276. weibo_comment: {
  277. SiteTypeID: 0,
  278. pager: {
  279. type: 2,
  280. nextLink: 'a[action-type="click_more_comment"]',
  281. nextText: '查看更多c',
  282. scrollDelta: 1000
  283. }
  284. },
  285. _58pic: {
  286. SiteTypeID: 0,
  287. pager: {
  288. type: 1,
  289. nextLink: '//div[contains(@class,"page-box")]//a[text()="下一页"][@href]',
  290. pageElement: 'css;.pic-box > .qtw-card',
  291. HT_insert: ['css;.pic-box', 3],
  292. replaceE: 'css;.page-box',
  293. scrollDelta: 2000
  294. },
  295. function: {
  296. before: _58pic_beforeFunction
  297. }
  298. },
  299. _58pic_c: {
  300. SiteTypeID: 0,
  301. pager: {
  302. type: 1,
  303. nextLink: '//div[contains(@class,"page-box")]//a[text()="下一页"][@href]',
  304. pageElement: 'css;.list-box > .qtw-card',
  305. HT_insert: ['css;.list-box', 3],
  306. replaceE: 'css;.page-box',
  307. scrollDelta: 4000
  308. },
  309. function: {
  310. before: _58pic_beforeFunction
  311. }
  312. },
  313. pixabay: {
  314. SiteTypeID: 0,
  315. pager: {
  316. type: 1,
  317. nextLink: '//a[text()="Next page"][@href]',
  318. pageElement: 'css;[class^="results"] > [class^="container"] > div',
  319. HT_insert: ['css;[class^="results"] > [class^="container"]', 3],
  320. replaceE: '//a[text()="Next page"][@href]',
  321. scrollDelta: 2000
  322. },
  323. function: {
  324. before: pixabay_beforeFunction
  325. }
  326. },
  327. _3dmgame: {
  328. SiteTypeID: 0,
  329. pager: {
  330. type: 3,
  331. nextLink: '//li[@class="next"]/a[@href]',
  332. pageElement: 'css;.news_warp_center > *',
  333. HT_insert: ['css;.news_warp_center', 3],
  334. replaceE: 'css;.pagewrap',
  335. scrollElement: '.pagewrap',
  336. scrollDelta: 400
  337. }
  338. },
  339. ali213_www: {
  340. SiteTypeID: 0,
  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: 0,
  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. gamersky_ent: {
  364. SiteTypeID: 0,
  365. pager: {
  366. type: 3,
  367. nextLink: '//div[@class="page_css"]/a[text()="下一页"][@href]',
  368. pageElement: 'css;.Mid2L_con > *:not(.gs_nc_editor):not(.pagecss):not(.page_css):not(.gs_ccs_solve):not(.post_ding)',
  369. HT_insert: ['css;.page_css', 1],
  370. replaceE: 'css;.page_css',
  371. scrollElement: '.page_css',
  372. scrollDelta: 100
  373. }
  374. },
  375. gamersky_gl: {
  376. SiteTypeID: 0,
  377. pager: {
  378. type: 3,
  379. nextLink: '//div[@class="page_css"]/a[text()="下一页"][@href]',
  380. pageElement: 'css;.Mid2L_con > *:not(.gs_nc_editor):not(.pagecss):not(.gs_ccs_solve):not(.post_ding)',
  381. HT_insert: ['css;.gs_nc_editor', 1],
  382. replaceE: 'css;.page_css',
  383. scrollElement: '.pagecss',
  384. scrollDelta: -1000
  385. },
  386. function: {
  387. before: gamersky_gl_beforeFunction
  388. }
  389. },
  390. steamcommunity: {
  391. SiteTypeID: 0,
  392. pager: {
  393. type: 1,
  394. nextLink: '//a[@class="pagebtn"][last()][@href]',
  395. pageElement: 'css;.workshopBrowseItems > *',
  396. HT_insert: ['css;.workshopBrowseItems', 3],
  397. replaceE: 'css;.workshopBrowsePaging',
  398. scrollDelta: 1500
  399. }
  400. },
  401. _423down: {
  402. SiteTypeID: 0,
  403. pager: {
  404. type: 1,
  405. nextLink: '//div[@class="paging"]//a[contains(text(),"下一页")][@href]',
  406. pageElement: 'css;div.content-wrap ul.excerpt > li',
  407. HT_insert: ['css;div.content-wrap ul.excerpt', 3],
  408. replaceE: 'css;div.paging',
  409. scrollDelta: 1500
  410. }
  411. },
  412. sordum: {
  413. SiteTypeID: 0,
  414. pager: {
  415. type: 1,
  416. nextLink: '//a[@class="next page-numbers"][@href]',
  417. pageElement: 'css;.article > article',
  418. HT_insert: ['css;nav.navigation.posts-navigation', 1],
  419. replaceE: 'css;nav.navigation.posts-navigation',
  420. scrollDelta: 1500
  421. }
  422. },
  423. iao_su: {
  424. SiteTypeID: 0,
  425. pager: {
  426. type: 1,
  427. nextLink: '//li[@class="btn btn-primary next"]//a[@href]',
  428. pageElement: 'css;#index > article, #archive > article',
  429. HT_insert: ['css;ol.page-navigator', 1],
  430. replaceE: 'css;ol.page-navigator',
  431. scrollDelta: 800
  432. },
  433. function: {
  434. before: iao_su_beforeFunction
  435. }
  436. },
  437. appinn: {
  438. SiteTypeID: 0,
  439. pager: {
  440. type: 1,
  441. nextLink: '//a[@class="next page-numbers"][@href]',
  442. pageElement: 'css;section#latest-posts > article',
  443. HT_insert: ['css;nav.navigation.pagination', 1],
  444. replaceE: 'css;div.nav-links',
  445. scrollDelta: 1500
  446. }
  447. },
  448. sixyin: {
  449. SiteTypeID: 0,
  450. pager: {
  451. type: 2,
  452. nextLink: '.load-more',
  453. nextHTML: '点击查看更多',
  454. scrollDelta: 1500
  455. }
  456. },
  457. sixyin_postlist: {
  458. SiteTypeID: 0,
  459. pager: {
  460. type: 1,
  461. nextLink: '//a[@class="next"][@href]',
  462. pageElement: 'css;ul.post-loop > li',
  463. HT_insert: ['css;ul.post-loop', 3],
  464. replaceE: 'css;ul.pagination',
  465. scrollDelta: 1500
  466. }
  467. },
  468. weidown: {
  469. SiteTypeID: 0,
  470. pager: {
  471. type: 1,
  472. nextLink: '//a[@class="nextpage"][@href]',
  473. pageElement: 'css;.articleWrapper > .itemArticle, .articleWrapper > .richTextItem.search',
  474. HT_insert: ['css;.articleWrapper', 3],
  475. replaceE: 'css;#pageGroup',
  476. scrollDelta: 1500
  477. }
  478. },
  479. weidown_search: {
  480. SiteTypeID: 0,
  481. pager: {
  482. type: 1,
  483. nextLink: '//a[@class="nextpage"][@href]',
  484. pageElement: 'css;.articleListWrapper > .richTextItem.search',
  485. HT_insert: ['css;#pageGroup', 1],
  486. replaceE: 'css;#pageGroup',
  487. scrollDelta: 700
  488. }
  489. },
  490. weidown_special: {
  491. SiteTypeID: 0,
  492. pager: {
  493. type: 1,
  494. nextLink: '//a[@class="nextpage"][@href]',
  495. pageElement: 'css;.special > .item',
  496. HT_insert: ['css;.special', 3],
  497. replaceE: 'css;#pageGroup',
  498. scrollDelta: 700
  499. }
  500. },
  501. iplaysoft_postslist: {
  502. SiteTypeID: 0,
  503. pager: {
  504. type: 1,
  505. nextLink: '//div[@class="pagenavi"]//a[@title="下一页"][@href]',
  506. pageElement: 'css;#postlist > div.entry',
  507. HT_insert: ['css;#postlist > .pagenavi-button', 1],
  508. replaceE: 'css;.pagenavi-button, .pagenavi',
  509. scrollDelta: 1200
  510. },
  511. function: {
  512. before: iplaysoft_postslist_beforeFunction
  513. }
  514. },
  515. iplaysoft_postcomments: {
  516. SiteTypeID: 0,
  517. pager: {
  518. type: 2,
  519. nextLink: '#loadHistoryComments',
  520. nextTextOf: '展开后面',
  521. scrollDelta: 1200
  522. }
  523. },
  524. mpyit: {
  525. SiteTypeID: 0,
  526. pager: {
  527. type: 1,
  528. nextLink: '//a[@class="page-numbers"][@title="下一页"][@href]',
  529. pageElement: 'css;#post > div[id^="post-"]',
  530. HT_insert: ['css;#post > #pagenavi', 1],
  531. replaceE: 'css;#post > #pagenavi',
  532. scrollDelta: 1700
  533. }
  534. },
  535. mpyit_category: {
  536. SiteTypeID: 0,
  537. pager: {
  538. type: 1,
  539. nextLink: '//a[@class="page-numbers"][@title="下一页"][@href]',
  540. pageElement: 'css;#content > div[class^="entry_box"]',
  541. HT_insert: ['css;#content > #pagenavi', 1],
  542. replaceE: 'css;#content > #pagenavi',
  543. scrollDelta: 1700
  544. }
  545. },
  546. yxssp: {
  547. SiteTypeID: 0,
  548. pager: {
  549. type: 1,
  550. nextLink: '//div[@class="page-nav td-pb-padding-side"]/a[last()][@href]',
  551. pageElement: 'css;.td-modules-container.td-module-number4 > div',
  552. HT_insert: ['css;.td-modules-container.td-module-number4', 3],
  553. replaceE: 'css;.page-nav.td-pb-padding-side',
  554. scrollDelta: 1000
  555. }
  556. },
  557. manhuadb: {
  558. SiteTypeID: 0,
  559. pager: {
  560. type: 4,
  561. pageElement: 'css;body > script:not([type]):not([src]), .vg-r-data, ol.links-of-books.num_div',
  562. HT_insert: ['css;.pjax-container', 3],
  563. intervals: 5000,
  564. functionNext: manhuadb_functionNext,
  565. functionAdd: manhuadb_functionAdd,
  566. scrollDelta: 3000
  567. }
  568. },
  569. hicomic: {
  570. SiteTypeID: 0,
  571. pager: {
  572. type: 4,
  573. HT_insert: ['css;.content', 3],
  574. intervals: 5000,
  575. functionNext: hicomic_functionNext,
  576. functionAdd: hicomic_functionAdd,
  577. scrollDelta: 3000
  578. }
  579. },
  580. gufengmh8: {
  581. SiteTypeID: 0,
  582. pager: {
  583. type: 4,
  584. pageElement: 'css;body > script:first-child',
  585. HT_insert: ['css;#images', 3],
  586. intervals: 5000,
  587. functionNext: gufengmh8_functionNext,
  588. functionAdd: gufengmh8_functionAdd,
  589. scrollDelta: 4000
  590. }
  591. },
  592. szcdmj: {
  593. SiteTypeID: 0,
  594. pager: {
  595. type: 1,
  596. nextLink: '//div[@class="fanye"][1]/a[@href][text()="下一页" or text()="下一话"]',
  597. pageElement: 'css;.comicpage > div,title',
  598. HT_insert: ['css;.comicpage', 3],
  599. replaceE: 'css;.fanye,h1.title',
  600. scrollDelta: 2000
  601. },
  602. function: {
  603. before: szcdmj_beforeFunction
  604. }
  605. },
  606. rarbgprx: {
  607. SiteTypeID: 0,
  608. pager: {
  609. type: 1,
  610. nextLink: '(//a[@title="next page"])[1][@href]',
  611. pageElement: 'css;table.lista2t tr.lista2',
  612. HT_insert: ['css;table.lista2t > tbody', 3],
  613. replaceE: 'css;#pager_links',
  614. scrollDelta: 900
  615. }
  616. },
  617. pubmed_postslist: {
  618. SiteTypeID: 0,
  619. pager: {
  620. type: 2,
  621. nextLink: 'button.load-button.next-page',
  622. nextText: 'Show more',
  623. scrollDelta: 1500
  624. }
  625. },
  626. afreecatv: {
  627. SiteTypeID: 0,
  628. pager: {
  629. type: 2,
  630. nextLink: '.btn-more > button',
  631. intervals: 2000,
  632. scrollDelta: 1000
  633. }
  634. },
  635. greasyfork: {
  636. SiteTypeID: 0,
  637. pager: {
  638. type: 1,
  639. nextLink: '//a[@class="next_page"][@href]',
  640. pageElement: 'css;ol#browse-script-list > li',
  641. HT_insert: ['css;ol#browse-script-list', 3],
  642. replaceE: 'css;.pagination',
  643. scrollDelta: 1000
  644. }
  645. },
  646. greasyfork_feedback: {
  647. SiteTypeID: 0,
  648. pager: {
  649. type: 1,
  650. nextLink: '//a[@class="next_page"][@href]',
  651. pageElement: 'css;.script-discussion-list > div',
  652. HT_insert: ['css;.script-discussion-list', 3],
  653. replaceE: 'css;.pagination',
  654. scrollDelta: 1500
  655. }
  656. },
  657. greasyfork_discussions: {
  658. SiteTypeID: 0,
  659. pager: {
  660. type: 1,
  661. nextLink: '//a[@class="next_page"][@href]',
  662. pageElement: 'css;.discussion-list > div',
  663. HT_insert: ['css;.discussion-list', 3],
  664. replaceE: 'css;.pagination',
  665. scrollDelta: 1000
  666. }
  667. },
  668. alphacoders_art: {
  669. SiteTypeID: 0,
  670. pager: {
  671. type: 1,
  672. nextLink: '//a[@id="next_page"][@href]',
  673. pageElement: 'css;.container-masonry > div',
  674. HT_insert: ['css;.container-masonry', 3],
  675. replaceE: '//div[@class="hidden-xs hidden-sm"]/..',
  676. scrollDelta: 1000
  677. },
  678. function: {
  679. before: alphacoders_art_beforeFunction
  680. }
  681. },
  682. alphacoders_wall: {
  683. SiteTypeID: 0,
  684. pager: {
  685. type: 1,
  686. nextLink: '//a[@id="next_page"][@href]',
  687. pageElement: 'css;.page_container > .center > div',
  688. HT_insert: ['css;.page_container > .center', 3],
  689. replaceE: '//div[@class="hidden-xs hidden-sm"]/..',
  690. scrollDelta: 1000
  691. }
  692. },
  693. cs_rin_ru: {
  694. SiteTypeID: 0,
  695. pager: {
  696. type: 1,
  697. nextLink: '//td[@class="gensmall"][@align="right"]//a[text()="Next"][@href]',
  698. pageElement: 'css;#pagecontent > table.tablebg > tbody > tr:not([align])',
  699. HT_insert: ['css;#pagecontent > table.tablebg > tbody > tr[align]', 1],
  700. replaceE: 'css;#pagecontent > table:first-child',
  701. scrollDelta: 1500
  702. },
  703. function: {
  704. before: cs_rin_ru_beforeFunction
  705. }
  706. },
  707. cs_rin_ru_viewtopic: {
  708. SiteTypeID: 0,
  709. pager: {
  710. type: 1,
  711. nextLink: 'id("pageheader")/p[@class="gensmall"]//a[text()="Next"][@href]',
  712. pageElement: 'css;#pagecontent > table.tablebg:not(:nth-last-child(2)):not(:nth-child(2))',
  713. HT_insert: ['css;#pagecontent > table.tablebg:nth-last-child(2)', 1],
  714. replaceE: 'css;#pagecontent >table:not(.tablebg), #pageheader p.gensmall',
  715. scrollDelta: 1500
  716. }
  717. },
  718. fitgirl: {
  719. SiteTypeID: 0,
  720. pager: {
  721. type: 1,
  722. nextLink: '//a[@class="next page-numbers"][@href]',
  723. pageElement: 'css;article[id^="post-"]',
  724. HT_insert: ['css;nav.paging-navigation', 1],
  725. replaceE: 'css;nav.paging-navigation',
  726. scrollDelta: 2000
  727. }
  728. }
  729. };
  730. // 生成 SiteTypeID
  731. generateID();
  732.  
  733. // 用于脚本判断(针对部分特殊的网站)
  734. const SiteType = {
  735. GOOGLE: DBSite.google.SiteTypeID,
  736. BAIDU_TIEBA: DBSite.baidu_tieba.SiteTypeID,
  737. GAMERSKY_GL: DBSite.gamersky_gl.SiteTypeID,
  738. STEAMCOMMUNITY: DBSite.steamcommunity.SiteTypeID
  739. };
  740.  
  741.  
  742. // < 其他网站 >
  743. if (webType === 1) {
  744. switch (location.host) {
  745. case 'www.baidu.com': // < 百度搜索 >
  746. curSite = DBSite.baidu;
  747. break;
  748. case 'www.google.com': // < 谷歌搜索 >
  749. if (location.pathname === '/search') curSite = DBSite.google;
  750. break;
  751. case 'www.bing.com': // < 必应搜索 >
  752. case 'cn.bing.com':
  753. if (location.pathname === '/search') {curSite = DBSite.bing; document.lastElementChild.appendChild(document.createElement('style')).textContent = '.b_imagePair.square_mp > .inner {display: none;}';}
  754. break;
  755. case 'tieba.baidu.com': // < 百度贴吧 >
  756. if (location.pathname === '/f') { // 帖子列表
  757. baidu_tieba_1(); // 右侧悬浮发帖按钮点击事件(解决自动翻页导致无法发帖的问题)
  758. curSite = DBSite.baidu_tieba; document.lastElementChild.appendChild(document.createElement('style')).textContent = 'img.j_retract {margin-top: 0 !important;margin-bottom: 0 !important;}'; // 修复帖子列表中预览图片,在切换下一个/上一个图片时,多出来的图片上下边距
  759. //} else if (location.pathname.indexOf('/p/') > -1) { // 帖子内
  760. // curSite = DBSite.baidu_tieba_post;
  761. } else if (location.pathname === '/f/search/res') { // 吧内搜索/全吧搜索
  762. curSite = DBSite.baidu_tieba_search;
  763. }
  764. break;
  765. case 'movie.douban.com': // < 豆瓣评论 >
  766. if (location.pathname.indexOf('/subject') > -1 && location.pathname.indexOf('/comments') > -1) { // 短评列表
  767. curSite = DBSite.douban_subject_comments;
  768. } else if (location.pathname.indexOf('/subject') > -1 && location.pathname.indexOf('/reviews') > -1) { // 影评列表
  769. curSite = DBSite.douban_subject_reviews;
  770. } else if(location.pathname.indexOf('/subject') > -1 && location.pathname.indexOf('/episode') > -1) { // 电视剧每集评论
  771. curSite = DBSite.douban_subject_episode;
  772. }
  773. break;
  774. case 'weibo.com': // < 微博评论 >
  775. curSite = DBSite.weibo_comment;
  776. break;
  777. case 'www.58pic.com': // < 千图网 >
  778. if (location.pathname.indexOf('/tupian/') > -1) {
  779. curSite = DBSite._58pic; document.lastElementChild.appendChild(document.createElement('style')).textContent = '.qtw-card.place-box.is-two {display: none !important;}'; // 隐藏末尾很大的 [下一页] 按钮
  780. } else if (location.pathname.indexOf('/c/') > -1) {
  781. curSite = DBSite._58pic_c;
  782. }
  783. break;
  784. case 'pixabay.com': // < Pixabay >
  785. curSite = DBSite.pixabay;
  786. break;
  787. case 'www.3dmgame.com': // < 3DM >
  788. curSite = DBSite._3dmgame;
  789. break;
  790. case 'www.ali213.net': // < 游侠网 >
  791. curSite = DBSite.ali213_www;
  792. break;
  793. case 'gl.ali213.net': // < 游侠网 - 攻略页 >
  794. curSite = DBSite.ali213_gl; document.lastElementChild.appendChild(document.createElement('style')).textContent = '.n_show_b {display: none !important;}'; // 隐藏部分碍事元素
  795. break;
  796. case 'www.gamersky.com': // < 游民星空 >
  797. if (location.pathname.indexOf('/ent/') > -1) {
  798. curSite = DBSite.gamersky_ent;
  799. } else {
  800. curSite = DBSite.gamersky_gl;
  801. }
  802. break;
  803. case 'steamcommunity.com': // < Steam 创意工坊 >
  804. curSite = DBSite.steamcommunity;
  805. break;
  806. case 'www.423down.com': // < 423down >
  807. if (location.pathname.indexOf('.html') === -1) curSite = DBSite._423down;
  808. break;
  809. case 'www.sordum.org': // < Sordum >
  810. curSite = DBSite.sordum;
  811. break;
  812. case 'iao.su': // < 不死鸟 >
  813. curSite = DBSite.iao_su;
  814. break;
  815. case 'www.appinn.com': // < 小众软件 >
  816. curSite = DBSite.appinn;
  817. break;
  818. case 'www.sixyin.com': // < 六音软件 >
  819. if (location.pathname === '/' && location.search === '') { // 首页
  820. curSite = DBSite.sixyin;
  821. } else if (location.pathname.indexOf('.html') === -1) { // 分类页
  822. curSite = DBSite.sixyin_postlist;
  823. }
  824. break;
  825. case 'www.weidown.com': // < 微当下载 >
  826. if (location.pathname.indexOf('/search/') > -1) {
  827. curSite = DBSite.weidown_search;
  828. } else if (location.pathname.indexOf('/special/') > -1) {
  829. curSite = DBSite.weidown_special;
  830. } else {
  831. curSite = DBSite.weidown;
  832. }
  833. break;
  834. case 'www.iplaysoft.com': // < 异次元软件 >
  835. if (location.pathname.indexOf('.html') > -1 || location.pathname.indexOf('/p/') > -1) { // 文章内
  836. curSite = DBSite.iplaysoft_postcomments;
  837. } else { // 其他页面
  838. curSite = DBSite.iplaysoft_postslist;
  839. }
  840. break;
  841. case 'www.mpyit.com': // < 老殁殁漂遥 >
  842. if (location.pathname === '/' && !location.search) {
  843. curSite = DBSite.mpyit;
  844. } else if (location.pathname.indexOf('/category/') > -1 || location.search.indexOf('?s=') > -1) {
  845. curSite = DBSite.mpyit_category;
  846. }
  847. break;
  848. case 'www.yxssp.com': // < 异星软件空间 >
  849. curSite = DBSite.yxssp;
  850. break;
  851. case 'www.manhuadb.com': // < 漫画DB >
  852. if (location.pathname.indexOf('/manhua/') > -1 && location.pathname.indexOf('.html') > -1) {
  853. document.lastElementChild.appendChild(document.createElement('style')).textContent = '.row.m-0.pt-3.ad_2_wrap, .row.m-0.ad_1_wrap, .pagination.justify-content-center, #left, #right {display: none !important;}';
  854. document.querySelector('img.img-fluid.show-pic').style.display = 'none'; // 隐藏第一个图片(避免重复)
  855. setTimeout(manhuadb_init, 100);
  856. curSite = DBSite.manhuadb;
  857. }
  858. break;
  859. case 'www.hicomic.net': // < HiComic(嗨漫画) >
  860. if (location.pathname.indexOf('/chapters/') > -1) {
  861. document.lastElementChild.appendChild(document.createElement('style')).textContent = '.content {height: auto !important;} .footer, .left_cursor, .right_cursor, .finish {display: none !important;} .content > img {display: block !important;margin: 0 auto !important;}';
  862. setTimeout(hicomic_init, 100);
  863. curSite = DBSite.hicomic;
  864. }
  865. break;
  866. case 'www.gufengmh8.com': // < 古风漫画网 >
  867. if (location.pathname.indexOf('.html') > -1) {
  868. let chapterScroll = document.getElementById('chapter-scroll') // 强制为 [下拉阅读] 模式
  869. if (chapterScroll && chapterScroll.className === '') {chapterScroll.click();}
  870. curSite = DBSite.gufengmh8; document.lastElementChild.appendChild(document.createElement('style')).textContent = 'p.img_info {display: none !important;}'; // 隐藏中间的页数信息
  871. }
  872. break;
  873. case 'www.szcdmj.com': // < 砂之船动漫家 >
  874. if (location.pathname.indexOf('/szcchapter/') > -1) curSite = DBSite.szcdmj;
  875. break;
  876. case 'rarbgprx.org': // < RARBG >
  877. curSite = DBSite.rarbgprx;
  878. break;
  879. case 'pubmed.ncbi.nlm.nih.gov': // < 国外学术网站 >
  880. curSite = DBSite.pubmed_postslist;
  881. break;
  882. case 'www.afreecatv.com': // < 直播网站 >
  883. curSite = DBSite.afreecatv;
  884. break;
  885. case 'greasyfork.org': // < GreasyFork >
  886. if (location.pathname.indexOf('/scripts') + 8 === location.pathname.length) {
  887. curSite = DBSite.greasyfork;
  888. } else if (location.pathname.lastIndexOf('/feedback') + 9 === location.pathname.length) {
  889. curSite = DBSite.greasyfork_feedback;
  890. } else if (location.pathname.lastIndexOf('/discussions') + 12 === location.pathname.length) {
  891. curSite = DBSite.greasyfork_discussions;
  892. }
  893. break;
  894. case 'art.alphacoders.com': // < 壁纸网站 >
  895. curSite = DBSite.alphacoders_art;
  896. setTimeout(alphacoders_art_beforeFunction_0, 1000);
  897. break;
  898. /*case 'wall.alphacoders.com': // 这几个已经原生支持自动无缝翻页了
  899. case 'avatars.alphacoders.com':
  900. case 'mobile.alphacoders.com':
  901. curSite = DBSite.alphacoders_wall;
  902. break;*/
  903. case 'cs.rin.ru': // < cs_rin_ru >
  904. if (location.pathname === '/forum/viewforum.php') { // 版块帖子列表
  905. curSite = DBSite.cs_rin_ru;
  906. } else if (location.pathname === '/forum/viewtopic.php') { // 帖子内
  907. if (GM_getValue('menu_discuz_thread_page')) curSite = DBSite.cs_rin_ru_viewtopic;
  908. }
  909. break;
  910. case 'crackhub.site': // < 游戏下载网站 >
  911. curSite = DBSite.fitgirl; document.lastElementChild.appendChild(document.createElement('style')).textContent = 'html.wp-dark-mode-active .inside-article {background-color: var(--wp-dark-mode-bg);}'
  912. break;
  913. case 'fitgirl-repacks.site': // < 游戏下载网站 >
  914. curSite = DBSite.fitgirl;
  915. break;
  916. }
  917. // < 所有 Discuz!论坛 >
  918. } else if (webType === 2) {
  919. if (location.pathname.indexOf('.html') > -1) { // 判断是不是静态网页(.html 结尾)
  920. if (location.pathname.indexOf('/forum-') > -1) { // 各版块帖子列表
  921. if (document.getElementById('autopbn')) { // 判断是否有 [下一页] 按钮
  922. curSite = DBSite.discuz_forum;
  923. } else {
  924. curSite = DBSite.discuz_guide;
  925. }
  926. } else if (location.pathname.indexOf('/thread-') > -1) { // 帖子内
  927. if (GM_getValue('menu_discuz_thread_page')) {
  928. curSite = DBSite.discuz_thread;
  929. hidePgbtn(); // 隐藏帖子内的 [下一页] 按钮
  930. }
  931. } else if(location.pathname.indexOf('search') > -1) { // 搜索结果
  932. curSite = DBSite.discuz_search;
  933. }
  934. } else {
  935. if (location.search.indexOf('mod=forumdisplay') > -1) { // 各版块帖子列表
  936. if (document.getElementById('autopbn')) { // 判断是否有 [下一页] 按钮
  937. curSite = DBSite.discuz_forum;
  938. } else {
  939. curSite = DBSite.discuz_guide;
  940. }
  941. } else if (location.search.indexOf('mod=viewthread') > -1) { // 帖子内
  942. if (GM_getValue('menu_discuz_thread_page')) {
  943. curSite = DBSite.discuz_thread;
  944. hidePgbtn(); // 隐藏帖子内的 [下一页] 按钮
  945. }
  946. } else if (location.search.indexOf('mod=guide') > -1) { // 导读帖子列表
  947. curSite = DBSite.discuz_guide;
  948. } else if(location.search.indexOf('mod=space') > -1 && location.search.indexOf('&view=me') > -1) { // 别人的主题/回复
  949. curSite = DBSite.discuz_youspace;
  950. } else if (location.search.indexOf('mod=collection') > -1) { // 淘贴列表
  951. curSite = DBSite.discuz_collection;
  952. } else if (location.pathname.indexOf('search') > -1) { // 搜索结果
  953. curSite = DBSite.discuz_search;
  954. } else { // 考虑到部分论坛的部分板块帖子列表 URL 是自定义的
  955. curSite = DBSite.discuz_forum;
  956. }
  957. }
  958. // < 所有 Flarum 论坛 >
  959. } else if (webType === 3) {
  960. curSite = DBSite.flarum;
  961. // < 所有使用 WordPress DUX 主题的网站 >
  962. } else if (webType === 4) {
  963. if (location.pathname.indexOf('.html') === -1) curSite = DBSite.dux;
  964. if (location.host === 'apphot.cc') curSite.pager.scrollDelta = 2500; // 对于速度慢的网站,需要增加翻页敏感度
  965. }
  966.  
  967. pausePageEvent(); // 左键双击网页空白处暂停翻页
  968. curSite.pageUrl = ''; // 下一页URL
  969. //console.log(curSite);
  970. pageLoading(); // 自动无缝翻页
  971.  
  972.  
  973. // 隐藏帖子内的 [下一页] 按钮(Discuz! 论坛)
  974. function hidePgbtn() {
  975. document.lastChild.appendChild(document.createElement('style')).textContent = '.pgbtn {display: none;}';
  976. }
  977.  
  978.  
  979. // dux 的插入前函数(加载图片)
  980. function dux_beforeFunction(pageElems) {
  981. pageElems.forEach(function (one) {
  982. let now = one.querySelector('img.thumb[data-src]')
  983. if (now) {now.src = now.dataset.src;}
  984. });
  985. return pageElems
  986. }
  987.  
  988.  
  989. // 百度贴吧(发帖按钮点击事件)
  990. function baidu_tieba_1() {
  991. let button = document.querySelector('.tbui_aside_fbar_button.tbui_fbar_post > a');
  992. if (button) {
  993. button.remove();
  994. document.querySelector('li.tbui_aside_fbar_button.tbui_fbar_down').insertAdjacentHTML(addTo(4), '<li class="tbui_aside_fbar_button tbui_fbar_post"><a href="javascript:void(0);" title="因为 [自动无缝翻页] 的原因,请点击该按钮发帖!"></a></li>')
  995. button = document.querySelector('.tbui_aside_fbar_button.tbui_fbar_post > a');
  996. if (button) {
  997. button.onclick = function(){
  998. let button2 = document.querySelector('div.edui-btn.edui-btn-fullscreen.edui-btn-name-portrait');
  999. if (button2) {
  1000. button2.click();
  1001. } else {
  1002. alert('提示:登录后才能发帖!');
  1003. }
  1004. return false;
  1005. }
  1006. }
  1007. }
  1008. }
  1009.  
  1010.  
  1011. // 百度贴吧 的插入前函数(加载图片)
  1012. function baidu_tieba_beforeFunction(pageElems) {
  1013. pageElems.forEach(function (one) {
  1014. one.querySelectorAll('img.threadlist_pic[data-original]').forEach(function (now) {
  1015. now.src = now.dataset.original;
  1016. now.style.display = 'inline';
  1017. })
  1018. });
  1019. return pageElems
  1020. }
  1021.  
  1022.  
  1023. // 58pic 的插入前函数(加载图片)
  1024. function _58pic_beforeFunction(pageElems) {
  1025. let is_one = document.querySelector('.qtw-card.place-box.is-one');
  1026. if (is_one && is_one.style.display != 'none') {is_one.style.display = 'none';}
  1027. pageElems.forEach(function (one) {
  1028. let now = one.querySelector('img.lazy')
  1029. if (now && now.getAttribute('src') != now.dataset.original) {
  1030. now.src = now.dataset.original;
  1031. now.style.display = 'block';
  1032. }
  1033. });
  1034. return pageElems
  1035. }
  1036.  
  1037.  
  1038. // Pixabay 的插入前函数(加载图片)
  1039. function pixabay_beforeFunction(pageElems) {
  1040. pageElems.forEach(function (one) {
  1041. let now = one.querySelector('img[data-lazy-src]')
  1042. if (now) {
  1043. now.src = now.dataset.lazySrc;
  1044. now.removeAttribute('data-lazy-src')
  1045. now.removeAttribute('data-lazy-srcset')
  1046. }
  1047. });
  1048. return pageElems
  1049. }
  1050.  
  1051.  
  1052. // 游民星空攻略 的插入前函数(移除下一页底部的 "更多相关内容请关注:xxx" 文字)
  1053. function gamersky_gl_beforeFunction(pageElems) {
  1054. pageElems.forEach(function (one) {
  1055. if (one.tagName === 'P' && one.textContent.indexOf('更多相关内容请关注') > -1) {one.style.display = 'none';}
  1056. });
  1057. return pageElems
  1058. }
  1059.  
  1060.  
  1061. // iao.su 的插入前函数(加载图片)
  1062. function iao_su_beforeFunction(pageElems) {
  1063. pageElems.forEach(function (one) {
  1064. let now = one.getElementsByClassName('post-card')[0]
  1065. if (now) {
  1066. now.getElementsByClassName('blog-background')[0].style.backgroundImage = 'url("' + now.getElementsByTagName('script')[0].textContent.split("'")[1] + '")';
  1067. //now.getElementsByClassName('blog-background')[0].style.backgroundImage = 'url("' + RegExp("(?<=loadBannerDirect\\(').*(?=', '',)").exec(now.getElementsByTagName('script')[0].textContent)[0]; + '")';
  1068. }
  1069. });
  1070. return pageElems
  1071. }
  1072.  
  1073.  
  1074. // iplaysoft 的插入前函数(加载图片)
  1075. function iplaysoft_postslist_beforeFunction(pageElems) {
  1076. pageElems.forEach(function (one) {
  1077. let now = one.querySelector('img.lazyload')
  1078. if (now && !now.src) {
  1079. now.src = now.dataset.src;
  1080. now.setAttribute('srcset', now.dataset.src)
  1081. now.setAttribute('class', 'lazyloaded')
  1082. }
  1083. });
  1084. return pageElems
  1085. }
  1086.  
  1087.  
  1088. // alphacoders_art 的插入前函数(图片结构调整)
  1089. function alphacoders_art_beforeFunction(pageElems) {
  1090. pageElems.forEach(function (one) {
  1091. one.style.float = 'left';
  1092. });
  1093. return pageElems
  1094. }
  1095. // alphacoders_art(图片结构调整)
  1096. function alphacoders_art_beforeFunction_0() {
  1097. let pageElems1 = document.querySelectorAll('.container-masonry > div')
  1098. document.querySelector('.container-masonry').style.height = 'auto'
  1099. pageElems1.forEach(function (one) {
  1100. one.style.float = 'left';
  1101. });
  1102. }
  1103.  
  1104.  
  1105. // cs_rin_ru 的插入前函数(过滤置顶帖子)
  1106. function cs_rin_ru_beforeFunction(pageElems) {
  1107. for (let i = 0; i < pageElems.length; i++) {
  1108. if (pageElems[i].textContent.replace(/\n| /g,'') === 'Topics') {
  1109. pageElems.splice(0,i+1);
  1110. break;
  1111. }
  1112. }
  1113. return pageElems
  1114. }
  1115.  
  1116.  
  1117. // manhuadb 初始化(将本话其余图片插入网页中)
  1118. function manhuadb_init() {
  1119. let _img = '',
  1120. data = document.querySelector('.vg-r-data'), imgDate;
  1121. if (!data) return
  1122. document.querySelectorAll(curSite.pager.pageElement.replace('css;', '')).forEach(function (one) {
  1123. if (one.tagName === 'SCRIPT' && one.textContent.indexOf('var img_data =') > -1) {
  1124. let json = JSON.parse(window.atob(one.textContent.split("'")[1]));
  1125. if (json) {
  1126. let _img = '';
  1127. for (let i = 0; i < json.length; i++) { // 遍历图片文件名数组,组合为 img 标签
  1128. let src = data.dataset.host + data.dataset.img_pre + json[i].img;
  1129. _img += `<img class="img-fluid show-pic" src="${src}">`
  1130. }
  1131. document.querySelector(curSite.pager.HT_insert[0].replace('css;', '')).insertAdjacentHTML(addTo(curSite.pager.HT_insert[1]), _img); // 将 img 标签插入到网页中
  1132. }
  1133. }
  1134. })
  1135. }
  1136. // manhuadb 获取下一页地址
  1137. function manhuadb_functionNext() {
  1138. let nextArr = document.querySelectorAll('a.fixed-a-es'), next;
  1139. if (nextArr.length == 0) return
  1140. curSite.pageUrl = '';
  1141. for (let i = 0; i < nextArr.length; i++) {
  1142. if (nextArr[i].className.indexOf('active') > -1) {
  1143. if (nextArr[i+1]) curSite.pageUrl = nextArr[i+1].href;
  1144. break;
  1145. }
  1146. }
  1147. if (curSite.pageUrl) getPageElems(curSite.pageUrl);
  1148. }
  1149. // manhuadb 插入数据
  1150. function manhuadb_functionAdd(pageElems, type) {
  1151. if (!pageElems) return
  1152. let oriE = document.querySelectorAll(curSite.pager.pageElement.replace('css;', '')),
  1153. repE = getAllElements(curSite.pager.pageElement, pageElems, pageElems);
  1154. if (oriE.length === repE.length) {
  1155. for (let i = 0; i < oriE.length; i++) {
  1156. oriE[i].outerHTML = repE[i].outerHTML;
  1157. }
  1158. manhuadb_init(); // 将刚刚替换的图片插入网页中
  1159. }
  1160. }
  1161.  
  1162.  
  1163. // hicomic 初始化(将本话其余图片插入网页中)
  1164. function hicomic_init() {
  1165. let _img = '';
  1166. document.querySelectorAll('.chapter > section:not(:first-child) > section[val]').forEach(function (one) {
  1167. let src = one.getAttribute('val');
  1168. if (src.indexOf('!p_c_c_') === -1) src += '!p_c_c_h'
  1169. _img += `<img src="${src}">`
  1170. })
  1171. document.querySelector(curSite.pager.HT_insert[0].replace('css;', '')).insertAdjacentHTML(addTo(curSite.pager.HT_insert[1]), _img); // 将 img 标签插入到网页中
  1172. window.document.title = window.document.title.replace(/(\(第.+\))? - HiComic/, `(${document.querySelector('.chapter_name').textContent}) - HiComic`); // 修改网页标题(加上 第 X 话)
  1173. }
  1174. // hicomic 获取下一页地址
  1175. function hicomic_functionNext() {
  1176. let nextId;
  1177. nextId = document.querySelector('.next_chapter:not(.end)')
  1178. if (nextId && nextId.id && nextId.id != 'None') {
  1179. curSite.pageUrl = location.href;
  1180. getPageElems(`https://www.hicomic.net/api/web/chapter/${nextId.id}/contents`, 'json');
  1181. }
  1182. }
  1183. // hicomic 插入数据
  1184. function hicomic_functionAdd(pageElems, type) {
  1185. if (!pageElems || pageElems.code != 200) return
  1186. if (pageElems.results.chapter.next) { // 写入下一页的 UUID
  1187. document.querySelector('.next_chapter').id = pageElems.results.chapter.next;
  1188. } else {
  1189. document.querySelector('.next_chapter').id = 'None';
  1190. document.querySelector('.next_chapter').classList.add('end');
  1191. }
  1192. document.querySelector('.chapter_name').textContent = pageElems.results.chapter.name; // 修改漫画标题
  1193. let title = window.document.title.replace(/(\(第.+\))? - HiComic/, `(${pageElems.results.chapter.name}) - HiComic`)
  1194. window.history.pushState(`{title: ${document.title}, url: ${location.href}}`, title, curSite.pageUrl); // 添加历史记录
  1195. window.document.title = title; // 修改当前网页标题为下一话的标题
  1196. let _img = '';
  1197. for (let i = 0; i < pageElems.results.chapter.contents.length; i++) { // 遍历图片文件名数组,组合为 img 标签
  1198. let src = pageElems.results.chapter.contents[i].url;
  1199. if (src.indexOf('!p_c_c_') === -1) src += '!p_c_c_h';
  1200. _img += `<img src="${src}">`
  1201. }
  1202. document.querySelector(curSite.pager.HT_insert[0].replace('css;', '')).insertAdjacentHTML(addTo(curSite.pager.HT_insert[1]), _img); // 将 img 标签插入到网页中
  1203. }
  1204.  
  1205.  
  1206. // gufengmh8 获取下一页地址
  1207. function gufengmh8_functionNext() {
  1208. let pageElems = document.querySelector(curSite.pager.pageElement.replace('css;', '')); // 寻找数据所在元素
  1209. if (pageElems) {
  1210. let comicUrl, nextId;
  1211. pageElems.textContent.split(';').forEach(function (one){ // 分号 ; 分割为数组并遍历
  1212. //console.log(one)
  1213. if (one.indexOf('comicUrl') > -1) { // 下一页 URL 前半部分
  1214. comicUrl = one.split('"')[1];
  1215. } else if (one.indexOf('nextChapterData') > -1) { // 下一页 URL 的后半部分 ID
  1216. nextId = one.split('"id":')[1].split(',')[0];
  1217. }
  1218. })
  1219. if (comicUrl && nextId && nextId != 'null') { // 组合到一起就是下一页 URL
  1220. curSite.pageUrl = comicUrl + nextId + '.html'
  1221. getPageElems(curSite.pageUrl); // 访问下一页 URL 获取
  1222. }
  1223. }
  1224. }
  1225. // gufengmh8 插入数据
  1226. function gufengmh8_functionAdd(pageElems, type) {
  1227. if (pageElems) {
  1228. let url = curSite.pageUrl;
  1229. pageElems = getAllElements(curSite.pager.pageElement, pageElems, pageElems)[0];
  1230. let chapterImages, chapterPath;
  1231. document.querySelector(curSite.pager.pageElement.replace('css;', '')).innerText = pageElems.textContent; // 将当前网页内的数据所在元素内容改为刚刚获取的下一页数据内容,以便循环获取下一页 URL
  1232. pageElems.textContent.split(';').forEach(function (one){ // 分号 ; 分割为数组并遍历
  1233. //console.log(one)
  1234. if (one.indexOf('chapterImages') > -1) { // 图片文件名数组
  1235. chapterImages = one.replace(/^.+\[/, '').replace(']', '').replaceAll('"', '').split(',')
  1236. } else if (one.indexOf('chapterPath') > -1) { // 图片文件路径
  1237. chapterPath = one.split('"')[1];
  1238. } else if (one.indexOf('pageTitle') > -1) { // 网页标题
  1239. let title = one.split('"')[1];
  1240. window.history.pushState(`{title: ${document.title}, url: ${location.href}}`, title, url); // 添加历史记录
  1241. window.document.title = title; // 修改当前网页标题为下一页的标题
  1242. }
  1243. })
  1244. if (chapterImages && chapterPath) {
  1245. let _img = '';
  1246. chapterImages.forEach(function (one2){ // 遍历图片文件名数组,组合为 img 标签
  1247. _img += '<img src="https://res.xiaoqinre.com/' + chapterPath + one2 + '" data-index="0" style="display: inline-block;">'
  1248. })
  1249. document.querySelector(curSite.pager.HT_insert[0].replace('css;', '')).insertAdjacentHTML(addTo(curSite.pager.HT_insert[1]), _img); // 将 img 标签插入到网页中
  1250. }
  1251. }
  1252. }
  1253.  
  1254.  
  1255. // szcdmj 的插入前函数(加载图片)
  1256. function szcdmj_beforeFunction(pageElems) {
  1257. pageElems.forEach(function (one) {
  1258. if (one.tagName === 'TITLE') {
  1259. let title = one.textContent;
  1260. window.history.pushState(`{title: ${document.title}, url: ${location.href}}`, title, curSite.pageUrl); // 添加历史记录
  1261. window.document.title = title; // 修改当前网页标题为下一页的标题
  1262. one.style.display = 'none';
  1263. } else {
  1264. let now = one.querySelector('img[data-original]')
  1265. if (now) {
  1266. now.src = now.dataset.original;
  1267. now.style.display = 'inline';
  1268. }
  1269. }
  1270. });
  1271. return pageElems
  1272. }
  1273.  
  1274.  
  1275. // 自动无缝翻页
  1276. function pageLoading() {
  1277. if (curSite.SiteTypeID > 0) {
  1278. windowScroll(function (direction, e) {
  1279. if (direction === 'down' && pausePage === true) { // 下滑/没有暂停翻页时,才准备翻页
  1280. let scrollTop = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop,
  1281. scrollHeight = window.innerHeight || document.documentElement.clientHeight,
  1282. scrollDelta = curSite.pager.scrollDelta;
  1283. if (curSite.pager.type === 3) { // <<<<< 翻页类型 3(依靠元素距离可视区域底部的距离来触发翻页)>>>>>
  1284. let scrollElement = document.querySelector(curSite.pager.scrollElement);
  1285. //console.log(scrollElement.offsetTop - (scrollTop + scrollHeight), scrollDelta, curSite.SiteTypeID)
  1286. if (scrollElement.offsetTop - (scrollTop + scrollHeight) <= scrollDelta) {
  1287. if (curSite.SiteTypeID === SiteType.GAMERSKY_GL) curSite.pager.scrollDelta -= 800 // 游民星空 gl 的比较奇葩,需要特殊处理下
  1288. ShowPager.loadMorePage();
  1289. }
  1290. } else {
  1291. if (document.documentElement.scrollHeight <= scrollHeight + scrollTop + scrollDelta) {
  1292. if (curSite.pager.type === 2) { // <<<<< 翻页类型 2(网站自带了自动无缝翻页功能,只需要点击下一页按钮即可)>>>>>
  1293. if (curSite.SiteTypeID > 0) { // 如果指定了间隔时间,那么就依靠这个判断时间到了没有~
  1294. let autopbn = document.querySelector(curSite.pager.nextLink);
  1295. if (autopbn) { // 寻找下一页链接
  1296. if (!curSite.pager.nextText && !curSite.pager.nextTextOf && !curSite.pager.nextHTML) { // 如果没有指定按钮文字就直接点击
  1297. autopbn.click();
  1298. // 对于没有按钮文字变化的按钮,可以手动指定间隔时间
  1299. if (curSite.pager.intervals) {
  1300. let _SiteTypeID = curSite.SiteTypeID; curSite.SiteTypeID = 0;
  1301. setTimeout(function(){curSite.SiteTypeID = _SiteTypeID;}, curSite.pager.intervals)
  1302. }
  1303. } else { // 避免重复点击翻页按钮
  1304. if (curSite.pager.nextText) { // 按钮文本,当按钮文本 = 该文本时,才会点击按钮加载下一页
  1305. if (autopbn.innerText === curSite.pager.nextText) autopbn.click();
  1306. } else if (curSite.pager.nextTextOf) { // 按钮文本的一部分,当按钮文本包含该文本时,才会点击按钮加载下一页
  1307. if (autopbn.innerText.indexOf(curSite.pager.nextTextOf) > -1) autopbn.click();
  1308. } else if (curSite.pager.nextHTML) { // 按钮内元素,当按钮内元素 = 该元素内容时,才会点击按钮加载下一页
  1309. if (autopbn.innerHTML === curSite.pager.nextHTML) autopbn.click();
  1310. }
  1311. }
  1312. }
  1313. }
  1314. } else if (curSite.pager.type === 1) { // <<<<< 翻页类型 1(由脚本实现自动无缝翻页)>>>>>
  1315. // 为百度贴吧的发帖考虑...
  1316. if (!(document.documentElement.scrollHeight <= scrollHeight + scrollTop + 200 && curSite.SiteTypeID === SiteType.BAIDU_TIEBA)) {
  1317. ShowPager.loadMorePage();
  1318. }
  1319. } else if (curSite.pager.type === 4) { // <<<<< 翻页类型 4(部分简单的动态加载类网站)>>>>>
  1320. if (curSite.SiteTypeID > 0) {
  1321. curSite.pager.functionNext();
  1322. if (curSite.pager.intervals) {
  1323. let _SiteTypeID = curSite.SiteTypeID;
  1324. curSite.SiteTypeID = 0;
  1325. setTimeout(function(){curSite.SiteTypeID = _SiteTypeID;}, curSite.pager.intervals)
  1326. }
  1327. }
  1328. }
  1329. }
  1330. }
  1331. }
  1332. });
  1333. }
  1334. }
  1335.  
  1336.  
  1337. // 启用/禁用 (当前网站)
  1338. function menu_disable(type) {
  1339. switch(type) {
  1340. case 'check':
  1341. if(check()) {return true;} else {return false;}; break;
  1342. case 'add':
  1343. add(); break;
  1344. case 'del':
  1345. del(); break;
  1346. }
  1347.  
  1348. function check() { // 存在返回真,不存在返回假
  1349. let list = GM_getValue('menu_disable'); // 读取网站列表
  1350. if (list.indexOf(location.host) === -1) return false // 不存在返回假
  1351. return true
  1352. }
  1353.  
  1354. function add() {
  1355. if (check()) return
  1356. let list = GM_getValue('menu_disable'); // 读取网站列表
  1357. list.push(location.host); // 追加网站域名
  1358. GM_setValue('menu_disable', list); // 写入配置
  1359. location.reload(); // 刷新网页
  1360. }
  1361.  
  1362. function del() {
  1363. if (!check()) return
  1364. let list = GM_getValue('menu_disable'), // 读取网站列表
  1365. index = list.indexOf(location.host);
  1366. list.splice(index, 1); // 删除网站域名
  1367. GM_setValue('menu_disable', list); // 写入配置
  1368. location.reload(); // 刷新网页
  1369. }
  1370. }
  1371.  
  1372.  
  1373. // 左键双击网页空白处暂停翻页
  1374. function pausePageEvent() {
  1375. if (!GM_getValue('menu_pause_page')) return
  1376. if (curSite.SiteTypeID === 0) return
  1377. document.body.addEventListener('dblclick', function (e) {
  1378. if (pausePage) {
  1379. pausePage = false;
  1380. GM_notification({text: `❌ 已暂停本页 [自动无缝翻页]\n (再次双击可恢复)`, timeout: 2500});
  1381. } else {
  1382. pausePage = true;
  1383. GM_notification({text: `✅ 已恢复本页 [自动无缝翻页]\n (再次双击可暂停)`, timeout: 2500});
  1384. }
  1385. });
  1386. }
  1387.  
  1388.  
  1389. // 菜单开关
  1390. function menu_switch(menu_status, Name, Tips) {
  1391. if (menu_status === true){
  1392. GM_setValue(`${Name}`, false);
  1393. } else {
  1394. GM_setValue(`${Name}`, true);
  1395. }
  1396. location.reload();
  1397. };
  1398.  
  1399.  
  1400. // 生成 ID
  1401. function generateID() {
  1402. let num = 0
  1403. for (let val in DBSite) {
  1404. DBSite[val].SiteTypeID = num = num + 1;
  1405. }
  1406. }
  1407.  
  1408.  
  1409. // 类型 4 专用
  1410. function getPageElems(url, type = 'text', method = 'GET', data = '', type2) {
  1411. //console.log(url, data)
  1412. GM_xmlhttpRequest({
  1413. url: url,
  1414. method: method,
  1415. data: data,
  1416. responseType: type,
  1417. headers: {
  1418. 'Content-Type': (method === 'POST') ? 'application/x-www-form-urlencoded':''
  1419. },
  1420. timeout: 5000,
  1421. onload: function (response) {
  1422. try {
  1423. //console.log('最终 URL:' + response.finalUrl, '返回内容:' + response.responseText)
  1424. switch (type) {
  1425. case 'json':
  1426. curSite.pager.functionAdd(response.response, type2);
  1427. break;
  1428. default:
  1429. curSite.pager.functionAdd(ShowPager.createDocumentByString(response.responseText), type2)
  1430. }
  1431. } catch (e) {
  1432. console.log(e);
  1433. }
  1434. }
  1435. });
  1436. }
  1437.  
  1438.  
  1439. // 插入位置
  1440. function addTo(num) {
  1441. switch (num) {
  1442. case 1:
  1443. return 'beforebegin'; break;
  1444. case 2:
  1445. return 'afterbegin'; break;
  1446. case 3:
  1447. return 'beforeend'; break;
  1448. case 4:
  1449. return 'afterend'; break;
  1450. }
  1451. }
  1452.  
  1453.  
  1454. // 滚动条事件
  1455. function windowScroll(fn1) {
  1456. var beforeScrollTop = document.documentElement.scrollTop,
  1457. fn = fn1 || function () {};
  1458. setTimeout(function () { // 延时 1 秒执行,避免刚载入到页面就触发翻页事件
  1459. window.addEventListener('scroll', function (e) {
  1460. var afterScrollTop = document.documentElement.scrollTop,
  1461. delta = afterScrollTop - beforeScrollTop;
  1462. if (delta == 0) return false;
  1463. fn(delta > 0 ? 'down' : 'up', e);
  1464. beforeScrollTop = afterScrollTop;
  1465. }, false);
  1466. }, 1000)
  1467. }
  1468.  
  1469.  
  1470. // 修改自 https://greasyfork.org/scripts/14178 , https://github.com/machsix/Super-preloader
  1471. var ShowPager = {
  1472. getFullHref: function (e) {
  1473. if (e != null && e.nodeType === 1 && e.href && e.href.slice(0,4) === 'http') return e.href;
  1474. return '';
  1475. },
  1476. createDocumentByString: function (e) {
  1477. if (e) {
  1478. if ('HTML' !== document.documentElement.nodeName) return (new DOMParser).parseFromString(e, 'application/xhtml+xml');
  1479. var t;
  1480. try { t = (new DOMParser).parseFromString(e, 'text/html');} catch (e) {}
  1481. if (t) return t;
  1482. if (document.implementation.createHTMLDocument) {
  1483. t = document.implementation.createHTMLDocument('ADocument');
  1484. } else {
  1485. try {((t = document.cloneNode(!1)).appendChild(t.importNode(document.documentElement, !1)), t.documentElement.appendChild(t.createElement('head')), t.documentElement.appendChild(t.createElement('body')));} catch (e) {}
  1486. }
  1487. if (t) {
  1488. var r = document.createRange(),
  1489. n = r.createContextualFragment(e);
  1490. r.selectNodeContents(document.body);
  1491. t.body.appendChild(n);
  1492. for (var a, o = { TITLE: !0, META: !0, LINK: !0, STYLE: !0, BASE: !0}, i = t.body, s = i.childNodes, c = s.length - 1; c >= 0; c--) o[(a = s[c]).nodeName] && i.removeChild(a);
  1493. return t;
  1494. }
  1495. } else console.error('没有找到要转成 DOM 的字符串');
  1496. },
  1497. loadMorePage: function () {
  1498. if (curSite.pager) {
  1499. let curPageEle = getElementByXpath(curSite.pager.nextLink);
  1500. var url = this.getFullHref(curPageEle);
  1501. //console.log(url, curPageEle, curSite.pageUrl);
  1502. if (url === '') return;
  1503. if (curSite.pageUrl === url) return;// 避免重复加载相同的页面
  1504. curSite.pageUrl = url;
  1505. if (curSite.SiteTypeID === SiteType.BAIDU_TIEBA) {
  1506. url = url + '&pagelets=frs-list%2Fpagelet%2Fthread&pagelets_stamp=' + new Date().getTime();
  1507. }
  1508. // 读取下一页的数据
  1509. GM_xmlhttpRequest({
  1510. url: url,
  1511. method: 'GET',
  1512. timeout: 5000,
  1513. onload: function (response) {
  1514. try {
  1515. //console.log('最终 URL:' + response.finalUrl, '返回内容:' + response.responseText)
  1516. var newBody = ShowPager.createDocumentByString(response.responseText);
  1517. let pageElems = getAllElements(curSite.pager.pageElement, newBody, newBody),
  1518. toElement = getAllElements(curSite.pager.HT_insert[0])[0];
  1519. //console.log(curSite.pager.pageElement, pageElems)
  1520.  
  1521. if (pageElems.length >= 0) {
  1522. // 如果有插入前函数就执行函数
  1523. if (curSite.function && curSite.function.before) {
  1524. if (curSite.function.parameter) { // 如果指定了参数
  1525. pageElems = curSite.function.before(curSite.function.parameter);
  1526. } else {
  1527. pageElems = curSite.function.before(pageElems);
  1528. }
  1529. }
  1530.  
  1531. // 插入位置
  1532. let addTo1 = addTo(curSite.pager.HT_insert[1]);
  1533.  
  1534. // 插入新页面元素
  1535. if (curSite.SiteTypeID === SiteType.STEAMCOMMUNITY) {
  1536. pageElems.forEach(function (one) {
  1537. if (one.tagName === 'SCRIPT') { // 对于 <script> 需要用另一种方式插入网页,以便正常运行
  1538. toElement.appendChild(document.createElement('script')).innerHTML = one.textContent;
  1539. } else {
  1540. toElement.insertAdjacentElement(addTo1, one); // 继续插入网页主体元素
  1541. }
  1542. });
  1543. } else if (curSite.SiteTypeID != SiteType.BAIDU_TIEBA) {
  1544. pageElems.forEach(function (one) {toElement.insertAdjacentElement(addTo1, one);});
  1545. }
  1546.  
  1547. // 对于 <script> 需要用另一种方式插入网页,以便正常运行
  1548. if (curSite.SiteTypeID === SiteType.GOOGLE) {
  1549. const scriptElems = getAllElements('//script', newBody, newBody);
  1550. let scriptText = '';
  1551. scriptElems.forEach(function (one) {scriptText += one.innerHTML;});
  1552. toElement.appendChild(document.createElement('script')).innerHTML = scriptText;
  1553. }
  1554.  
  1555. // 对于百度贴吧这种动态加载内容的网站需要单独处理
  1556. if (curSite.SiteTypeID === SiteType.BAIDU_TIEBA) {
  1557. const scriptElems = getAllElements('//script', newBody, newBody);
  1558. let scriptText = '';
  1559. for (let i = 0; i < scriptElems.length; i++) {
  1560. if (scriptElems[i].textContent.indexOf('Bigpipe.register("frs-list/pagelet/thread_list"') > -1) {
  1561. scriptText = scriptElems[i].textContent.replace('Bigpipe.register("frs-list/pagelet/thread_list", ','');
  1562. break
  1563. }
  1564. }
  1565. if (scriptText) {
  1566. scriptText = scriptText.slice(0, scriptText.indexOf(').')) // 获取主体内容
  1567. let scriptJSON = JSON.parse(scriptText).content; // 字符串转 JSON
  1568. var temp_baidu_tieba = document.createElement('div'); temp_baidu_tieba.innerHTML = scriptJSON; // 字符串转 Element 元素
  1569. pageElems = curSite.function.before(getAllElements(curSite.pager.pageElement, temp_baidu_tieba, temp_baidu_tieba)); // 插入前执行函数
  1570. pageElems.forEach(function (one) {toElement.insertAdjacentElement(addTo1, one);}); // 插入元素
  1571. }
  1572. //toElement.appendChild(document.createElement('script')).innerHTML = scriptText;
  1573. }
  1574.  
  1575. // 替换待替换元素
  1576. try {
  1577. let oriE = getAllElements(curSite.pager.replaceE), repE;
  1578. if (curSite.SiteTypeID === SiteType.BAIDU_TIEBA) {
  1579. repE = getAllElements(curSite.pager.replaceE, temp_baidu_tieba, temp_baidu_tieba);
  1580. } else {
  1581. repE = getAllElements(curSite.pager.replaceE, newBody, newBody);
  1582. }
  1583. if (oriE.length === repE.length) {
  1584. for (let i = 0; i < oriE.length; i++) {
  1585. oriE[i].outerHTML = repE[i].outerHTML;
  1586. }
  1587. }
  1588. } catch (e) {
  1589. console.log(e);
  1590. }
  1591. // 如果有插入后函数就执行函数
  1592. if (curSite.function && curSite.function.after) {
  1593. if (curSite.function.parameter) { // 如果指定了参数
  1594. curSite.function.after(curSite.function.parameter);
  1595. }else{
  1596. curSite.function.after();
  1597. }
  1598. }
  1599. }
  1600. } catch (e) {
  1601. console.log(e);
  1602. }
  1603. }
  1604. });
  1605. }
  1606. },
  1607. };
  1608.  
  1609. function getElementByCSS(css, contextNode = document) {
  1610. return contextNode.querySelector(css);
  1611. }
  1612. function getAllElementsByCSS(css, contextNode = document) {
  1613. return [].slice.call(contextNode.querySelectorAll(css));
  1614. }
  1615. function getElementByXpath(xpath, contextNode, doc = document) {
  1616. contextNode = contextNode || doc;
  1617. try {
  1618. const result = doc.evaluate(xpath, contextNode, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
  1619. // 应该总是返回一个元素节点
  1620. return result.singleNodeValue && result.singleNodeValue.nodeType === 1 && result.singleNodeValue;
  1621. } catch (err) {
  1622. throw new Error(`Invalid xpath: ${xpath}`);
  1623. }
  1624. }
  1625. function getAllElementsByXpath(xpath, contextNode, doc = document) {
  1626. contextNode = contextNode || doc;
  1627. const result = [];
  1628. try {
  1629. const query = doc.evaluate(xpath, contextNode, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
  1630. for (let i = 0; i < query.snapshotLength; i++) {
  1631. const node = query.snapshotItem(i);
  1632. // 如果是 Element 节点
  1633. if (node.nodeType === 1) result.push(node);
  1634. }
  1635. } catch (err) {
  1636. throw new Error(`无效 Xpath: ${xpath}`);
  1637. }
  1638. return result;
  1639. }
  1640. function getAllElements(selector, contextNode = undefined, doc = document, win = window, _cplink = undefined) {
  1641. if (!selector) return [];
  1642. contextNode = contextNode || doc;
  1643. if (typeof selector === 'string') {
  1644. if (selector.search(/^css;/i) === 0) {
  1645. return getAllElementsByCSS(selector.slice(4), contextNode);
  1646. } else {
  1647. return getAllElementsByXpath(selector, contextNode, doc);
  1648. }
  1649. } else {
  1650. const query = selector(doc, win, _cplink);
  1651. if (!Array.isArray(query)) {
  1652. throw new Error('getAllElements 返回错误类型');
  1653. } else {
  1654. return query;
  1655. }
  1656. }
  1657. }
  1658. })();