自动无缝翻页

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

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

  1. // ==UserScript==
  2. // @name 自动无缝翻页
  3. // @version 1.6.9
  4. // @author X.I.U
  5. // @description 无缝拼接下一页内容,目前支持:[所有使用「Discuz!、Flarum、DUX(WordPress)」的网站]、百度、谷歌、必应、贴吧、豆瓣、微博、千图网、Pixabay、3DM、游侠网、游民星空、Steam 创意工坊、423Down、Sordum、不死鸟、小众软件、六音软件、微当下载、异次元软件、老殁殁漂遥、异星软件空间、动漫狂、漫画DB、HiComic(嗨漫画)、古风漫画网、砂之船动漫家、高清电台、RARBG、PubMed、AfreecaTV、GreasyFork、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.cartoonmad.cc', 'www.manhuadb.com', 'www.hicomic.net', 'www.gufengmh8.com', 'www.szcdmj.com',
  31. 'gaoqing.fm',
  32. 'rarbgprx.org', 'pubmed.ncbi.nlm.nih.gov', 'www.afreecatv.com', 'greasyfork.org',
  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 || location.host === 'cs.rin.ru') {
  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. insertPosition:
  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. insertPosition: ['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. insertPosition: ['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. insertPosition: ['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. insertPosition: ['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. insertPosition: ['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. insertPosition: ['css;.content > .pagination', 1],
  167. replaceE: 'css;.content > .pagination',
  168. scrollDelta: 1500
  169. },
  170. function: {
  171. before: dux_functionBefore
  172. }
  173. },
  174. baidu: {
  175. SiteTypeID: 0,
  176. pager: {
  177. type: 1,
  178. nextLink: 'id("page")//a[contains(text(),"下一页")][@href]',
  179. pageElement: 'css;#content_left > *',
  180. insertPosition: ['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: 'id("pnnext")[@href]',
  190. pageElement: 'css;#res > *',
  191. insertPosition: ['css;#res', 3],
  192. replaceE: 'id("navcnt") | id("rcnt")//div[@role="navigation"]',
  193. scrollDelta: 2000
  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. insertPosition: ['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. insertPosition: ['css;#thread_list', 3],
  214. replaceE: 'css;#frs_list_pager',
  215. scrollDelta: 1500
  216. },
  217. function: {
  218. before: baidu_tieba_functionBefore
  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. insertPosition: ['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. insertPosition: ['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. insertPosition: ['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. insertPosition: ['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. insertPosition: ['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. insertPosition: ['css;.pic-box', 3],
  292. replaceE: 'css;.page-box',
  293. scrollDelta: 2000
  294. },
  295. function: {
  296. before: _58pic_functionBefore
  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. insertPosition: ['css;.list-box', 3],
  306. replaceE: 'css;.page-box',
  307. scrollDelta: 4000
  308. },
  309. function: {
  310. before: _58pic_functionBefore
  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. insertPosition: ['css;[class^="results"] > [class^="container"]', 3],
  320. replaceE: '//a[text()="Next page"][@href]',
  321. scrollDelta: 2000
  322. },
  323. function: {
  324. before: pixabay_functionBefore
  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. insertPosition: ['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: 'id("after_this_page")[@href]',
  344. pageElement: 'css;#Content >*:not(.news_ding):not(.page_fenye)',
  345. insertPosition: ['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. insertPosition: ['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. insertPosition: ['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. insertPosition: ['css;.gs_nc_editor', 1],
  382. replaceE: 'css;.page_css',
  383. scrollElement: '.pagecss',
  384. scrollDelta: -1000
  385. },
  386. function: {
  387. before: gamersky_gl_functionBefore
  388. }
  389. },
  390. steamcommunity: {
  391. SiteTypeID: 0,
  392. pager: {
  393. type: 1,
  394. nextLink: '//a[@class="pagebtn"][last()][@href]',
  395. pageElement: 'css;.workshopBrowseItems > *',
  396. insertPosition: ['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. insertPosition: ['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. insertPosition: ['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. insertPosition: ['css;ol.page-navigator', 1],
  430. replaceE: 'css;ol.page-navigator',
  431. scrollDelta: 800
  432. },
  433. function: {
  434. before: iao_su_functionBefore
  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. insertPosition: ['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. insertPosition: ['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. insertPosition: ['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. insertPosition: ['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. insertPosition: ['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. insertPosition: ['css;#postlist > .pagenavi-button', 1],
  508. replaceE: 'css;.pagenavi-button, .pagenavi',
  509. scrollDelta: 1200
  510. },
  511. function: {
  512. before: iplaysoft_postslist_functionBefore
  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. insertPosition: ['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. insertPosition: ['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. insertPosition: ['css;.td-modules-container.td-module-number4', 3],
  553. replaceE: 'css;.page-nav.td-pb-padding-side',
  554. scrollDelta: 1000
  555. }
  556. },
  557. cartoonmad: {
  558. SiteTypeID: 0,
  559. pager: {
  560. type: 1,
  561. nextLink: cartoonmad_functionNext,
  562. pageElement: 'css;body > table > tbody > tr:nth-child(4) > td > table > tbody > tr:first-child > td:first-child img',
  563. insertPosition: ['css;body > table > tbody > tr:nth-child(4) > td > table > tbody > tr:first-child > td:first-child > a', 3],
  564. replaceE: 'css;body > table > tbody > tr:nth-child(2), body > table > tbody > tr:nth-child(5)',
  565. scrollDelta: 2000
  566. }
  567. },
  568. manhuadb: {
  569. SiteTypeID: 0,
  570. pager: {
  571. type: 4,
  572. nextLink: manhuadb_functionNext,
  573. pageElement: 'css;body > script:not([type]):not([src]), .vg-r-data, ol.links-of-books.num_div',
  574. insertPosition: ['css;.pjax-container', 3],
  575. insertElement: manhuadb_insertElement,
  576. intervals: 5000,
  577. scrollDelta: 3000
  578. }
  579. },
  580. hicomic: {
  581. SiteTypeID: 0,
  582. pager: {
  583. type: 4,
  584. nextLink: hicomic_functionNext,
  585. insertPosition: ['css;.content', 3],
  586. insertElement: hicomic_insertElement,
  587. intervals: 5000,
  588. scrollDelta: 3000
  589. }
  590. },
  591. gufengmh8: {
  592. SiteTypeID: 0,
  593. pager: {
  594. type: 4,
  595. nextLink: gufengmh8_functionNext,
  596. pageElement: 'css;body > script:first-child',
  597. insertPosition: ['css;#images', 3],
  598. insertElement: gufengmh8_insertElement,
  599. intervals: 5000,
  600. scrollDelta: 4000
  601. }
  602. },
  603. szcdmj: {
  604. SiteTypeID: 0,
  605. pager: {
  606. type: 1,
  607. nextLink: '//div[@class="fanye"][1]/a[@href][text()="下一页" or text()="下一话"]',
  608. pageElement: 'css;.comicpage > div,title',
  609. insertPosition: ['css;.comicpage', 3],
  610. replaceE: 'css;.fanye,h1.title',
  611. scrollDelta: 2000
  612. },
  613. function: {
  614. before: szcdmj_functionBefore
  615. }
  616. },
  617. gaoqing_fm: {
  618. SiteTypeID: 0,
  619. pager: {
  620. type: 2,
  621. nextLink: '.col-md-12 > a[href], #loadmore > a[href]',
  622. intervals: 1500,
  623. scrollDelta: 1000
  624. }
  625. },
  626. rarbgprx: {
  627. SiteTypeID: 0,
  628. pager: {
  629. type: 1,
  630. nextLink: '(//a[@title="next page"])[1][@href]',
  631. pageElement: 'css;table.lista2t tr.lista2',
  632. insertPosition: ['css;table.lista2t > tbody', 3],
  633. replaceE: 'css;#pager_links',
  634. scrollDelta: 900
  635. }
  636. },
  637. pubmed_postslist: {
  638. SiteTypeID: 0,
  639. pager: {
  640. type: 2,
  641. nextLink: 'button.load-button.next-page',
  642. nextText: 'Show more',
  643. scrollDelta: 1500
  644. }
  645. },
  646. afreecatv: {
  647. SiteTypeID: 0,
  648. pager: {
  649. type: 2,
  650. nextLink: '.btn-more > button',
  651. intervals: 2000,
  652. scrollDelta: 1000
  653. }
  654. },
  655. greasyfork: {
  656. SiteTypeID: 0,
  657. pager: {
  658. type: 1,
  659. nextLink: '//a[@class="next_page"][@href]',
  660. pageElement: 'css;ol#browse-script-list > li',
  661. insertPosition: ['css;ol#browse-script-list', 3],
  662. replaceE: 'css;.pagination',
  663. scrollDelta: 1000
  664. }
  665. },
  666. greasyfork_feedback: {
  667. SiteTypeID: 0,
  668. pager: {
  669. type: 1,
  670. nextLink: '//a[@class="next_page"][@href]',
  671. pageElement: 'css;.script-discussion-list > div',
  672. insertPosition: ['css;.script-discussion-list', 3],
  673. replaceE: 'css;.pagination',
  674. scrollDelta: 1500
  675. }
  676. },
  677. greasyfork_discussions: {
  678. SiteTypeID: 0,
  679. pager: {
  680. type: 1,
  681. nextLink: '//a[@class="next_page"][@href]',
  682. pageElement: 'css;.discussion-list > div',
  683. insertPosition: ['css;.discussion-list', 3],
  684. replaceE: 'css;.pagination',
  685. scrollDelta: 1000
  686. }
  687. },
  688. cs_rin_ru: {
  689. SiteTypeID: 0,
  690. pager: {
  691. type: 1,
  692. nextLink: '//td[@class="gensmall"][@align="right"]//a[text()="Next"][@href]',
  693. pageElement: 'css;#pagecontent > table.tablebg > tbody > tr:not([align])',
  694. insertPosition: ['css;#pagecontent > table.tablebg > tbody > tr[align]', 1],
  695. replaceE: 'css;#pagecontent > table:first-child',
  696. scrollDelta: 1500
  697. },
  698. function: {
  699. before: cs_rin_ru_functionBefore
  700. }
  701. },
  702. cs_rin_ru_viewtopic: {
  703. SiteTypeID: 0,
  704. pager: {
  705. type: 1,
  706. nextLink: 'id("pageheader")/p[@class="gensmall"]//a[text()="Next"][@href]',
  707. pageElement: 'css;#pagecontent > table.tablebg:not(:nth-last-child(2)):not(:nth-child(2))',
  708. insertPosition: ['css;#pagecontent > table.tablebg:nth-last-child(2)', 1],
  709. replaceE: 'css;#pagecontent >table:not(.tablebg), #pageheader p.gensmall',
  710. scrollDelta: 1500
  711. }
  712. },
  713. cs_rin_ru_search: {
  714. SiteTypeID: 0,
  715. pager: {
  716. type: 1,
  717. nextLink: 'id("wrapcentre")/div[@class="nav"]//a[text()="Next"]',
  718. pageElement: 'css;#wrapcentre > form > table.tablebg > tbody > tr[valign]',
  719. insertPosition: ['css;#wrapcentre > form > table.tablebg > tbody > tr:last-child', 1],
  720. replaceE: 'css;#wrapcentre > div',
  721. scrollDelta: 1500
  722. }
  723. },
  724. fitgirl: {
  725. SiteTypeID: 0,
  726. pager: {
  727. type: 1,
  728. nextLink: '//a[@class="next page-numbers"][@href]',
  729. pageElement: 'css;article[id^="post-"]',
  730. insertPosition: ['css;nav.paging-navigation', 1],
  731. replaceE: 'css;nav.paging-navigation',
  732. scrollDelta: 2000
  733. }
  734. }
  735. };
  736. // 生成 SiteTypeID
  737. generateID();
  738.  
  739. // 用于脚本判断(针对部分特殊的网站)
  740. const SiteType = {
  741. GOOGLE: DBSite.google.SiteTypeID,
  742. BAIDU_TIEBA: DBSite.baidu_tieba.SiteTypeID,
  743. GAMERSKY_GL: DBSite.gamersky_gl.SiteTypeID,
  744. STEAMCOMMUNITY: DBSite.steamcommunity.SiteTypeID,
  745. CARTONNMAD: DBSite.cartoonmad.SiteTypeID
  746. };
  747.  
  748.  
  749. // < 其他网站 >
  750. if (webType === 1) {
  751. switch (location.host) {
  752. case 'www.baidu.com': // < 百度搜索 >
  753. curSite = DBSite.baidu;
  754. break;
  755. case 'www.google.com': // < 谷歌搜索 >
  756. if (location.pathname === '/search') curSite = DBSite.google;
  757. break;
  758. case 'www.bing.com': // < 必应搜索 >
  759. case 'cn.bing.com':
  760. if (location.pathname === '/search') {curSite = DBSite.bing; document.lastElementChild.appendChild(document.createElement('style')).textContent = '.b_imagePair.square_mp > .inner {display: none;}';}
  761. break;
  762. case 'tieba.baidu.com': // < 百度贴吧 >
  763. if (location.pathname === '/f') { // 帖子列表
  764. baidu_tieba_1(); // 右侧悬浮发帖按钮点击事件(解决自动翻页导致无法发帖的问题)
  765. curSite = DBSite.baidu_tieba; document.lastElementChild.appendChild(document.createElement('style')).textContent = 'img.j_retract {margin-top: 0 !important;margin-bottom: 0 !important;}'; // 修复帖子列表中预览图片,在切换下一个/上一个图片时,多出来的图片上下边距
  766. //} else if (location.pathname.indexOf('/p/') > -1) { // 帖子内
  767. // curSite = DBSite.baidu_tieba_post;
  768. } else if (location.pathname === '/f/search/res') { // 吧内搜索/全吧搜索
  769. curSite = DBSite.baidu_tieba_search;
  770. }
  771. break;
  772. case 'movie.douban.com': // < 豆瓣评论 >
  773. if (location.pathname.indexOf('/subject') > -1 && location.pathname.indexOf('/comments') > -1) { // 短评列表
  774. curSite = DBSite.douban_subject_comments;
  775. } else if (location.pathname.indexOf('/subject') > -1 && location.pathname.indexOf('/reviews') > -1) { // 影评列表
  776. curSite = DBSite.douban_subject_reviews;
  777. } else if(location.pathname.indexOf('/subject') > -1 && location.pathname.indexOf('/episode') > -1) { // 电视剧每集评论
  778. curSite = DBSite.douban_subject_episode;
  779. }
  780. break;
  781. case 'weibo.com': // < 微博评论 >
  782. curSite = DBSite.weibo_comment;
  783. break;
  784. case 'www.58pic.com': // < 千图网 >
  785. if (location.pathname.indexOf('/tupian/') > -1) {
  786. curSite = DBSite._58pic; document.lastElementChild.appendChild(document.createElement('style')).textContent = '.qtw-card.place-box.is-two {display: none !important;}'; // 隐藏末尾很大的 [下一页] 按钮
  787. } else if (location.pathname.indexOf('/c/') > -1) {
  788. curSite = DBSite._58pic_c;
  789. }
  790. break;
  791. case 'pixabay.com': // < Pixabay >
  792. curSite = DBSite.pixabay;
  793. break;
  794. case 'www.3dmgame.com': // < 3DM >
  795. curSite = DBSite._3dmgame;
  796. break;
  797. case 'www.ali213.net': // < 游侠网 >
  798. curSite = DBSite.ali213_www;
  799. break;
  800. case 'gl.ali213.net': // < 游侠网 - 攻略页 >
  801. curSite = DBSite.ali213_gl; document.lastElementChild.appendChild(document.createElement('style')).textContent = '.n_show_b {display: none !important;}'; // 隐藏部分碍事元素
  802. break;
  803. case 'www.gamersky.com': // < 游民星空 >
  804. if (location.pathname.indexOf('/ent/') > -1) {
  805. curSite = DBSite.gamersky_ent;
  806. } else {
  807. curSite = DBSite.gamersky_gl;
  808. }
  809. break;
  810. case 'steamcommunity.com': // < Steam 创意工坊 >
  811. curSite = DBSite.steamcommunity;
  812. break;
  813. case 'www.423down.com': // < 423down >
  814. if (location.pathname.indexOf('.html') === -1) curSite = DBSite._423down;
  815. break;
  816. case 'www.sordum.org': // < Sordum >
  817. curSite = DBSite.sordum;
  818. break;
  819. case 'iao.su': // < 不死鸟 >
  820. curSite = DBSite.iao_su;
  821. break;
  822. case 'www.appinn.com': // < 小众软件 >
  823. curSite = DBSite.appinn;
  824. break;
  825. case 'www.sixyin.com': // < 六音软件 >
  826. if (location.pathname === '/' && location.search === '') { // 首页
  827. curSite = DBSite.sixyin;
  828. } else if (location.pathname.indexOf('.html') === -1) { // 分类页
  829. curSite = DBSite.sixyin_postlist;
  830. }
  831. break;
  832. case 'www.weidown.com': // < 微当下载 >
  833. if (location.pathname.indexOf('/search/') > -1) {
  834. curSite = DBSite.weidown_search;
  835. } else if (location.pathname.indexOf('/special/') > -1) {
  836. curSite = DBSite.weidown_special;
  837. } else {
  838. curSite = DBSite.weidown;
  839. }
  840. break;
  841. case 'www.iplaysoft.com': // < 异次元软件 >
  842. if (location.pathname.indexOf('.html') > -1 || location.pathname.indexOf('/p/') > -1) { // 文章内
  843. curSite = DBSite.iplaysoft_postcomments;
  844. } else { // 其他页面
  845. curSite = DBSite.iplaysoft_postslist;
  846. }
  847. break;
  848. case 'www.mpyit.com': // < 老殁殁漂遥 >
  849. if (location.pathname === '/' && !location.search) {
  850. curSite = DBSite.mpyit;
  851. } else if (location.pathname.indexOf('/category/') > -1 || location.search.indexOf('?s=') > -1) {
  852. curSite = DBSite.mpyit_category;
  853. }
  854. break;
  855. case 'www.yxssp.com': // < 异星软件空间 >
  856. curSite = DBSite.yxssp;
  857. break;
  858. case 'www.cartoonmad.cc': // < 漫画狂 >
  859. if (location.pathname.indexOf('/comic/') > -1) {
  860. document.lastElementChild.appendChild(document.createElement('style')).textContent = 'body > table > tbody > tr:nth-child(4) > td > table > tbody > tr:first-child > td:not(:first-child) {display: none !important;} body > table > tbody > tr:nth-child(4) > td > table > tbody > tr:first-child > td:first-child img {max-width: 100%;height: auto;display: block !important;margin: 0 auto !important;}';
  861. document.querySelector('body > table > tbody > tr:nth-child(4) > td > table > tbody > tr:first-child > td:first-child > a').href = 'javascript:void(0);'; // 清理图片上的链接
  862. curSite = DBSite.cartoonmad;
  863. }
  864. break;
  865. case 'www.manhuadb.com': // < 漫画DB >
  866. if (location.pathname.indexOf('/manhua/') > -1 && location.pathname.indexOf('.html') > -1) {
  867. 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;}';
  868. document.querySelector('img.img-fluid.show-pic').style.display = 'none'; // 隐藏第一个图片(避免重复)
  869. setTimeout(manhuadb_init, 100);
  870. curSite = DBSite.manhuadb;
  871. }
  872. break;
  873. case 'www.hicomic.net': // < HiComic(嗨漫画) >
  874. if (location.pathname.indexOf('/chapters/') > -1) {
  875. 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;}';
  876. setTimeout(hicomic_init, 100);
  877. curSite = DBSite.hicomic;
  878. }
  879. break;
  880. case 'www.gufengmh8.com': // < 古风漫画网 >
  881. if (location.pathname.indexOf('.html') > -1) {
  882. let chapterScroll = document.getElementById('chapter-scroll') // 强制为 [下拉阅读] 模式
  883. if (chapterScroll && chapterScroll.className === '') {chapterScroll.click();}
  884. curSite = DBSite.gufengmh8; document.lastElementChild.appendChild(document.createElement('style')).textContent = 'p.img_info {display: none !important;}'; // 隐藏中间的页数信息
  885. }
  886. break;
  887. case 'www.szcdmj.com': // < 砂之船动漫家 >
  888. if (location.pathname.indexOf('/szcchapter/') > -1) curSite = DBSite.szcdmj;
  889. break;
  890. case 'gaoqing.fm': // < 高清电台 >
  891. curSite = DBSite.gaoqing_fm;
  892. break;
  893. case 'rarbgprx.org': // < RARBG >
  894. curSite = DBSite.rarbgprx;
  895. break;
  896. case 'pubmed.ncbi.nlm.nih.gov': // < 国外学术网站 >
  897. curSite = DBSite.pubmed_postslist;
  898. break;
  899. case 'www.afreecatv.com': // < 直播网站 >
  900. curSite = DBSite.afreecatv;
  901. break;
  902. case 'greasyfork.org': // < GreasyFork >
  903. if (location.pathname.indexOf('/scripts') + 8 === location.pathname.length) {
  904. curSite = DBSite.greasyfork;
  905. } else if (location.pathname.lastIndexOf('/feedback') + 9 === location.pathname.length) {
  906. curSite = DBSite.greasyfork_feedback;
  907. } else if (location.pathname.lastIndexOf('/discussions') + 12 === location.pathname.length) {
  908. curSite = DBSite.greasyfork_discussions;
  909. }
  910. break;
  911. case 'cs.rin.ru': // < 游戏下载论坛 >
  912. if (location.pathname === '/forum/viewforum.php') { // 版块帖子列表
  913. curSite = DBSite.cs_rin_ru;
  914. } else if (location.pathname === '/forum/viewtopic.php') { // 帖子内
  915. if (GM_getValue('menu_discuz_thread_page')) curSite = DBSite.cs_rin_ru_viewtopic;
  916. } else if (location.pathname === '/forum/search.php') { // 搜索结果
  917. curSite = DBSite.cs_rin_ru_search;
  918. }
  919. break;
  920. case 'crackhub.site': // < 游戏下载网站 >
  921. curSite = DBSite.fitgirl; document.lastElementChild.appendChild(document.createElement('style')).textContent = 'html.wp-dark-mode-active .inside-article {background-color: var(--wp-dark-mode-bg);}'
  922. break;
  923. case 'fitgirl-repacks.site': // < 游戏下载网站 >
  924. curSite = DBSite.fitgirl;
  925. break;
  926. }
  927. // < 所有 Discuz!论坛 >
  928. } else if (webType === 2) {
  929. if (location.pathname.indexOf('.html') > -1) { // 判断是不是静态网页(.html 结尾)
  930. if (location.pathname.indexOf('/forum-') > -1) { // 各版块帖子列表
  931. if (document.getElementById('autopbn')) { // 判断是否有 [下一页] 按钮
  932. curSite = DBSite.discuz_forum;
  933. } else {
  934. curSite = DBSite.discuz_guide;
  935. }
  936. } else if (location.pathname.indexOf('/thread-') > -1) { // 帖子内
  937. if (GM_getValue('menu_discuz_thread_page')) {
  938. curSite = DBSite.discuz_thread;
  939. hidePgbtn(); // 隐藏帖子内的 [下一页] 按钮
  940. }
  941. } else if(location.pathname.indexOf('search') > -1) { // 搜索结果
  942. curSite = DBSite.discuz_search;
  943. }
  944. } else {
  945. if (location.search.indexOf('mod=forumdisplay') > -1) { // 各版块帖子列表
  946. if (document.getElementById('autopbn')) { // 判断是否有 [下一页] 按钮
  947. curSite = DBSite.discuz_forum;
  948. } else {
  949. curSite = DBSite.discuz_guide;
  950. }
  951. } else if (location.search.indexOf('mod=viewthread') > -1) { // 帖子内
  952. if (GM_getValue('menu_discuz_thread_page')) {
  953. curSite = DBSite.discuz_thread;
  954. hidePgbtn(); // 隐藏帖子内的 [下一页] 按钮
  955. }
  956. } else if (location.search.indexOf('mod=guide') > -1) { // 导读帖子列表
  957. curSite = DBSite.discuz_guide;
  958. } else if(location.search.indexOf('mod=space') > -1 && location.search.indexOf('&view=me') > -1) { // 别人的主题/回复
  959. curSite = DBSite.discuz_youspace;
  960. } else if (location.search.indexOf('mod=collection') > -1) { // 淘贴列表
  961. curSite = DBSite.discuz_collection;
  962. } else if (location.pathname.indexOf('search') > -1) { // 搜索结果
  963. curSite = DBSite.discuz_search;
  964. } else { // 考虑到部分论坛的部分板块帖子列表 URL 是自定义的
  965. curSite = DBSite.discuz_forum;
  966. }
  967. }
  968. // < 所有 Flarum 论坛 >
  969. } else if (webType === 3) {
  970. curSite = DBSite.flarum;
  971. // < 所有使用 WordPress DUX 主题的网站 >
  972. } else if (webType === 4) {
  973. if (location.pathname.indexOf('.html') === -1) curSite = DBSite.dux;
  974. if (location.host === 'apphot.cc') curSite.pager.scrollDelta = 2500; // 对于速度慢的网站,需要增加翻页敏感度
  975. }
  976.  
  977. pausePageEvent(); // 左键双击网页空白处暂停翻页
  978. curSite.pageUrl = ''; // 下一页URL
  979. //console.log(curSite);
  980. pageLoading(); // 自动无缝翻页
  981.  
  982.  
  983. // 隐藏帖子内的 [下一页] 按钮(Discuz! 论坛)
  984. function hidePgbtn() {
  985. document.lastChild.appendChild(document.createElement('style')).textContent = '.pgbtn {display: none;}';
  986. }
  987.  
  988.  
  989. // dux 的插入前函数(加载图片)
  990. function dux_functionBefore(pageElems) {
  991. pageElems.forEach(function (one) {
  992. let now = one.querySelector('img.thumb[data-src]')
  993. if (now) {now.src = now.dataset.src;}
  994. });
  995. return pageElems
  996. }
  997.  
  998.  
  999. // 百度贴吧(发帖按钮点击事件)
  1000. function baidu_tieba_1() {
  1001. let button = document.querySelector('.tbui_aside_fbar_button.tbui_fbar_post > a');
  1002. if (button) {
  1003. button.remove();
  1004. 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>')
  1005. button = document.querySelector('.tbui_aside_fbar_button.tbui_fbar_post > a');
  1006. if (button) {
  1007. button.onclick = function(){
  1008. let button2 = document.querySelector('div.edui-btn.edui-btn-fullscreen.edui-btn-name-portrait');
  1009. if (button2) {
  1010. button2.click();
  1011. } else {
  1012. alert('提示:登录后才能发帖!');
  1013. }
  1014. return false;
  1015. }
  1016. }
  1017. }
  1018. }
  1019.  
  1020.  
  1021. // 百度贴吧 的插入前函数(加载图片)
  1022. function baidu_tieba_functionBefore(pageElems) {
  1023. pageElems.forEach(function (one) {
  1024. one.querySelectorAll('img.threadlist_pic[data-original]').forEach(function (now) {
  1025. now.src = now.dataset.original;
  1026. now.style.display = 'inline';
  1027. })
  1028. });
  1029. return pageElems
  1030. }
  1031.  
  1032.  
  1033. // 58pic 的插入前函数(加载图片)
  1034. function _58pic_functionBefore(pageElems) {
  1035. let is_one = document.querySelector('.qtw-card.place-box.is-one');
  1036. if (is_one && is_one.style.display != 'none') {is_one.style.display = 'none';}
  1037. pageElems.forEach(function (one) {
  1038. let now = one.querySelector('img.lazy')
  1039. if (now && now.getAttribute('src') != now.dataset.original) {
  1040. now.src = now.dataset.original;
  1041. now.style.display = 'block';
  1042. }
  1043. });
  1044. return pageElems
  1045. }
  1046.  
  1047.  
  1048. // Pixabay 的插入前函数(加载图片)
  1049. function pixabay_functionBefore(pageElems) {
  1050. pageElems.forEach(function (one) {
  1051. let now = one.querySelector('img[data-lazy-src]')
  1052. if (now) {
  1053. now.src = now.dataset.lazySrc;
  1054. now.removeAttribute('data-lazy-src')
  1055. now.removeAttribute('data-lazy-srcset')
  1056. }
  1057. });
  1058. return pageElems
  1059. }
  1060.  
  1061.  
  1062. // 游民星空攻略 的插入前函数(移除下一页底部的 "更多相关内容请关注:xxx" 文字)
  1063. function gamersky_gl_functionBefore(pageElems) {
  1064. pageElems.forEach(function (one) {
  1065. if (one.tagName === 'P' && one.textContent.indexOf('更多相关内容请关注') > -1) {one.style.display = 'none';}
  1066. });
  1067. return pageElems
  1068. }
  1069.  
  1070.  
  1071. // iao.su 的插入前函数(加载图片)
  1072. function iao_su_functionBefore(pageElems) {
  1073. pageElems.forEach(function (one) {
  1074. let now = one.getElementsByClassName('post-card')[0]
  1075. if (now) {
  1076. now.getElementsByClassName('blog-background')[0].style.backgroundImage = 'url("' + now.getElementsByTagName('script')[0].textContent.split("'")[1] + '")';
  1077. //now.getElementsByClassName('blog-background')[0].style.backgroundImage = 'url("' + RegExp("(?<=loadBannerDirect\\(').*(?=', '',)").exec(now.getElementsByTagName('script')[0].textContent)[0]; + '")';
  1078. }
  1079. });
  1080. return pageElems
  1081. }
  1082.  
  1083.  
  1084. // iplaysoft 的插入前函数(加载图片)
  1085. function iplaysoft_postslist_functionBefore(pageElems) {
  1086. pageElems.forEach(function (one) {
  1087. let now = one.querySelector('img.lazyload')
  1088. if (now && !now.src) {
  1089. now.src = now.dataset.src;
  1090. now.setAttribute('srcset', now.dataset.src)
  1091. now.setAttribute('class', 'lazyloaded')
  1092. }
  1093. });
  1094. return pageElems
  1095. }
  1096.  
  1097.  
  1098. // cs_rin_ru 各版块帖子列表的插入前函数(过滤置顶帖子)
  1099. function cs_rin_ru_functionBefore(pageElems) {
  1100. for (let i = 0; i < pageElems.length; i++) {
  1101. if (pageElems[i].textContent.replace(/\n| /g,'') === 'Topics') {
  1102. pageElems.splice(0,i+1);
  1103. break;
  1104. }
  1105. }
  1106. return pageElems
  1107. }
  1108.  
  1109.  
  1110. // 漫画狂 获取下一页地址
  1111. function cartoonmad_functionNext() {
  1112. let nextXPAHT = '//a[@class="pages"][contains(text(),"下一頁")]',
  1113. nextPXPATH = '//a[@class="pages"][contains(string(),"下一話")]'
  1114. let url = getElementByXpath(nextXPAHT);
  1115. if (url) {
  1116. if (url.getAttribute('href') === 'thend.asp') {
  1117. return getElementByXpath(nextPXPATH).href;
  1118. } else {
  1119. return url.href;
  1120. }
  1121. }
  1122. return '';
  1123. }
  1124.  
  1125.  
  1126. // manhuadb 初始化(将本话其余图片插入网页中)
  1127. function manhuadb_init() {
  1128. let _img = '',
  1129. data = document.querySelector('.vg-r-data'), imgDate;
  1130. if (!data) return
  1131. document.querySelectorAll(curSite.pager.pageElement.replace('css;', '')).forEach(function (one) {
  1132. if (one.tagName === 'SCRIPT' && one.textContent.indexOf('var img_data =') > -1) {
  1133. let json = JSON.parse(window.atob(one.textContent.split("'")[1]));
  1134. if (json) {
  1135. let _img = '';
  1136. for (let i = 0; i < json.length; i++) { // 遍历图片文件名数组,组合为 img 标签
  1137. let src = data.dataset.host + data.dataset.img_pre + json[i].img;
  1138. _img += `<img class="img-fluid show-pic" src="${src}">`
  1139. }
  1140. document.querySelector(curSite.pager.insertPosition[0].replace('css;', '')).insertAdjacentHTML(addTo(curSite.pager.insertPosition[1]), _img); // 将 img 标签插入到网页中
  1141. }
  1142. }
  1143. })
  1144. }
  1145. // manhuadb 获取下一页地址
  1146. function manhuadb_functionNext() {
  1147. let nextArr = document.querySelectorAll('a.fixed-a-es'), next;
  1148. if (nextArr.length == 0) return
  1149. curSite.pageUrl = '';
  1150. for (let i = 0; i < nextArr.length; i++) {
  1151. if (nextArr[i].className.indexOf('active') > -1) {
  1152. if (nextArr[i+1]) curSite.pageUrl = nextArr[i+1].href;
  1153. break;
  1154. }
  1155. }
  1156. if (curSite.pageUrl) getPageElems(curSite.pageUrl);
  1157. }
  1158. // manhuadb 插入数据
  1159. function manhuadb_insertElement(pageElems, type) {
  1160. if (!pageElems) return
  1161. let oriE = document.querySelectorAll(curSite.pager.pageElement.replace('css;', '')),
  1162. repE = getAllElements(curSite.pager.pageElement, pageElems, pageElems);
  1163. if (oriE.length === repE.length) {
  1164. for (let i = 0; i < oriE.length; i++) {
  1165. oriE[i].outerHTML = repE[i].outerHTML;
  1166. }
  1167. manhuadb_init(); // 将刚刚替换的图片插入网页中
  1168. }
  1169. }
  1170.  
  1171.  
  1172. // hicomic 初始化(将本话其余图片插入网页中)
  1173. function hicomic_init() {
  1174. let _img = '';
  1175. document.querySelectorAll('.chapter > section:not(:first-child) > section[val]').forEach(function (one) {
  1176. let src = one.getAttribute('val');
  1177. if (src.indexOf('!p_c_c_') === -1) src += '!p_c_c_h'
  1178. _img += `<img src="${src}">`
  1179. })
  1180. document.querySelector(curSite.pager.insertPosition[0].replace('css;', '')).insertAdjacentHTML(addTo(curSite.pager.insertPosition[1]), _img); // 将 img 标签插入到网页中
  1181. window.document.title = window.document.title.replace(/(\(第.+\))? - HiComic/, `(${document.querySelector('.chapter_name').textContent}) - HiComic`); // 修改网页标题(加上 第 X 话)
  1182. }
  1183. // hicomic 获取下一页地址
  1184. function hicomic_functionNext() {
  1185. let nextId;
  1186. nextId = document.querySelector('.next_chapter:not(.end)')
  1187. if (nextId && nextId.id && nextId.id != 'None') {
  1188. curSite.pageUrl = location.href;
  1189. getPageElems(`https://www.hicomic.net/api/web/chapter/${nextId.id}/contents`, 'json');
  1190. }
  1191. }
  1192. // hicomic 插入数据
  1193. function hicomic_insertElement(pageElems, type) {
  1194. if (!pageElems || pageElems.code != 200) return
  1195. if (pageElems.results.chapter.next) { // 写入下一页的 UUID
  1196. document.querySelector('.next_chapter').id = pageElems.results.chapter.next;
  1197. } else {
  1198. document.querySelector('.next_chapter').id = 'None';
  1199. document.querySelector('.next_chapter').classList.add('end');
  1200. }
  1201. document.querySelector('.chapter_name').textContent = pageElems.results.chapter.name; // 修改漫画标题
  1202. let title = window.document.title.replace(/(\(第.+\))? - HiComic/, `(${pageElems.results.chapter.name}) - HiComic`)
  1203. window.history.pushState(`{title: ${document.title}, url: ${location.href}}`, title, curSite.pageUrl); // 添加历史记录
  1204. window.document.title = title; // 修改当前网页标题为下一话的标题
  1205. let _img = '';
  1206. for (let i = 0; i < pageElems.results.chapter.contents.length; i++) { // 遍历图片文件名数组,组合为 img 标签
  1207. let src = pageElems.results.chapter.contents[i].url;
  1208. if (src.indexOf('!p_c_c_') === -1) src += '!p_c_c_h';
  1209. _img += `<img src="${src}">`
  1210. }
  1211. document.querySelector(curSite.pager.insertPosition[0].replace('css;', '')).insertAdjacentHTML(addTo(curSite.pager.insertPosition[1]), _img); // 将 img 标签插入到网页中
  1212. }
  1213.  
  1214.  
  1215. // gufengmh8 获取下一页地址
  1216. function gufengmh8_functionNext() {
  1217. let pageElems = document.querySelector(curSite.pager.pageElement.replace('css;', '')); // 寻找数据所在元素
  1218. if (pageElems) {
  1219. let comicUrl, nextId;
  1220. pageElems.textContent.split(';').forEach(function (one){ // 分号 ; 分割为数组并遍历
  1221. //console.log(one)
  1222. if (one.indexOf('comicUrl') > -1) { // 下一页 URL 前半部分
  1223. comicUrl = one.split('"')[1];
  1224. } else if (one.indexOf('nextChapterData') > -1) { // 下一页 URL 的后半部分 ID
  1225. nextId = one.split('"id":')[1].split(',')[0];
  1226. }
  1227. })
  1228. if (comicUrl && nextId && nextId != 'null') { // 组合到一起就是下一页 URL
  1229. curSite.pageUrl = comicUrl + nextId + '.html'
  1230. getPageElems(curSite.pageUrl); // 访问下一页 URL 获取
  1231. }
  1232. }
  1233. }
  1234. // gufengmh8 插入数据
  1235. function gufengmh8_insertElement(pageElems, type) {
  1236. if (pageElems) {
  1237. let url = curSite.pageUrl;
  1238. pageElems = getAllElements(curSite.pager.pageElement, pageElems, pageElems)[0];
  1239. let chapterImages, chapterPath;
  1240. document.querySelector(curSite.pager.pageElement.replace('css;', '')).innerText = pageElems.textContent; // 将当前网页内的数据所在元素内容改为刚刚获取的下一页数据内容,以便循环获取下一页 URL
  1241. pageElems.textContent.split(';').forEach(function (one){ // 分号 ; 分割为数组并遍历
  1242. //console.log(one)
  1243. if (one.indexOf('chapterImages') > -1) { // 图片文件名数组
  1244. chapterImages = one.replace(/^.+\[/, '').replace(']', '').replaceAll('"', '').split(',')
  1245. } else if (one.indexOf('chapterPath') > -1) { // 图片文件路径
  1246. chapterPath = one.split('"')[1];
  1247. } else if (one.indexOf('pageTitle') > -1) { // 网页标题
  1248. let title = one.split('"')[1];
  1249. window.history.pushState(`{title: ${document.title}, url: ${location.href}}`, title, url); // 添加历史记录
  1250. window.document.title = title; // 修改当前网页标题为下一页的标题
  1251. }
  1252. })
  1253. if (chapterImages && chapterPath) {
  1254. let _img = '';
  1255. chapterImages.forEach(function (one2){ // 遍历图片文件名数组,组合为 img 标签
  1256. _img += '<img src="https://res.xiaoqinre.com/' + chapterPath + one2 + '" data-index="0" style="display: inline-block;">'
  1257. })
  1258. document.querySelector(curSite.pager.insertPosition[0].replace('css;', '')).insertAdjacentHTML(addTo(curSite.pager.insertPosition[1]), _img); // 将 img 标签插入到网页中
  1259. }
  1260. }
  1261. }
  1262.  
  1263.  
  1264. // szcdmj 的插入前函数(加载图片)
  1265. function szcdmj_functionBefore(pageElems) {
  1266. pageElems.forEach(function (one) {
  1267. if (one.tagName === 'TITLE') {
  1268. let title = one.textContent;
  1269. window.history.pushState(`{title: ${document.title}, url: ${location.href}}`, title, curSite.pageUrl); // 添加历史记录
  1270. window.document.title = title; // 修改当前网页标题为下一页的标题
  1271. one.style.display = 'none';
  1272. } else {
  1273. let now = one.querySelector('img[data-original]')
  1274. if (now) {
  1275. now.src = now.dataset.original;
  1276. now.style.display = 'inline';
  1277. }
  1278. }
  1279. });
  1280. return pageElems
  1281. }
  1282.  
  1283.  
  1284. // 自动无缝翻页
  1285. function pageLoading() {
  1286. if (curSite.SiteTypeID > 0) {
  1287. windowScroll(function (direction, e) {
  1288. if (direction === 'down' && pausePage === true) { // 下滑/没有暂停翻页时,才准备翻页
  1289. let scrollTop = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop,
  1290. scrollHeight = window.innerHeight || document.documentElement.clientHeight,
  1291. scrollDelta = curSite.pager.scrollDelta;
  1292. if (curSite.pager.type === 3) { // <<<<< 翻页类型 3(依靠元素距离可视区域底部的距离来触发翻页)>>>>>
  1293. let scrollElement = document.querySelector(curSite.pager.scrollElement);
  1294. //console.log(scrollElement.offsetTop - (scrollTop + scrollHeight), scrollDelta, curSite.SiteTypeID)
  1295. if (scrollElement.offsetTop - (scrollTop + scrollHeight) <= scrollDelta) {
  1296. if (curSite.SiteTypeID === SiteType.GAMERSKY_GL) curSite.pager.scrollDelta -= 800 // 游民星空 gl 的比较奇葩,需要特殊处理下
  1297. ShowPager.loadMorePage();
  1298. }
  1299. } else {
  1300. if (document.documentElement.scrollHeight <= scrollHeight + scrollTop + scrollDelta) {
  1301. if (curSite.pager.type === 2) { // <<<<< 翻页类型 2(网站自带了自动无缝翻页功能,只需要点击下一页按钮即可)>>>>>
  1302. if (curSite.SiteTypeID > 0) { // 如果指定了间隔时间,那么就依靠这个判断时间到了没有~
  1303. let autopbn = document.querySelector(curSite.pager.nextLink);
  1304. if (autopbn) { // 寻找下一页链接
  1305. if (!curSite.pager.nextText && !curSite.pager.nextTextOf && !curSite.pager.nextHTML) { // 如果没有指定按钮文字就直接点击
  1306. autopbn.click();
  1307. // 对于没有按钮文字变化的按钮,可以手动指定间隔时间
  1308. if (curSite.pager.intervals) {
  1309. let _SiteTypeID = curSite.SiteTypeID; curSite.SiteTypeID = 0;
  1310. setTimeout(function(){curSite.SiteTypeID = _SiteTypeID;}, curSite.pager.intervals)
  1311. }
  1312. } else { // 避免重复点击翻页按钮
  1313. if (curSite.pager.nextText) { // 按钮文本,当按钮文本 = 该文本时,才会点击按钮加载下一页
  1314. if (autopbn.innerText === curSite.pager.nextText) autopbn.click();
  1315. } else if (curSite.pager.nextTextOf) { // 按钮文本的一部分,当按钮文本包含该文本时,才会点击按钮加载下一页
  1316. if (autopbn.innerText.indexOf(curSite.pager.nextTextOf) > -1) autopbn.click();
  1317. } else if (curSite.pager.nextHTML) { // 按钮内元素,当按钮内元素 = 该元素内容时,才会点击按钮加载下一页
  1318. if (autopbn.innerHTML === curSite.pager.nextHTML) autopbn.click();
  1319. }
  1320. }
  1321. }
  1322. }
  1323. } else if (curSite.pager.type === 1) { // <<<<< 翻页类型 1(由脚本实现自动无缝翻页)>>>>>
  1324. // 为百度贴吧的发帖考虑...
  1325. if (!(document.documentElement.scrollHeight <= scrollHeight + scrollTop + 200 && curSite.SiteTypeID === SiteType.BAIDU_TIEBA)) {
  1326. ShowPager.loadMorePage();
  1327. }
  1328. } else if (curSite.pager.type === 4) { // <<<<< 翻页类型 4(部分简单的动态加载类网站)>>>>>
  1329. if (curSite.SiteTypeID > 0) {
  1330. curSite.pager.nextLink();
  1331. if (curSite.pager.intervals) {
  1332. let _SiteTypeID = curSite.SiteTypeID;
  1333. curSite.SiteTypeID = 0;
  1334. setTimeout(function(){curSite.SiteTypeID = _SiteTypeID;}, curSite.pager.intervals)
  1335. }
  1336. }
  1337. }
  1338. }
  1339. }
  1340. }
  1341. });
  1342. }
  1343. }
  1344.  
  1345.  
  1346. // 启用/禁用 (当前网站)
  1347. function menu_disable(type) {
  1348. switch(type) {
  1349. case 'check':
  1350. if(check()) {return true;} else {return false;}; break;
  1351. case 'add':
  1352. add(); break;
  1353. case 'del':
  1354. del(); break;
  1355. }
  1356.  
  1357. function check() { // 存在返回真,不存在返回假
  1358. let list = GM_getValue('menu_disable'); // 读取网站列表
  1359. if (list.indexOf(location.host) === -1) return false // 不存在返回假
  1360. return true
  1361. }
  1362.  
  1363. function add() {
  1364. if (check()) return
  1365. let list = GM_getValue('menu_disable'); // 读取网站列表
  1366. list.push(location.host); // 追加网站域名
  1367. GM_setValue('menu_disable', list); // 写入配置
  1368. location.reload(); // 刷新网页
  1369. }
  1370.  
  1371. function del() {
  1372. if (!check()) return
  1373. let list = GM_getValue('menu_disable'), // 读取网站列表
  1374. index = list.indexOf(location.host);
  1375. list.splice(index, 1); // 删除网站域名
  1376. GM_setValue('menu_disable', list); // 写入配置
  1377. location.reload(); // 刷新网页
  1378. }
  1379. }
  1380.  
  1381.  
  1382. // 左键双击网页空白处暂停翻页
  1383. function pausePageEvent() {
  1384. if (!GM_getValue('menu_pause_page')) return
  1385. if (curSite.SiteTypeID === 0) return
  1386. document.body.addEventListener('dblclick', function (e) {
  1387. if (pausePage) {
  1388. pausePage = false;
  1389. GM_notification({text: `❌ 已暂停本页 [自动无缝翻页]\n (再次双击可恢复)`, timeout: 2500});
  1390. } else {
  1391. pausePage = true;
  1392. GM_notification({text: `✅ 已恢复本页 [自动无缝翻页]\n (再次双击可暂停)`, timeout: 2500});
  1393. }
  1394. });
  1395. }
  1396.  
  1397.  
  1398. // 菜单开关
  1399. function menu_switch(menu_status, Name, Tips) {
  1400. if (menu_status === true){
  1401. GM_setValue(`${Name}`, false);
  1402. } else {
  1403. GM_setValue(`${Name}`, true);
  1404. }
  1405. location.reload();
  1406. };
  1407.  
  1408.  
  1409. // 生成 ID
  1410. function generateID() {
  1411. let num = 0
  1412. for (let val in DBSite) {
  1413. DBSite[val].SiteTypeID = num = num + 1;
  1414. }
  1415. }
  1416.  
  1417.  
  1418. // 类型 4 专用
  1419. function getPageElems(url, type = 'text', method = 'GET', data = '', type2) {
  1420. //console.log(url, data)
  1421. GM_xmlhttpRequest({
  1422. url: url,
  1423. method: method,
  1424. data: data,
  1425. responseType: type,
  1426. headers: {
  1427. 'Content-Type': (method === 'POST') ? 'application/x-www-form-urlencoded':''
  1428. },
  1429. timeout: 5000,
  1430. onload: function (response) {
  1431. try {
  1432. //console.log('最终 URL:' + response.finalUrl, '返回内容:' + response.responseText)
  1433. switch (type) {
  1434. case 'json':
  1435. curSite.pager.insertElement(response.response, type2);
  1436. break;
  1437. default:
  1438. curSite.pager.insertElement(ShowPager.createDocumentByString(response.responseText), type2)
  1439. }
  1440. } catch (e) {
  1441. console.log(e);
  1442. }
  1443. }
  1444. });
  1445. }
  1446.  
  1447.  
  1448. // 插入位置
  1449. function addTo(num) {
  1450. switch (num) {
  1451. case 1:
  1452. return 'beforebegin'; break;
  1453. case 2:
  1454. return 'afterbegin'; break;
  1455. case 3:
  1456. return 'beforeend'; break;
  1457. case 4:
  1458. return 'afterend'; break;
  1459. }
  1460. }
  1461.  
  1462.  
  1463. // 滚动条事件
  1464. function windowScroll(fn1) {
  1465. var beforeScrollTop = document.documentElement.scrollTop || document.body.scrollTop,
  1466. fn = fn1 || function () {};
  1467. setTimeout(function () { // 延时 1 秒执行,避免刚载入到页面就触发翻页事件
  1468. window.addEventListener('scroll', function (e) {
  1469. var afterScrollTop = document.documentElement.scrollTop || document.body.scrollTop,
  1470. delta = afterScrollTop - beforeScrollTop;
  1471. if (delta == 0) return false;
  1472. fn(delta > 0 ? 'down' : 'up', e);
  1473. beforeScrollTop = afterScrollTop;
  1474. }, false);
  1475. }, 1000)
  1476. }
  1477.  
  1478.  
  1479. // 修改自 https://greasyfork.org/scripts/14178 , https://github.com/machsix/Super-preloader
  1480. var ShowPager = {
  1481. getFullHref: function (e) {
  1482. if (e != null && e.nodeType === 1 && e.href && e.href.slice(0,4) === 'http') return e.href;
  1483. return '';
  1484. },
  1485. createDocumentByString: function (e) {
  1486. if (e) {
  1487. if ('HTML' !== document.documentElement.nodeName) return (new DOMParser).parseFromString(e, 'application/xhtml+xml');
  1488. var t;
  1489. try { t = (new DOMParser).parseFromString(e, 'text/html');} catch (e) {}
  1490. if (t) return t;
  1491. if (document.implementation.createHTMLDocument) {
  1492. t = document.implementation.createHTMLDocument('ADocument');
  1493. } else {
  1494. 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) {}
  1495. }
  1496. if (t) {
  1497. var r = document.createRange(),
  1498. n = r.createContextualFragment(e);
  1499. r.selectNodeContents(document.body);
  1500. t.body.appendChild(n);
  1501. 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);
  1502. return t;
  1503. }
  1504. } else console.error('没有找到要转成 DOM 的字符串');
  1505. },
  1506. loadMorePage: function () {
  1507. if (curSite.pager) {
  1508. var url;
  1509. if (typeof curSite.pager.nextLink == 'function') {
  1510. url = curSite.pager.nextLink();
  1511. } else {
  1512. let curPageEle = getElementByXpath(curSite.pager.nextLink);
  1513. url = this.getFullHref(curPageEle);
  1514. }
  1515. //let curPageEle = getElementByXpath(curSite.pager.nextLink);
  1516. //var url = this.getFullHref(curPageEle);
  1517. //console.log(url, curPageEle, curSite.pageUrl);
  1518. if (url === '') return;
  1519. if (curSite.pageUrl === url) return;// 避免重复加载相同的页面
  1520. curSite.pageUrl = url;
  1521. if (curSite.SiteTypeID === SiteType.BAIDU_TIEBA) {
  1522. url = url + '&pagelets=frs-list%2Fpagelet%2Fthread&pagelets_stamp=' + new Date().getTime();
  1523. }
  1524. let overrideMimeType = '';
  1525. if (curSite.SiteTypeID === SiteType.CARTONNMAD) overrideMimeType = 'text/html; charset=big5';
  1526. // 读取下一页的数据
  1527. GM_xmlhttpRequest({
  1528. url: url,
  1529. method: 'GET',
  1530. overrideMimeType: overrideMimeType,
  1531. timeout: 5000,
  1532. onload: function (response) {
  1533. try {
  1534. //console.log('最终 URL:' + response.finalUrl, '返回内容:' + response.responseText)
  1535. var newBody = ShowPager.createDocumentByString(response.responseText);
  1536. let pageElems = getAllElements(curSite.pager.pageElement, newBody, newBody),
  1537. toElement = getAllElements(curSite.pager.insertPosition[0])[0];
  1538. //console.log(curSite.pager.pageElement, pageElems)
  1539.  
  1540. if (pageElems.length >= 0) {
  1541. // 如果有插入前函数就执行函数
  1542. if (curSite.function && curSite.function.before) {
  1543. if (curSite.function.parameter) { // 如果指定了参数
  1544. pageElems = curSite.function.before(curSite.function.parameter);
  1545. } else {
  1546. pageElems = curSite.function.before(pageElems);
  1547. }
  1548. }
  1549.  
  1550. // 插入位置
  1551. let addTo1 = addTo(curSite.pager.insertPosition[1]);
  1552.  
  1553. // 插入新页面元素
  1554. if (curSite.SiteTypeID === SiteType.STEAMCOMMUNITY) {
  1555. pageElems.forEach(function (one) {
  1556. if (one.tagName === 'SCRIPT') { // 对于 <script> 需要用另一种方式插入网页,以便正常运行
  1557. toElement.appendChild(document.createElement('script')).innerHTML = one.textContent;
  1558. } else {
  1559. toElement.insertAdjacentElement(addTo1, one); // 继续插入网页主体元素
  1560. }
  1561. });
  1562. } else if (curSite.SiteTypeID != SiteType.BAIDU_TIEBA) {
  1563. pageElems.forEach(function (one) {toElement.insertAdjacentElement(addTo1, one);});
  1564. }
  1565.  
  1566. // 对于 <script> 需要用另一种方式插入网页,以便正常运行
  1567. if (curSite.SiteTypeID === SiteType.GOOGLE) {
  1568. const scriptElems = getAllElements('//script', newBody, newBody);
  1569. let scriptText = '';
  1570. scriptElems.forEach(function (one) {scriptText += one.innerHTML;});
  1571. toElement.appendChild(document.createElement('script')).innerHTML = scriptText;
  1572. }
  1573.  
  1574. // 对于百度贴吧这种动态加载内容的网站需要单独处理
  1575. if (curSite.SiteTypeID === SiteType.BAIDU_TIEBA) {
  1576. const scriptElems = getAllElements('//script', newBody, newBody);
  1577. let scriptText = '';
  1578. for (let i = 0; i < scriptElems.length; i++) {
  1579. if (scriptElems[i].textContent.indexOf('Bigpipe.register("frs-list/pagelet/thread_list"') > -1) {
  1580. scriptText = scriptElems[i].textContent.replace('Bigpipe.register("frs-list/pagelet/thread_list", ','');
  1581. break
  1582. }
  1583. }
  1584. if (scriptText) {
  1585. scriptText = scriptText.slice(0, scriptText.indexOf(').')) // 获取主体内容
  1586. let scriptJSON = JSON.parse(scriptText).content; // 字符串转 JSON
  1587. var temp_baidu_tieba = document.createElement('div'); temp_baidu_tieba.innerHTML = scriptJSON; // 字符串转 Element 元素
  1588. pageElems = curSite.function.before(getAllElements(curSite.pager.pageElement, temp_baidu_tieba, temp_baidu_tieba)); // 插入前执行函数
  1589. pageElems.forEach(function (one) {toElement.insertAdjacentElement(addTo1, one);}); // 插入元素
  1590. }
  1591. //toElement.appendChild(document.createElement('script')).innerHTML = scriptText;
  1592. }
  1593.  
  1594. // 替换待替换元素
  1595. try {
  1596. let oriE = getAllElements(curSite.pager.replaceE), repE;
  1597. if (curSite.SiteTypeID === SiteType.BAIDU_TIEBA) {
  1598. repE = getAllElements(curSite.pager.replaceE, temp_baidu_tieba, temp_baidu_tieba);
  1599. } else {
  1600. repE = getAllElements(curSite.pager.replaceE, newBody, newBody);
  1601. }
  1602. if (oriE.length === repE.length) {
  1603. for (let i = 0; i < oriE.length; i++) {
  1604. oriE[i].outerHTML = repE[i].outerHTML;
  1605. }
  1606. }
  1607. } catch (e) {
  1608. console.log(e);
  1609. }
  1610. // 如果有插入后函数就执行函数
  1611. if (curSite.function && curSite.function.after) {
  1612. if (curSite.function.parameter) { // 如果指定了参数
  1613. curSite.function.after(curSite.function.parameter);
  1614. } else {
  1615. curSite.function.after();
  1616. }
  1617. }
  1618. }
  1619. } catch (e) {
  1620. console.log(e);
  1621. }
  1622. }
  1623. });
  1624. }
  1625. },
  1626. };
  1627.  
  1628. function getElementByCSS(css, contextNode = document) {
  1629. return contextNode.querySelector(css);
  1630. }
  1631. function getAllElementsByCSS(css, contextNode = document) {
  1632. return [].slice.call(contextNode.querySelectorAll(css));
  1633. }
  1634. function getElementByXpath(xpath, contextNode, doc = document) {
  1635. contextNode = contextNode || doc;
  1636. try {
  1637. const result = doc.evaluate(xpath, contextNode, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
  1638. // 应该总是返回一个元素节点
  1639. return result.singleNodeValue && result.singleNodeValue.nodeType === 1 && result.singleNodeValue;
  1640. } catch (err) {
  1641. throw new Error(`Invalid xpath: ${xpath}`);
  1642. }
  1643. }
  1644. function getAllElementsByXpath(xpath, contextNode, doc = document) {
  1645. contextNode = contextNode || doc;
  1646. const result = [];
  1647. try {
  1648. const query = doc.evaluate(xpath, contextNode, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
  1649. for (let i = 0; i < query.snapshotLength; i++) {
  1650. const node = query.snapshotItem(i);
  1651. // 如果是 Element 节点
  1652. if (node.nodeType === 1) result.push(node);
  1653. }
  1654. } catch (err) {
  1655. throw new Error(`无效 Xpath: ${xpath}`);
  1656. }
  1657. return result;
  1658. }
  1659. function getAllElements(selector, contextNode = undefined, doc = document, win = window, _cplink = undefined) {
  1660. if (!selector) return [];
  1661. contextNode = contextNode || doc;
  1662. if (typeof selector === 'string') {
  1663. if (selector.search(/^css;/i) === 0) {
  1664. return getAllElementsByCSS(selector.slice(4), contextNode);
  1665. } else {
  1666. return getAllElementsByXpath(selector, contextNode, doc);
  1667. }
  1668. } else {
  1669. const query = selector(doc, win, _cplink);
  1670. if (!Array.isArray(query)) {
  1671. throw new Error('getAllElements 返回错误类型');
  1672. } else {
  1673. return query;
  1674. }
  1675. }
  1676. }
  1677. })();