MCPcopy Create free account
hub / github.com/XIU2/UserScript / getAllElementsByXpath

Function getAllElementsByXpath

3dm-Enhanced.user.js:378–392  ·  view source on GitHub ↗
(xpath, contextNode, doc = document)

Source from the content-addressed store, hash-verified

376 }
377 }
378 function getAllElementsByXpath(xpath, contextNode, doc = document) {
379 contextNode = contextNode || doc;
380 const result = [];
381 try {
382 const query = doc.evaluate(xpath, contextNode, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
383 for (let i = 0; i < query.snapshotLength; i++) {
384 const node = query.snapshotItem(i);
385 // 如果是 Element 节点
386 if (node.nodeType === 1) result.push(node);
387 }
388 } catch (err) {
389 throw new Error(`无效 Xpath: ${xpath}`);
390 }
391 return result;
392 }
393 function getAllElements(selector, contextNode = undefined, doc = document, win = window, _cplink = undefined) {
394 if (!selector) return [];
395 contextNode = contextNode || doc;

Callers 1

getAllElementsFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected