|
10 | 10 | // @name:fr Pagetual |
11 | 11 | // @name:it Pagetual |
12 | 12 | // @namespace hoothin |
13 | | -// @version 1.9.36.40 |
| 13 | +// @version 1.9.36.41 |
14 | 14 | // @description Perpetual pages - powerful auto-pager script. Auto loading next paginated web pages and inserting into current page. Support thousands of web sites without any rule. |
15 | 15 | // @description:zh-CN 终极自动翻页 - 加载并拼接下一分页内容至当前页尾,智能适配任意网页 |
16 | 16 | // @description:zh-TW 終極自動翻頁 - 加載並拼接下一分頁內容至當前頁尾,智能適配任意網頁 |
|
807 | 807 | return doc.body || doc.querySelector('body') || doc; |
808 | 808 | } |
809 | 809 |
|
810 | | - function getElementByXpath(xpath, contextNode, doc) { |
| 810 | + function getElementByXpath(xpath, doc, contextNode, bySort) { |
811 | 811 | doc = doc || document; |
812 | 812 | contextNode = contextNode || doc; |
813 | 813 | try { |
814 | | - var result = doc.evaluate(xpath, contextNode, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null); |
815 | | - return result.singleNodeValue && result.singleNodeValue.nodeType === 1 && result.singleNodeValue; |
| 814 | + if (!bySort) { |
| 815 | + let result = doc.evaluate(xpath, contextNode, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null); |
| 816 | + return result.singleNodeValue && result.singleNodeValue.nodeType === 1 && result.singleNodeValue; |
| 817 | + } else { |
| 818 | + let xpathArr = xpath.split("|"); |
| 819 | + try { |
| 820 | + for (let i = 0; i < xpathArr.length; i++) { |
| 821 | + let result = doc.evaluate(xpathArr[i].trim(), contextNode, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null); |
| 822 | + if (result.singleNodeValue && result.singleNodeValue.nodeType === 1) return result.singleNodeValue; |
| 823 | + } |
| 824 | + } catch(e) {} |
| 825 | + return null; |
| 826 | + } |
816 | 827 | } catch (err) { |
817 | 828 | debug(`Invalid xpath: ${xpath}`); |
818 | 829 | } |
|
851 | 862 | return getAllElementsByXpath(sel, contextNode, doc); |
852 | 863 | } |
853 | 864 |
|
854 | | - function getElement(sel, doc, contextNode) { |
| 865 | + function getElement(sel, doc, contextNode, bySort) { |
855 | 866 | try { |
856 | 867 | if (!isXPath(sel)) { |
857 | | - return doc.querySelector(sel); |
| 868 | + if (!bySort) { |
| 869 | + return doc.querySelector(sel); |
| 870 | + } else { |
| 871 | + let selArr = sel.split(","); |
| 872 | + try { |
| 873 | + for (let i = 0; i < selArr.length; i++) { |
| 874 | + let ele = doc.querySelector(selArr[i].trim()); |
| 875 | + if (ele) return ele; |
| 876 | + } |
| 877 | + } catch(e) {} |
| 878 | + return null; |
| 879 | + } |
858 | 880 | } |
859 | 881 | } catch(e) { |
860 | 882 | debug(e, 'Error selector'); |
861 | 883 | } |
862 | | - return getElementByXpath(sel, contextNode, doc); |
| 884 | + return getElementByXpath(sel, doc, contextNode, bySort); |
863 | 885 | } |
864 | 886 |
|
865 | 887 | function geneSelector(ele, addID) { |
|
2429 | 2451 | let nextLinkSel = this.curSiteRule.nextLink; |
2430 | 2452 | if (nextLinkSel != 0) { |
2431 | 2453 | if (Array && Array.isArray && Array.isArray(nextLinkSel)) { |
2432 | | - nextLink = getElement(nextLinkSel[nextIndex], doc); |
| 2454 | + nextLink = getElement(nextLinkSel[nextIndex], doc, null, true); |
2433 | 2455 | if (!nextLink && curPage == 1 && nextIndex != 0) { |
2434 | 2456 | nextIndex = 0; |
2435 | | - nextLink = getElement(nextLinkSel[nextIndex], doc); |
| 2457 | + nextLink = getElement(nextLinkSel[nextIndex], doc, null, true); |
2436 | 2458 | } |
2437 | | - } else nextLink = getElement(nextLinkSel, doc); |
| 2459 | + } else nextLink = getElement(nextLinkSel, doc, null, true); |
2438 | 2460 | } |
2439 | 2461 | if (nextLink && (this.curSiteRule.action == 0 || this.curSiteRule.action == 1 || this.curSiteRule.action == 2)) { |
2440 | 2462 | let form = doc.querySelector('#search-form'); |
|
2774 | 2796 | if (Array && Array.isArray && Array.isArray(insertSel)) { |
2775 | 2797 | insertSel = insertSel[nextIndex < insertSel.length ? nextIndex : 0]; |
2776 | 2798 | } |
2777 | | - this.insert = getElement(insertSel, document); |
| 2799 | + this.insert = getElement(insertSel, document, null, true); |
2778 | 2800 | } else { |
2779 | 2801 | this.docPageElement = null; |
2780 | 2802 | let pageElement = this.getPageElement(document, _unsafeWindow); |
|
3010 | 3032 | let autoClick = self.curSiteRule.autoClick; |
3011 | 3033 | if (autoClick) { |
3012 | 3034 | let autoClickBtn; |
3013 | | - autoClickBtn = getElement(autoClick, document); |
| 3035 | + autoClickBtn = getElement(autoClick, document, null, true); |
3014 | 3036 | if (autoClickBtn) { |
3015 | 3037 | emuClick(autoClickBtn); |
3016 | 3038 | } |
|
6330 | 6352 | if (loadmoreBtn) return loadmoreBtn; |
6331 | 6353 | let btnSel = ruleParser.curSiteRule.loadMore || defaultLoadmoreSel; |
6332 | 6354 | if (btnSel) { |
6333 | | - loadmoreBtn = getElement(btnSel, doc); |
| 6355 | + loadmoreBtn = getElement(btnSel, doc, null, true); |
6334 | 6356 | } |
6335 | 6357 | if (!loadmoreBtn) { |
6336 | 6358 | let buttons = doc.querySelectorAll("input,button,a,div[onclick]"); |
|
6650 | 6672 | if (!sel) return null; |
6651 | 6673 | return new Promise((resolve) => { |
6652 | 6674 | let checkInv = setInterval(() => { |
6653 | | - let result = getElement(sel, doc); |
| 6675 | + let result = getElement(sel, doc, null, true); |
6654 | 6676 | if (result) { |
6655 | 6677 | clearInterval(checkInv); |
6656 | 6678 | resolve(result); |
|
0 commit comments