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

Function getElementByXpath

52pojie-Enhanced.user.js:353–362  ·  view source on GitHub ↗
(xpath, contextNode, doc = document)

Source from the content-addressed store, hash-verified

351 return [].slice.call(contextNode.querySelectorAll(css));
352 }
353 function getElementByXpath(xpath, contextNode, doc = document) {
354 contextNode = contextNode || doc;
355 try {
356 const result = doc.evaluate(xpath, contextNode, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
357 // 应该总是返回一个元素节点
358 return result.singleNodeValue && result.singleNodeValue.nodeType === 1 && result.singleNodeValue;
359 } catch (err) {
360 throw new Error(`Invalid xpath: ${xpath}`);
361 }
362 }
363 function getAllElementsByXpath(xpath, contextNode, doc = document) {
364 contextNode = contextNode || doc;
365 const result = [];

Callers 1

showPagerFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected