Skip to content

Instantly share code, notes, and snippets.

@ZoolWay
Created August 28, 2020 07:07
Show Gist options
  • Save ZoolWay/1c3b18530614b8537515cfeb0f93aacb to your computer and use it in GitHub Desktop.
Save ZoolWay/1c3b18530614b8537515cfeb0f93aacb to your computer and use it in GitHub Desktop.
Tampermonkey, XPath parser function for javascript console
// ==UserScript==
// @name ricky_xpath
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://*/*
// @match http://*/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
window.ricky_xpath = function (xpath) {
const result = document.evaluate(xpath, document, null, XPathResult.ANY_TYPE, null);
let nodes = [];
let node = result.iterateNext();
while (node) {
nodes.push(node);
node = result.iterateNext();
}
return nodes;
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment