自动无缝翻页

自动无缝翻页,目前支持:所有「Discuz!、Flarum」论坛、百度、豆瓣、微博、千图网、3DM、游侠网、游民星空、423Down、APPHOT、不死鸟、亿破姐、小众软件、微当下载、落尘之木、异次元软件、老殁殁漂遥、异星软件空间、古风漫画网、RARBG、PubMed、AfreecaTV、AlphaCoders、FitGirl Repacks...

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

  1. // ==UserScript==
  2. // @name 自动无缝翻页
  3. // @version 1.4.5
  4. // @author X.I.U
  5. // @description 自动无缝翻页,目前支持:所有「Discuz!、Flarum」论坛、百度、豆瓣、微博、千图网、3DM、游侠网、游民星空、423Down、APPHOT、不死鸟、亿破姐、小众软件、微当下载、落尘之木、异次元软件、老殁殁漂遥、异星软件空间、古风漫画网、RARBG、PubMed、AfreecaTV、AlphaCoders、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. // @license GPL-3.0 License
  15. // @run-at document-end
  16. // @namespace https://github.com/XIU2/UserScript
  17. // @supportURL https://github.com/XIU2/UserScript
  18. // @homepageURL https://github.com/XIU2/UserScript
  19. // ==/UserScript==
  20.  
  21. (function() {
  22. 'use strict';
  23. var webType, curSite = {SiteTypeID: 0};
  24. // 目前支持的网站
  25. const websiteList = ['www.baidu.com', 'movie.douban.com', 'weibo.com', 'www.58pic.com',
  26. 'www.3dmgame.com', 'www.ali213.net', 'gl.ali213.net', 'www.gamersky.com',
  27. 'www.423down.com', 'apphot.cc', 'iao.su', 'www.ypojie.com', 'www.appinn.com', 'www.weidown.com', 'www.luochenzhimu.com', 'www.iplaysoft.com', 'www.mpyit.com', 'www.yxssp.com',
  28. 'www.gufengmh8.com',
  29. 'rarbgprx.org',
  30. 'pubmed.ncbi.nlm.nih.gov',
  31. 'www.afreecatv.com',
  32. 'art.alphacoders.com', 'wall.alphacoders.com', 'avatars.alphacoders.com', 'mobile.alphacoders.com',
  33. '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. // 注册脚本菜单
  38. if (menu_disable('check')) { // 当前网站是否已存在禁用列表中
  39. GM_registerMenuCommand('❎ 已禁用 (点击对当前网站启用)', function(){menu_disable('del')});
  40. return
  41. } else {
  42. if (websiteList.indexOf(location.host) > -1) {
  43. webType = 1 // 其他网站
  44. } else if (document.querySelector('meta[name="author"][content*="Discuz!"], meta[name="generator"][content*="Discuz!"]') || document.getElementById('ft') && document.getElementById('ft').textContent.indexOf('Discuz!') > -1) {
  45. webType = 2 // 所有 Discuz! 论坛
  46. } else if (document.getElementById('flarum-loading')) {
  47. webType = 3 // 所有 Flarum 论坛
  48. } else {
  49. 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});});
  50. return
  51. }
  52. GM_registerMenuCommand('✅ 已启用 (点击对当前网站禁用)', function(){menu_disable('add')});
  53. if (webType === 2) {
  54. GM_registerMenuCommand(`${GM_getValue('menu_discuz_thread_page')?'✅':'❎'} 帖子内自动翻页 (仅 Discuz! 论坛)`, function(){menu_switch(GM_getValue('menu_discuz_thread_page'), 'menu_discuz_thread_page', 'Discuz! 论坛帖子内翻页')});
  55. }
  56. }
  57. 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});});
  58.  
  59.  
  60. /*
  61. 自动翻页规则
  62. type:
  63. 1 = 脚本实现自动无缝翻页
  64. 2 = 网站自带了自动无缝翻页功能,只需要点击下一页按钮即可
  65. nextText: 按钮文本,只有按钮文本为该文本时才会点击按钮加载下一页,避免一瞬间加载太多次下一页
  66. intervals: 点击间隔时间,对于没有按钮文字变化的按钮,可以手动指定间隔时间,单位:ms
  67. 3 = 依靠元素距离可视区域底部的距离来触发翻页
  68. 4 = 针对部分简单动态加载的网站
  69. HT_insert:
  70. 1 = 插入该元素本身的前面;
  71. 2 = 插入该元素当中,第一个子元素前面;
  72. 3 = 插入该元素当中,最后一个子元素后面;
  73. 4 = 插入该元素本身的后面;
  74. scrollDelta:数值越大,滚动条触发点越靠上(越早开始翻页),一般是访问网页速度越慢,该值就需要越大(如果 Type = 3,则相反)
  75. function:
  76. before = 插入前执行函数;
  77. after = 插入后执行函数;
  78. parameter = 参数
  79. */
  80. let DBSite = {
  81. discuz_forum: {
  82. SiteTypeID: 0,
  83. pager: {
  84. type: 2,
  85. nextLink: '#autopbn',
  86. nextText: '下一页 »',
  87. scrollDelta: 1000
  88. }
  89. },
  90. discuz_thread: {
  91. SiteTypeID: 0,
  92. pager: {
  93. type: 1,
  94. nextLink: '//a[@class="nxt"][@href]',
  95. pageElement: 'css;div#postlist > div[id^="post_"]',
  96. HT_insert: ['css;div#postlist', 3],
  97. replaceE: 'css;div.pg',
  98. scrollDelta: 1000
  99. }
  100. },
  101. discuz_search: {
  102. SiteTypeID: 0,
  103. pager: {
  104. type: 1,
  105. nextLink: '//a[@class="nxt"][@href]',
  106. pageElement: 'css;div#threadlist > ul',
  107. HT_insert: ['css;div#threadlist', 3],
  108. replaceE: 'css;div.pg',
  109. scrollDelta: 1000
  110. }
  111. },
  112. discuz_guide: {
  113. SiteTypeID: 0,
  114. pager: {
  115. type: 1,
  116. nextLink: '//a[@class="nxt"][@href]',
  117. pageElement: 'css;div#threadlist div.bm_c table > tbody',
  118. HT_insert: ['css;div#threadlist div.bm_c table', 3],
  119. replaceE: 'css;div.pg',
  120. scrollDelta: 1000
  121. }
  122. },
  123. discuz_youspace: {
  124. SiteTypeID: 0,
  125. pager: {
  126. type: 1,
  127. nextLink: '//a[@class="nxt"][@href]',
  128. pageElement: 'css;tbody > tr:not(.th)',
  129. HT_insert: ['css;tbody', 3],
  130. replaceE: 'css;div.pg',
  131. scrollDelta: 1000
  132. }
  133. },
  134. discuz_collection: {
  135. SiteTypeID: 0,
  136. pager: {
  137. type: 1,
  138. nextLink: '//a[@class="nxt"][@href]',
  139. pageElement: 'css;div#ct div.bm_c table > tbody',
  140. HT_insert: ['css;div#ct div.bm_c table', 3],
  141. replaceE: 'css;div.pg',
  142. scrollDelta: 1000
  143. }
  144. },
  145. flarum: {
  146. SiteTypeID: 0,
  147. pager: {
  148. type: 2,
  149. nextLink: '.DiscussionList-loadMore > button[title]',
  150. scrollDelta: 1000
  151. }
  152. },
  153. dux: {
  154. SiteTypeID: 0,
  155. pager: {
  156. type: 1,
  157. nextLink: '//li[@class="next-page"]/a[@href]',
  158. pageElement: 'css;.content > article',
  159. HT_insert: ['css;.content > .pagination', 1],
  160. replaceE: 'css;.content > .pagination',
  161. scrollDelta: 1000
  162. },
  163. function: {
  164. before: dux_beforeFunction
  165. }
  166. },
  167. baidu: {
  168. SiteTypeID: 0,
  169. pager: {
  170. type: 1,
  171. nextLink: '//div[@id="page"]//a[contains(text(),"下一页")][@href]',
  172. pageElement: 'css;#content_left > *',
  173. HT_insert: ['css;#content_left', 3],
  174. replaceE: 'css;#page',
  175. scrollDelta: 1200
  176. }
  177. },
  178. douban_subject_comments: {
  179. SiteTypeID: 0,
  180. pager: {
  181. type: 1,
  182. nextLink: '//a[@class="next"][@href]',
  183. pageElement: 'css;#comments > .comment-item',
  184. HT_insert: ['css;#paginator', 1],
  185. replaceE: 'css;#paginator',
  186. scrollDelta: 1000
  187. }
  188. },
  189. douban_subject_reviews: {
  190. SiteTypeID: 0,
  191. pager: {
  192. type: 1,
  193. nextLink: '//link[@rel="next"][@href]',
  194. pageElement: 'css;.review-list > div',
  195. HT_insert: ['css;.review-list', 3],
  196. replaceE: 'css;.paginator',
  197. scrollDelta: 1000
  198. }
  199. },
  200. douban_subject_episode: {
  201. SiteTypeID: 0,
  202. pager: {
  203. type: 1,
  204. nextLink: '//link[@rel="next"][@href]',
  205. pageElement: 'css;#comments > div',
  206. HT_insert: ['css;#comments', 3],
  207. replaceE: 'css;.paginator',
  208. scrollDelta: 1000
  209. }
  210. },
  211. weibo_comment: {
  212. SiteTypeID: 0,
  213. pager: {
  214. type: 2,
  215. nextLink: 'a[action-type="click_more_comment"]',
  216. nextText: '查看更多c',
  217. scrollDelta: 1000
  218. }
  219. },
  220. _58pic: {
  221. SiteTypeID: 0,
  222. pager: {
  223. type: 1,
  224. nextLink: '//div[contains(@class,"page-box")]//a[text()="下一页"][@href]',
  225. pageElement: 'css;.pic-box > .qtw-card',
  226. HT_insert: ['css;.pic-box', 3],
  227. replaceE: 'css;.page-box',
  228. scrollDelta: 2000
  229. },
  230. function: {
  231. before: _58pic_beforeFunction
  232. }
  233. },
  234. _58pic_c: {
  235. SiteTypeID: 0,
  236. pager: {
  237. type: 1,
  238. nextLink: '//div[contains(@class,"page-box")]//a[text()="下一页"][@href]',
  239. pageElement: 'css;.list-box > .qtw-card',
  240. HT_insert: ['css;.list-box', 3],
  241. replaceE: 'css;.page-box',
  242. scrollDelta: 4000
  243. },
  244. function: {
  245. before: _58pic_beforeFunction
  246. }
  247. },
  248. _3dmgame: {
  249. SiteTypeID: 0,
  250. pager: {
  251. type: 3,
  252. nextLink: '//li[@class="next"]/a[@href]',
  253. pageElement: 'css;.news_warp_center > *',
  254. HT_insert: ['css;.news_warp_center', 3],
  255. replaceE: 'css;.pagewrap',
  256. scrollElement: '.pagewrap',
  257. scrollDelta: 400
  258. }
  259. },
  260. ali213_www: {
  261. SiteTypeID: 0,
  262. pager: {
  263. type: 3,
  264. nextLink: '//a[@id="after_this_page"][@href]',
  265. pageElement: 'css;#Content >*:not(.news_ding):not(.page_fenye)',
  266. HT_insert: ['css;.page_fenye', 1],
  267. replaceE: 'css;.page_fenye',
  268. scrollElement: '.page_fenye',
  269. scrollDelta: 400
  270. }
  271. },
  272. ali213_gl: {
  273. SiteTypeID: 0,
  274. pager: {
  275. type: 3,
  276. nextLink: '//a[@class="next n"][@href]',
  277. pageElement: 'css;.c-detail >*',
  278. HT_insert: ['css;.c-detail', 3],
  279. replaceE: 'css;.page_fenye',
  280. scrollElement: '.page_fenye',
  281. scrollDelta: 400
  282. }
  283. },
  284. gamersky_ent: {
  285. SiteTypeID: 0,
  286. pager: {
  287. type: 3,
  288. nextLink: '//div[@class="page_css"]/a[text()="下一页"][@href]',
  289. pageElement: 'css;.Mid2L_con > *:not(.gs_nc_editor):not(.pagecss):not(.page_css):not(.gs_ccs_solve):not(.post_ding)',
  290. HT_insert: ['css;.page_css', 1],
  291. replaceE: 'css;.page_css',
  292. scrollElement: '.page_css',
  293. scrollDelta: 100
  294. }
  295. },
  296. gamersky_gl: {
  297. SiteTypeID: 0,
  298. pager: {
  299. type: 3,
  300. nextLink: '//div[@class="page_css"]/a[text()="下一页"][@href]',
  301. pageElement: 'css;.Mid2L_con > *:not(.gs_nc_editor):not(.pagecss):not(.gs_ccs_solve):not(.post_ding)',
  302. HT_insert: ['css;.gs_nc_editor', 1],
  303. replaceE: 'css;.page_css',
  304. scrollElement: '.pagecss',
  305. scrollDelta: -1000
  306. },
  307. function: {
  308. before: gamersky_gl_beforeFunction
  309. }
  310. },
  311. _423down: {
  312. SiteTypeID: 0,
  313. pager: {
  314. type: 1,
  315. nextLink: '//div[@class="paging"]//a[contains(text(),"下一页")][@href]',
  316. pageElement: 'css;div.content-wrap ul.excerpt > li',
  317. HT_insert: ['css;div.content-wrap ul.excerpt', 3],
  318. replaceE: 'css;div.paging',
  319. scrollDelta: 1500
  320. }
  321. },
  322. iao_su: {
  323. SiteTypeID: 0,
  324. pager: {
  325. type: 1,
  326. nextLink: '//li[@class="btn btn-primary next"]//a[@href]',
  327. pageElement: 'css;#index > article, #archive > article',
  328. HT_insert: ['css;ol.page-navigator', 1],
  329. replaceE: 'css;ol.page-navigator',
  330. scrollDelta: 800
  331. },
  332. function: {
  333. before: iao_su_beforeFunction
  334. }
  335. },
  336. appinn: {
  337. SiteTypeID: 0,
  338. pager: {
  339. type: 1,
  340. nextLink: '//a[@class="next page-numbers"][@href]',
  341. pageElement: 'css;section#latest-posts > article',
  342. HT_insert: ['css;nav.navigation.pagination', 1],
  343. replaceE: 'css;div.nav-links',
  344. scrollDelta: 1500
  345. }
  346. },
  347. weidown: {
  348. SiteTypeID: 0,
  349. pager: {
  350. type: 1,
  351. nextLink: '//a[@class="nextpage"][@href]',
  352. pageElement: 'css;.articleWrapper > .itemArticle, .articleWrapper > .richTextItem.search',
  353. HT_insert: ['css;.articleWrapper', 3],
  354. replaceE: 'css;#pageGroup',
  355. scrollDelta: 1500
  356. }
  357. },
  358. weidown_search: {
  359. SiteTypeID: 0,
  360. pager: {
  361. type: 1,
  362. nextLink: '//a[@class="nextpage"][@href]',
  363. pageElement: 'css;.articleListWrapper > .richTextItem.search',
  364. HT_insert: ['css;#pageGroup', 1],
  365. replaceE: 'css;#pageGroup',
  366. scrollDelta: 700
  367. }
  368. },
  369. weidown_special: {
  370. SiteTypeID: 0,
  371. pager: {
  372. type: 1,
  373. nextLink: '//a[@class="nextpage"][@href]',
  374. pageElement: 'css;.special > .item',
  375. HT_insert: ['css;.special', 3],
  376. replaceE: 'css;#pageGroup',
  377. scrollDelta: 700
  378. }
  379. },
  380. iplaysoft_postslist: {
  381. SiteTypeID: 0,
  382. pager: {
  383. type: 1,
  384. nextLink: '//div[@class="pagenavi"]//a[@title="下一页"][@href]',
  385. pageElement: 'css;#postlist > div.entry',
  386. HT_insert: ['css;#postlist > .pagenavi-button', 1],
  387. replaceE: 'css;.pagenavi-button, .pagenavi',
  388. scrollDelta: 1200
  389. },
  390. function: {
  391. before: iplaysoft_postslist_beforeFunction
  392. }
  393. },
  394. iplaysoft_postcomments: {
  395. SiteTypeID: 0,
  396. pager: {
  397. type: 2,
  398. nextLink: '#loadHistoryComments',
  399. nextText: '展开后面',
  400. scrollDelta: 1200
  401. }
  402. },
  403. mpyit: {
  404. SiteTypeID: 0,
  405. pager: {
  406. type: 1,
  407. nextLink: '//a[@class="page-numbers"][@title="下一页"][@href]',
  408. pageElement: 'css;#post > div[id^="post-"]',
  409. HT_insert: ['css;#post > #pagenavi', 1],
  410. replaceE: 'css;#post > #pagenavi',
  411. scrollDelta: 1700
  412. }
  413. },
  414. mpyit_category: {
  415. SiteTypeID: 0,
  416. pager: {
  417. type: 1,
  418. nextLink: '//a[@class="page-numbers"][@title="下一页"][@href]',
  419. pageElement: 'css;#content > div[class^="entry_box"]',
  420. HT_insert: ['css;#content > #pagenavi', 1],
  421. replaceE: 'css;#content > #pagenavi',
  422. scrollDelta: 1700
  423. }
  424. },
  425. yxssp: {
  426. SiteTypeID: 0,
  427. pager: {
  428. type: 1,
  429. nextLink: '//div[@class="page-nav td-pb-padding-side"]/a[last()][@href]',
  430. pageElement: 'css;.td-modules-container.td-module-number4 > div',
  431. HT_insert: ['css;.td-modules-container.td-module-number4', 3],
  432. replaceE: 'css;.page-nav.td-pb-padding-side',
  433. scrollDelta: 1000
  434. }
  435. },
  436. rarbgprx: {
  437. SiteTypeID: 0,
  438. pager: {
  439. type: 1,
  440. nextLink: '(//a[@title="next page"])[1][@href]',
  441. pageElement: 'css;table.lista2t tr.lista2',
  442. HT_insert: ['css;table.lista2t > tbody', 3],
  443. replaceE: 'css;#pager_links',
  444. scrollDelta: 900
  445. }
  446. },
  447. pubmed_postslist: {
  448. SiteTypeID: 0,
  449. pager: {
  450. type: 2,
  451. nextLink: 'button.load-button.next-page',
  452. nextText: 'Show more',
  453. scrollDelta: 1500
  454. }
  455. },
  456. afreecatv: {
  457. SiteTypeID: 0,
  458. pager: {
  459. type: 2,
  460. nextLink: '.btn-more > button',
  461. intervals: 2000,
  462. scrollDelta: 1000
  463. }
  464. },
  465. alphacoders_art: {
  466. SiteTypeID: 0,
  467. pager: {
  468. type: 1,
  469. nextLink: '//a[@id="next_page"][@href]',
  470. pageElement: 'css;.container-masonry > div',
  471. HT_insert: ['css;.container-masonry', 3],
  472. replaceE: '//div[@class="hidden-xs hidden-sm"]/..',
  473. scrollDelta: 1000
  474. },
  475. function: {
  476. before: alphacoders_art_beforeFunction
  477. }
  478. },
  479. alphacoders_wall: {
  480. SiteTypeID: 0,
  481. pager: {
  482. type: 1,
  483. nextLink: '//a[@id="next_page"][@href]',
  484. pageElement: 'css;.thumb-container-big, .avatar-thumb, .thumb-element',
  485. HT_insert: ['css;.thumb-container-big:nth-last-child(1), .avatar-thumb:nth-last-child(1), .thumb-element:nth-last-child(1)', 4],
  486. replaceE: '//div[@class="hidden-xs hidden-sm"]/..',
  487. scrollDelta: 1000
  488. }
  489. },
  490. fitgirl: {
  491. SiteTypeID: 0,
  492. pager: {
  493. type: 1,
  494. nextLink: '//a[@class="next page-numbers"][@href]',
  495. pageElement: 'css;article[id^="post-"]',
  496. HT_insert: ['css;nav.navigation.paging-navigation', 1],
  497. replaceE: 'css;nav.navigation.paging-navigation',
  498. scrollDelta: 2000
  499. }
  500. },
  501. gufengmh8: {
  502. SiteTypeID: 0,
  503. pager: {
  504. type: 4,
  505. pageElement: 'css;body > script:first-child',
  506. HT_insert: ['css;#images', 3],
  507. intervals: 5000,
  508. functionNext: gufengmh8_functionNext,
  509. functionAdd: gufengmh8_functionAdd,
  510. scrollDelta: 2333
  511. }
  512. }
  513. };
  514. // 生成 SiteTypeID
  515. generateID();
  516.  
  517. // 用于脚本判断(针对部分特殊的网站)
  518. const SiteType = {
  519. GAMERSKY_GL: DBSite.gamersky_gl.SiteTypeID
  520. };
  521.  
  522.  
  523. // < 其他网站 >
  524. if (webType === 1) {
  525. switch (location.host) {
  526. case 'apphot.cc': // < APPHOT >
  527. case 'www.ypojie.com': // < 亿破姐 >
  528. case 'www.luochenzhimu.com': // < 落尘之木 >
  529. if (location.pathname.indexOf('.html') === -1) curSite = DBSite.dux;
  530. if (location.host === 'apphot.cc') curSite.pager.scrollDelta = 1600; // 对于速度慢的网站,需要增加翻页敏感度
  531. break;
  532. // 以上几个都是 WordPress 的 DUX 主题
  533. case 'www.baidu.com': // < 百度搜索 >
  534. if (location.pathname === '/s') curSite = DBSite.baidu;
  535. break;
  536. case 'movie.douban.com': // < 豆瓣评论 >
  537. if (location.pathname.indexOf('/subject') > -1 && location.pathname.indexOf('/comments') > -1) { // 短评
  538. curSite = DBSite.douban_subject_comments;
  539. } else if (location.pathname.indexOf('/subject') > -1 && location.pathname.indexOf('/reviews') > -1) { // 影评
  540. curSite = DBSite.douban_subject_reviews;
  541. } else if(location.pathname.indexOf('/subject') > -1 && location.pathname.indexOf('/episode') > -1) { // 电视剧每集评论
  542. curSite = DBSite.douban_subject_episode;
  543. }
  544. break;
  545. case 'weibo.com': // < 微博评论 >
  546. curSite = DBSite.weibo_comment;
  547. break;
  548. case 'www.58pic.com': // < 千图网 >
  549. if (location.pathname.indexOf('/tupian/') > -1) {
  550. curSite = DBSite._58pic;
  551. } else if (location.pathname.indexOf('/c/') > -1) {
  552. curSite = DBSite._58pic_c;
  553. }
  554. break;
  555. case 'www.3dmgame.com': // < 3DM >
  556. curSite = DBSite._3dmgame;
  557. break;
  558. case 'www.ali213.net': // < 游侠网 >
  559. curSite = DBSite.ali213_www;
  560. break;
  561. case 'gl.ali213.net': // < 游侠网 - 攻略页 >
  562. curSite = DBSite.ali213_gl;
  563. document.lastElementChild.appendChild(document.createElement('style')).textContent = `.n_show_b {display: none !important;}` // 隐藏部分碍事元素
  564. break;
  565. case 'www.gamersky.com': // < 游民星空 >
  566. if (location.pathname.indexOf('/ent/') > -1) {
  567. curSite = DBSite.gamersky_ent;
  568. } else {
  569. curSite = DBSite.gamersky_gl;
  570. }
  571. break;
  572. case 'www.423down.com': // < 423down >
  573. if (location.pathname.indexOf('.html') === -1) curSite = DBSite._423down;
  574. break;
  575. case 'iao.su': // < 不死鸟 >
  576. curSite = DBSite.iao_su;
  577. break;
  578. case 'www.appinn.com': // < 小众软件 >
  579. curSite = DBSite.appinn;
  580. break;
  581. case 'www.weidown.com': // < 微当下载 >
  582. if (location.pathname.indexOf('/search/') > -1) {
  583. curSite = DBSite.weidown_search;
  584. } else if (location.pathname.indexOf('/special/') > -1) {
  585. curSite = DBSite.weidown_special;
  586. } else {
  587. curSite = DBSite.weidown;
  588. }
  589. break;
  590. case 'www.iplaysoft.com': // < 异次元软件 >
  591. if (location.pathname.indexOf('.html') > -1 || location.pathname.indexOf('/p/') > -1) { // 文章内
  592. curSite = DBSite.iplaysoft_postcomments;
  593. } else { // 其他页面
  594. curSite = DBSite.iplaysoft_postslist;
  595. }
  596. break;
  597. case 'www.mpyit.com': // < 老殁殁漂遥 >
  598. if (location.pathname === '/' && !location.search) {
  599. curSite = DBSite.mpyit;
  600. } else if (location.pathname.indexOf('/category/') > -1 || location.search.indexOf('?s=') > -1) {
  601. curSite = DBSite.mpyit_category;
  602. }
  603. break;
  604. case 'www.yxssp.com': // < 异星软件空间 >
  605. curSite = DBSite.yxssp;
  606. break;
  607. case 'www.gufengmh8.com': // < 古风漫画网 >
  608. curSite = DBSite.gufengmh8;
  609. break;
  610. case 'rarbgprx.org': // < RARBG >
  611. curSite = DBSite.rarbgprx;
  612. break;
  613. case 'pubmed.ncbi.nlm.nih.gov': // < 国外学术网站 >
  614. curSite = DBSite.pubmed_postslist;
  615. break;
  616. case 'www.afreecatv.com': // < 直播网站 >
  617. curSite = DBSite.afreecatv;
  618. break;
  619. case 'art.alphacoders.com': // < 壁纸网站 >
  620. curSite = DBSite.alphacoders_art;
  621. setTimeout(alphacoders_art_beforeFunction_0, 1000);
  622. break;
  623. case 'wall.alphacoders.com':
  624. case 'avatars.alphacoders.com':
  625. case 'mobile.alphacoders.com':
  626. curSite = DBSite.alphacoders_wall;
  627. break;
  628. case 'fitgirl-repacks.site': // < 游戏下载网站 >
  629. curSite = DBSite.fitgirl;
  630. break;
  631. }
  632. // < 所有 Discuz!论坛 >
  633. } else if (webType === 2) {
  634. if (location.pathname.indexOf('.html') > -1) { // 判断是不是静态网页(.html 结尾)
  635. if (location.pathname.indexOf('forum') > -1) { // 各版块帖子列表
  636. if (document.getElementById('autopbn')) { // 判断是否有 [下一页] 按钮
  637. curSite = DBSite.discuz_forum;
  638. } else {
  639. curSite = DBSite.discuz_guide;
  640. }
  641. } else if (location.pathname.indexOf('thread') > -1) { // 帖子内
  642. if (GM_getValue('menu_discuz_thread_page')) {
  643. curSite = DBSite.discuz_thread;
  644. hidePgbtn(); // 隐藏帖子内的 [下一页] 按钮
  645. }
  646. } else if(location.pathname.indexOf('search') > -1) { // 搜索结果
  647. curSite = DBSite.discuz_search;
  648. }
  649. } else {
  650. if (location.search.indexOf('mod=forumdisplay') > -1) { // 各版块帖子列表
  651. if (document.getElementById('autopbn')) { // 判断是否有 [下一页] 按钮
  652. curSite = DBSite.discuz_forum;
  653. } else {
  654. curSite = DBSite.discuz_guide;
  655. }
  656. } else if (location.search.indexOf('mod=viewthread') > -1) { // 帖子内
  657. if (GM_getValue('menu_discuz_thread_page')) {
  658. curSite = DBSite.discuz_thread;
  659. hidePgbtn(); // 隐藏帖子内的 [下一页] 按钮
  660. }
  661. } else if (location.search.indexOf('mod=guide') > -1) { // 导读帖子列表
  662. curSite = DBSite.discuz_guide;
  663. } else if(location.search.indexOf('mod=space') > -1 && location.search.indexOf('&view=me') > -1) { // 别人的主题/回复
  664. curSite = DBSite.discuz_youspace;
  665. } else if (location.search.indexOf('mod=collection') > -1) { // 淘贴列表
  666. curSite = DBSite.discuz_collection;
  667. } else if (location.pathname.indexOf('search') > -1) { // 搜索结果
  668. curSite = DBSite.discuz_search;
  669. } else { // 考虑到部分论坛的部分板块帖子列表 URL 是自定义的
  670. curSite = DBSite.discuz_forum;
  671. }
  672. }
  673. // < 所有 Flarum 论坛 >
  674. } else if (webType === 3) {
  675. curSite = DBSite.flarum;
  676. }
  677.  
  678.  
  679. curSite.pageUrl = ''; // 下一页URL
  680. pageLoading(); // 自动无缝翻页
  681.  
  682.  
  683. // 自动无缝翻页
  684. function pageLoading() {
  685. if (curSite.SiteTypeID > 0) {
  686. windowScroll(function (direction, e) {
  687. if (direction === 'down') { // 下滑才准备翻页
  688. let scrollTop = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop,
  689. scrollHeight = window.innerHeight || document.documentElement.clientHeight,
  690. scrollDelta = curSite.pager.scrollDelta;
  691. if (curSite.pager.type === 3) { // 翻页类型 3
  692. let scrollElement = document.querySelector(curSite.pager.scrollElement);
  693. //console.log(scrollElement.offsetTop - (scrollTop + scrollHeight), scrollDelta, curSite.SiteTypeID)
  694. if (scrollElement.offsetTop - (scrollTop + scrollHeight) <= scrollDelta) {
  695. if (curSite.SiteTypeID === SiteType.GAMERSKY_GL) curSite.pager.scrollDelta -= 800 // 游民星空 gl 的比较奇葩,需要特殊处理下
  696. ShowPager.loadMorePage();
  697. }
  698. } else {
  699. if (document.documentElement.scrollHeight <= scrollHeight + scrollTop + scrollDelta) {
  700. if (curSite.pager.type === 2) { // 翻页类型 2
  701. if (curSite.SiteTypeID > 0) { // 如果指定了间隔时间,那么就依靠这个判断时间到了没有~
  702. let autopbn = document.querySelector(curSite.pager.nextLink);
  703. if (autopbn) { // 寻找下一页链接
  704. if (!curSite.pager.nextText) { // 如果没有指定 nextText 就直接点击
  705. autopbn.click();
  706. } else if (autopbn.textContent.indexOf(curSite.pager.nextText) > -1){ // 如果指定了 nextText 就需要判断后再点击(避免已经在加载了,还重复点击)
  707. autopbn.click();
  708. }
  709. // 对于没有按钮文字变化的按钮,可以手动指定间隔时间
  710. if (curSite.pager.intervals) {
  711. let _SiteTypeID = curSite.SiteTypeID;
  712. curSite.SiteTypeID = 0;
  713. setTimeout(function(){curSite.SiteTypeID = _SiteTypeID;}, curSite.pager.intervals)
  714. }
  715. }
  716. }
  717. } else if (curSite.pager.type === 1) { // 翻页类型 1
  718. ShowPager.loadMorePage();
  719. } else if (curSite.pager.type === 4) { // 翻页类型 4
  720. if (curSite.SiteTypeID > 0) {
  721. curSite.pager.functionNext();
  722. if (curSite.pager.intervals) {
  723. let _SiteTypeID = curSite.SiteTypeID;
  724. curSite.SiteTypeID = 0;
  725. setTimeout(function(){curSite.SiteTypeID = _SiteTypeID;}, curSite.pager.intervals)
  726. }
  727. }
  728. }
  729. }
  730. }
  731. }
  732. });
  733. }
  734. }
  735.  
  736.  
  737. /*function getElementToPageTop(el) {
  738. if(el.parentElement) {
  739. return getElementToPageTop(el.parentElement) + el.offsetTop
  740. }
  741. return el.offsetTop
  742. }*/
  743.  
  744.  
  745. // 隐藏帖子内的 [下一页] 按钮(Discuz! 论坛)
  746. function hidePgbtn() {
  747. let style_hidePgbtn = document.createElement('style');
  748. style_hidePgbtn.innerHTML = `.pgbtn {display: none;}`;
  749. document.head.appendChild(style_hidePgbtn);
  750. }
  751.  
  752.  
  753. // dux 的插入前函数(加载图片)
  754. function dux_beforeFunction(pageElems) {
  755. pageElems.forEach(function (one) {
  756. let now = one.querySelector('img.thumb[data-src]')
  757. if (now) {
  758. now.setAttribute('src', now.dataset.src)
  759. }
  760. });
  761. return pageElems
  762. }
  763.  
  764.  
  765. // 58pic 的插入前函数(加载图片)
  766. function _58pic_beforeFunction(pageElems) {
  767. let is_one = document.querySelector('.qtw-card.place-box.is-one');
  768. if (is_one && is_one.style.display != 'none') {
  769. is_one.setAttribute('style', 'display: none;')
  770. }
  771. pageElems.forEach(function (one) {
  772. let now = one.querySelector('img.lazy')
  773. if (now && now.getAttribute('src') != now.dataset.original) {
  774. now.setAttribute('src', now.dataset.original)
  775. now.setAttribute('style', 'display: block;')
  776. }
  777. });
  778. return pageElems
  779. }
  780.  
  781.  
  782. // 游民星空攻略 的插入前函数(移除下一页底部的 "更多相关内容请关注:xxx" 文字)
  783. function gamersky_gl_beforeFunction(pageElems) {
  784. pageElems.forEach(function (one) {
  785. if (one.tagName === 'P' && one.textContent.indexOf('更多相关内容请关注') > -1) {
  786. one.style.display = 'none';
  787. }
  788. });
  789. return pageElems
  790. }
  791.  
  792.  
  793. // iao.su 的插入前函数(加载图片)
  794. function iao_su_beforeFunction(pageElems) {
  795. pageElems.forEach(function (one) {
  796. let now = one.getElementsByClassName('post-card')[0]
  797. if (now) {
  798. now.getElementsByClassName('blog-background')[0].style.backgroundImage = 'url("' + now.getElementsByTagName('script')[0].textContent.split("'")[1] + '")';
  799. //now.getElementsByClassName('blog-background')[0].style.backgroundImage = 'url("' + RegExp("(?<=loadBannerDirect\\(').*(?=', '',)").exec(now.getElementsByTagName('script')[0].textContent)[0]; + '")';
  800. }
  801. });
  802. return pageElems
  803. }
  804.  
  805.  
  806. // iplaysoft 的插入前函数(加载图片)
  807. function iplaysoft_postslist_beforeFunction(pageElems) {
  808. pageElems.forEach(function (one) {
  809. let now = one.querySelector('img.lazyload')
  810. if (now && !now.src) {
  811. now.setAttribute('src', now.dataset.src)
  812. now.setAttribute('srcset', now.dataset.src)
  813. now.setAttribute('class', 'lazyloaded')
  814. }
  815. });
  816. return pageElems
  817. }
  818.  
  819.  
  820. // alphacoders_art 的插入前函数(图片结构调整)
  821. function alphacoders_art_beforeFunction(pageElems) {
  822. pageElems.forEach(function (one) {
  823. one.setAttribute('style','float: left');
  824. });
  825. return pageElems
  826. }
  827. // alphacoders_art(图片结构调整)
  828. function alphacoders_art_beforeFunction_0() {
  829. let pageElems1 = document.querySelectorAll('.container-masonry > div')
  830. document.querySelector('.container-masonry').style.height = 'auto'
  831. pageElems1.forEach(function (one) {
  832. one.setAttribute('style','float: left');
  833. });
  834. }
  835.  
  836.  
  837. // gufengmh8
  838. function gufengmh8_functionNext() {
  839. if (curSite.pageUrl) { // 如果已经有下一页的 URL 则直接获取
  840. getPageElems(curSite.pageUrl)
  841. } else {
  842. let pageElems = document.querySelector(curSite.pager.pageElement.replace('css;', '')); // 寻找数据所在元素
  843. if (pageElems) {
  844. let comicUrl, nextId;
  845. pageElems.textContent.split(';').forEach(function (one){ // 分号 ; 分割为数组并遍历
  846. //console.log(one)
  847. if (one.indexOf('comicUrl') > -1) { // 下一页 URL 前半部分
  848. comicUrl = one.split('"')[1];
  849. } else if (one.indexOf('nextChapterData') > -1) { // 下一页 URL 的后半部分 ID
  850. nextId = one.split('"id":')[1].split(',')[0];
  851. }
  852. })
  853. if (comicUrl && nextId && nextId != 'null') { // 组合到一起就是下一页 URL
  854. curSite.pageUrl = comicUrl + nextId + '.html'
  855. //console.log(curSite.pageUrl)
  856. getPageElems(curSite.pageUrl); // 访问下一页 URL 获取
  857. }
  858. }
  859. }
  860. }
  861.  
  862. // gufengmh8
  863. function gufengmh8_functionAdd(pageElems) {
  864. if (pageElems) {
  865. curSite.pageUrl = ''; // 留空后,下一页 URL 依然交给 gufengmh8_function 函数获取(方便点)
  866. pageElems = pageElems[0];
  867. //console.log(pageElems)
  868. let chapterImages, chapterPath;
  869. //console.log(pageElems.textContent)
  870. document.querySelector(curSite.pager.pageElement.replace('css;', '')).innerText = pageElems.textContent; // 将当前网页内的数据所在元素内容改为刚刚获取的下一页数据内容,以便循环获取下一页 URL(gufengmh8_function 函数)
  871. pageElems.textContent.split(';').forEach(function (one){ // 分号 ; 分割为数组并遍历
  872. //console.log(one)
  873. if (one.indexOf('chapterImages') > -1) { // 图片文件名数组
  874. chapterImages = one.replace(/^.+\[/, '').replace(']', '').replaceAll('"', '').split(',')
  875. } else if (one.indexOf('chapterPath') > -1) { // 图片文件路径
  876. chapterPath = one.split('"')[1];
  877. } else if (one.indexOf('pageTitle') > -1) { // 网页标题
  878. window.document.title = one.split('"')[1]; // 修改当前网页标题为下一页的标题
  879. }
  880. })
  881. if (chapterImages && chapterPath) {
  882. let _img = '';
  883. chapterImages.forEach(function (one2){ // 遍历图片文件名数组,组合为 img 标签
  884. _img += '<img src="https://res.xiaoqinre.com/' + chapterPath + one2 + '" data-index="0" style="display: inline-block;">'
  885. //console.log('https://res.xiaoqinre.com/' + chapterPath + one2)
  886. })
  887. document.querySelector(curSite.pager.HT_insert[0].replace('css;', '')).insertAdjacentHTML(addTo(curSite.pager.HT_insert[1]), _img); // 将 img 标签插入到网页中
  888.  
  889. }
  890. }
  891. }
  892.  
  893.  
  894. // 启用/禁用 (当前网站)
  895. function menu_disable(type) {
  896. switch(type) {
  897. case 'check':
  898. if(check()) return true
  899. return false
  900. break;
  901. case 'add':
  902. add();
  903. break;
  904. case 'del':
  905. del();
  906. break;
  907. }
  908.  
  909. function check() { // 存在返回真,不存在返回假
  910. let list = GM_getValue('menu_disable'); // 读取网站列表
  911. if (list.indexOf(location.host) === -1) return false // 不存在返回假
  912. return true
  913. }
  914.  
  915. function add() {
  916. if (check()) return
  917. let list = GM_getValue('menu_disable'); // 读取网站列表
  918. list.push(location.host); // 追加网站域名
  919. GM_setValue('menu_disable', list); // 写入配置
  920. location.reload(); // 刷新网页
  921. }
  922.  
  923. function del() {
  924. if (!check()) return
  925. let list = GM_getValue('menu_disable'), // 读取网站列表
  926. index = list.indexOf(location.host);
  927. list.splice(index, 1); // 删除网站域名
  928. GM_setValue('menu_disable', list); // 写入配置
  929. location.reload(); // 刷新网页
  930. }
  931. }
  932.  
  933.  
  934. // 菜单开关
  935. function menu_switch(menu_status, Name, Tips) {
  936. if (menu_status === true){
  937. GM_setValue(`${Name}`, false);
  938. }else{
  939. GM_setValue(`${Name}`, true);
  940. }
  941. location.reload();
  942. };
  943.  
  944.  
  945. // 生成 ID
  946. function generateID() {
  947. let num = 0
  948. for (let val in DBSite) {
  949. DBSite[val].SiteTypeID = num = num + 1;
  950. }
  951. }
  952.  
  953.  
  954. // 类型 4 专用
  955. function getPageElems(url) {
  956. GM_xmlhttpRequest({
  957. url: url,
  958. method: 'GET',
  959. timeout: 5000,
  960. onload: function (response) {
  961. try {
  962. //console.log('最终 URL:' + response.finalUrl, '返回内容:' + response.responseText)
  963. var newBody = ShowPager.createDocumentByString(response.responseText);
  964. let pageElems = getAllElements(curSite.pager.pageElement, newBody, newBody);
  965. if (pageElems.length >= 0) {
  966. curSite.pager.functionAdd(pageElems)
  967. }
  968. } catch (e) {
  969. console.log(e);
  970. }
  971. }
  972. });
  973. }
  974.  
  975.  
  976. // 插入位置
  977. function addTo(num) {
  978. switch (num) {
  979. case 1:
  980. return 'beforebegin'
  981. break;
  982. case 2:
  983. return 'afterbegin'
  984. break;
  985. case 3:
  986. return 'beforeend'
  987. break;
  988. case 4:
  989. return 'afterend'
  990. break;
  991. }
  992. }
  993.  
  994.  
  995. // 滚动条事件
  996. function windowScroll(fn1) {
  997. var beforeScrollTop = document.documentElement.scrollTop,
  998. fn = fn1 || function () {};
  999. setTimeout(function () { // 延时执行,避免刚载入到页面就触发翻页事件
  1000. window.addEventListener('scroll', function (e) {
  1001. var afterScrollTop = document.documentElement.scrollTop,
  1002. delta = afterScrollTop - beforeScrollTop;
  1003. if (delta == 0) return false;
  1004. fn(delta > 0 ? 'down' : 'up', e);
  1005. beforeScrollTop = afterScrollTop;
  1006. }, false);
  1007. }, 1000)
  1008. }
  1009.  
  1010.  
  1011. // 修改自 https://greasyfork.org/scripts/14178 , https://github.com/machsix/Super-preloader
  1012. var ShowPager = {
  1013. getFullHref: function (e) {
  1014. if(e == null) return '';
  1015. 'string' != typeof e && (e = e.getAttribute('href'));
  1016. var t = this.getFullHref.a;
  1017. if (t) {return t}
  1018. ((this.getFullHref.a = t = document.createElement('a')), t.href = e, t.href)
  1019. if (t.href) {return t.href}
  1020. //return t || ((this.getFullHref.a = t = document.createElement('a')), t.href = e, t.href);
  1021. },
  1022. createDocumentByString: function (e) {
  1023. if (e) {
  1024. if ('HTML' !== document.documentElement.nodeName) return (new DOMParser).parseFromString(e, 'application/xhtml+xml');
  1025. var t;
  1026. try { t = (new DOMParser).parseFromString(e, 'text/html');} catch (e) {}
  1027. if (t) return t;
  1028. if (document.implementation.createHTMLDocument) {
  1029. t = document.implementation.createHTMLDocument('ADocument');
  1030. } else {
  1031. 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) {}
  1032. }
  1033. if (t) {
  1034. var r = document.createRange(),
  1035. n = r.createContextualFragment(e);
  1036. r.selectNodeContents(document.body);
  1037. t.body.appendChild(n);
  1038. 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);
  1039. return t;
  1040. }
  1041. } else console.error('没有找到要转成 DOM 的字符串');
  1042. },
  1043. loadMorePage: function () {
  1044. if (curSite.pager) {
  1045. let curPageEle = getElementByXpath(curSite.pager.nextLink);
  1046. var url = this.getFullHref(curPageEle);
  1047. //console.log(`${url} ${curPageEle} ${curSite.pageUrl}`);
  1048. if (url === '') return;
  1049. if (curSite.pageUrl === url) return;// 避免重复加载相同的页面
  1050. curSite.pageUrl = url;
  1051. // 读取下一页的数据
  1052. curSite.pager.startFilter && curSite.pager.startFilter();
  1053. GM_xmlhttpRequest({
  1054. url: url,
  1055. method: 'GET',
  1056. timeout: 5000,
  1057. onload: function (response) {
  1058. try {
  1059. //console.log('最终 URL:' + response.finalUrl, '返回内容:' + response.responseText)
  1060. var newBody = ShowPager.createDocumentByString(response.responseText);
  1061. let pageElems = getAllElements(curSite.pager.pageElement, newBody, newBody),
  1062. toElement = getAllElements(curSite.pager.HT_insert[0])[0];
  1063.  
  1064. if (pageElems.length >= 0) {
  1065. // 如果有插入前函数就执行函数
  1066. if (curSite.function && curSite.function.before) {
  1067. if (curSite.function.parameter) { // 如果指定了参数
  1068. pageElems = curSite.function.before(curSite.function.parameter);
  1069. } else {
  1070. pageElems = curSite.function.before(pageElems);
  1071. }
  1072. }
  1073.  
  1074. // 插入位置
  1075. let addTo1 = addTo(curSite.pager.HT_insert[1]);
  1076. // 插入新页面元素
  1077. pageElems.forEach(function (one) {
  1078. toElement.insertAdjacentElement(addTo1, one);
  1079. });
  1080.  
  1081. // 替换待替换元素
  1082. try {
  1083. let oriE = getAllElements(curSite.pager.replaceE);
  1084. let repE = getAllElements(curSite.pager.replaceE, newBody, newBody);
  1085. if (oriE.length === repE.length) {
  1086. for (var i = 0; i < oriE.length; i++) {
  1087. oriE[i].outerHTML = repE[i].outerHTML;
  1088. }
  1089. }
  1090. } catch (e) {
  1091. console.log(e);
  1092. }
  1093. // 如果有插入后函数就执行函数
  1094. if (curSite.function && curSite.function.after) {
  1095. if (curSite.function.parameter) { // 如果指定了参数
  1096. curSite.function.after(curSite.function.parameter);
  1097. }else{
  1098. curSite.function.after();
  1099. }
  1100. }
  1101. }
  1102. } catch (e) {
  1103. console.log(e);
  1104. }
  1105. }
  1106. });
  1107. }
  1108. },
  1109. };
  1110.  
  1111. function getElementByCSS(css, contextNode = document) {
  1112. return contextNode.querySelector(css);
  1113. }
  1114. function getAllElementsByCSS(css, contextNode = document) {
  1115. return [].slice.call(contextNode.querySelectorAll(css));
  1116. }
  1117. function getElementByXpath(xpath, contextNode, doc = document) {
  1118. contextNode = contextNode || doc;
  1119. try {
  1120. const result = doc.evaluate(xpath, contextNode, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
  1121. // 应该总是返回一个元素节点
  1122. return result.singleNodeValue && result.singleNodeValue.nodeType === 1 && result.singleNodeValue;
  1123. } catch (err) {
  1124. throw new Error(`Invalid xpath: ${xpath}`);
  1125. }
  1126. }
  1127. function getAllElementsByXpath(xpath, contextNode, doc = document) {
  1128. contextNode = contextNode || doc;
  1129. const result = [];
  1130. try {
  1131. const query = doc.evaluate(xpath, contextNode, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
  1132. for (let i = 0; i < query.snapshotLength; i++) {
  1133. const node = query.snapshotItem(i);
  1134. // 如果是 Element 节点
  1135. if (node.nodeType === 1) result.push(node);
  1136. }
  1137. } catch (err) {
  1138. throw new Error(`无效 Xpath: ${xpath}`);
  1139. }
  1140. return result;
  1141. }
  1142. function getAllElements(selector, contextNode = undefined, doc = document, win = window, _cplink = undefined) {
  1143. if (!selector) return [];
  1144. contextNode = contextNode || doc;
  1145. if (typeof selector === 'string') {
  1146. if (selector.search(/^css;/i) === 0) {
  1147. return getAllElementsByCSS(selector.slice(4), contextNode);
  1148. } else {
  1149. return getAllElementsByXpath(selector, contextNode, doc);
  1150. }
  1151. } else {
  1152. const query = selector(doc, win, _cplink);
  1153. if (!Array.isArray(query)) {
  1154. throw new Error('getAllElements 返回错误类型');
  1155. } else {
  1156. return query;
  1157. }
  1158. }
  1159. }
  1160. })();