MCPcopy Index your code
hub / github.com/XIU2/UserScript / getAllXpath

Function getAllXpath

Autopage.user.js:2361–2375  ·  view source on GitHub ↗
(xpath, contextNode, doc = document)

Source from the content-addressed store, hash-verified

2359 }
2360 }
2361 function getAllXpath(xpath, contextNode, doc = document) {
2362 contextNode = contextNode || doc;
2363 const result = [];
2364 try {
2365 const query = doc.evaluate(xpath, contextNode, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
2366 for (let i = 0; i < query.snapshotLength; i++) {
2367 const node = query.snapshotItem(i);
2368 // 如果是 Element 节点
2369 if (node.nodeType === 1) result.push(node);
2370 }
2371 } catch (err) {
2372 throw new Error(`无效 Xpath: ${xpath}`);
2373 }
2374 return result;
2375 }
2376 function getOne(selector, contextNode = undefined, doc = document) {
2377 if (!selector) return;
2378 contextNode = contextNode || doc;

Callers 2

doesItSupportFunction · 0.85
getAllFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected