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

Function getXpath

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

Source from the content-addressed store, hash-verified

2349 return [].slice.call(contextNode.querySelectorAll(css));
2350 }
2351 function getXpath(xpath, contextNode, doc = document) {
2352 contextNode = contextNode || doc;
2353 try {
2354 const result = doc.evaluate(xpath, contextNode, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
2355 // 应该总是返回一个元素节点
2356 return result.singleNodeValue && result.singleNodeValue.nodeType === 1 && result.singleNodeValue;
2357 } catch (err) {
2358 throw new Error(`无效 Xpath: ${xpath}`);
2359 }
2360 }
2361 function getAllXpath(xpath, contextNode, doc = document) {
2362 contextNode = contextNode || doc;
2363 const result = [];

Callers 4

doesItSupportFunction · 0.70
discuz_Function · 0.70
nexusmods_nextLFunction · 0.70
getOneFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected