Skip to content

Instantly share code, notes, and snippets.

@Dither
Created November 1, 2026 01:42
Show Gist options
  • Select an option

  • Save Dither/a30cf66c069bb6aeff1fa76047fbfef5 to your computer and use it in GitHub Desktop.

Select an option

Save Dither/a30cf66c069bb6aeff1fa76047fbfef5 to your computer and use it in GitHub Desktop.
Dev function for XPath verification
// ==UserScript==
// @name queryXPath
// @namespace developing
// @version 0.1
// @description queryXPath
// @match *
// @grant unsafeWindow
// ==/UserScript==
unsafeWindow.queryXPath = path => document.evaluate(
path,
document,
null,
XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
null
).snapshotItem(0)
unsafeWindow.queryXPathAll = path => {
const nodeArray = []
const xpath = document.evaluate(
path,
document,
null,
XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
null
)
for (let i=0; i<xpath.snapshotLength; i++) {
nodeArray.push(xpath.snapshotItem(i))
}
return nodeArray
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment