Skip to content

Instantly share code, notes, and snippets.

@ticky
Created April 8, 2021 22:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ticky/c346aedf0704fe0a5757240a8b41a174 to your computer and use it in GitHub Desktop.
Save ticky/c346aedf0704fe0a5757240a8b41a174 to your computer and use it in GitHub Desktop.
XPath query to array result shorthand function
// Looks up an XPath node selector and returns an array of matching nodes
const xpathQuerySelector = (xpath) => {
var result = document.evaluate(xpath, document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE);
return Array.from({ length: result.snapshotLength }, (_, index) => result.snapshotItem(index));
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment