Created
November 1, 2026 01:42
-
-
Save Dither/a30cf66c069bb6aeff1fa76047fbfef5 to your computer and use it in GitHub Desktop.
Dev function for XPath verification
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ==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