Skip to content

Commit bafdd25

Browse files
committed
1.9.36.41
1 parent 97e8909 commit bafdd25

2 files changed

Lines changed: 37 additions & 15 deletions

File tree

Pagetual/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[☯️](https://greasyfork.org/scripts/438684)東方永頁機 v.1.9.36.40
1+
[☯️](https://greasyfork.org/scripts/438684)東方永頁機 v.1.9.36.41
22
==
33
*Pagetual - Perpetual pages. Auto loading paginated web pages for 90% of all web sites ! [**Wiki**](https://pagetual.hoothin.com/en/)*
44

Pagetual/pagetual.user.js

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
// @name:fr Pagetual
1111
// @name:it Pagetual
1212
// @namespace hoothin
13-
// @version 1.9.36.40
13+
// @version 1.9.36.41
1414
// @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.
1515
// @description:zh-CN 终极自动翻页 - 加载并拼接下一分页内容至当前页尾,智能适配任意网页
1616
// @description:zh-TW 終極自動翻頁 - 加載並拼接下一分頁內容至當前頁尾,智能適配任意網頁
@@ -807,12 +807,23 @@
807807
return doc.body || doc.querySelector('body') || doc;
808808
}
809809

810-
function getElementByXpath(xpath, contextNode, doc) {
810+
function getElementByXpath(xpath, doc, contextNode, bySort) {
811811
doc = doc || document;
812812
contextNode = contextNode || doc;
813813
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+
}
816827
} catch (err) {
817828
debug(`Invalid xpath: ${xpath}`);
818829
}
@@ -851,15 +862,26 @@
851862
return getAllElementsByXpath(sel, contextNode, doc);
852863
}
853864

854-
function getElement(sel, doc, contextNode) {
865+
function getElement(sel, doc, contextNode, bySort) {
855866
try {
856867
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+
}
858880
}
859881
} catch(e) {
860882
debug(e, 'Error selector');
861883
}
862-
return getElementByXpath(sel, contextNode, doc);
884+
return getElementByXpath(sel, doc, contextNode, bySort);
863885
}
864886

865887
function geneSelector(ele, addID) {
@@ -2429,12 +2451,12 @@
24292451
let nextLinkSel = this.curSiteRule.nextLink;
24302452
if (nextLinkSel != 0) {
24312453
if (Array && Array.isArray && Array.isArray(nextLinkSel)) {
2432-
nextLink = getElement(nextLinkSel[nextIndex], doc);
2454+
nextLink = getElement(nextLinkSel[nextIndex], doc, null, true);
24332455
if (!nextLink && curPage == 1 && nextIndex != 0) {
24342456
nextIndex = 0;
2435-
nextLink = getElement(nextLinkSel[nextIndex], doc);
2457+
nextLink = getElement(nextLinkSel[nextIndex], doc, null, true);
24362458
}
2437-
} else nextLink = getElement(nextLinkSel, doc);
2459+
} else nextLink = getElement(nextLinkSel, doc, null, true);
24382460
}
24392461
if (nextLink && (this.curSiteRule.action == 0 || this.curSiteRule.action == 1 || this.curSiteRule.action == 2)) {
24402462
let form = doc.querySelector('#search-form');
@@ -2774,7 +2796,7 @@
27742796
if (Array && Array.isArray && Array.isArray(insertSel)) {
27752797
insertSel = insertSel[nextIndex < insertSel.length ? nextIndex : 0];
27762798
}
2777-
this.insert = getElement(insertSel, document);
2799+
this.insert = getElement(insertSel, document, null, true);
27782800
} else {
27792801
this.docPageElement = null;
27802802
let pageElement = this.getPageElement(document, _unsafeWindow);
@@ -3010,7 +3032,7 @@
30103032
let autoClick = self.curSiteRule.autoClick;
30113033
if (autoClick) {
30123034
let autoClickBtn;
3013-
autoClickBtn = getElement(autoClick, document);
3035+
autoClickBtn = getElement(autoClick, document, null, true);
30143036
if (autoClickBtn) {
30153037
emuClick(autoClickBtn);
30163038
}
@@ -6330,7 +6352,7 @@
63306352
if (loadmoreBtn) return loadmoreBtn;
63316353
let btnSel = ruleParser.curSiteRule.loadMore || defaultLoadmoreSel;
63326354
if (btnSel) {
6333-
loadmoreBtn = getElement(btnSel, doc);
6355+
loadmoreBtn = getElement(btnSel, doc, null, true);
63346356
}
63356357
if (!loadmoreBtn) {
63366358
let buttons = doc.querySelectorAll("input,button,a,div[onclick]");
@@ -6650,7 +6672,7 @@
66506672
if (!sel) return null;
66516673
return new Promise((resolve) => {
66526674
let checkInv = setInterval(() => {
6653-
let result = getElement(sel, doc);
6675+
let result = getElement(sel, doc, null, true);
66546676
if (result) {
66556677
clearInterval(checkInv);
66566678
resolve(result);

0 commit comments

Comments
 (0)