Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Utility functions for injecting into webpages to do scraping and fun things.
// Use http://bookmarklets.org/maker/ with no jQuery (sometimes there are SSL problems)
window.q = document.querySelectorAll.bind(document);
window.qq = document.querySelector.bind(document);
NodeList.prototype.map = function(func, debug) {
// A very useful function for reading and modifying a bunch of nodes on a web page.
// example usage: q('a').map(node => node.getAttribute('href')) -> ['http://glench.com/', 'closed-source/dictionaryofnumbers/', ...]
if (!func) { func = function(node) { return node;} }
var nodes = this;
var values = [];
for (var i=0; i < nodes.length; ++i) {
if (debug) {
// add a node and value so better inspection can happen
values.push([nodes[i], func(nodes[i])]);
} else {
values.push(func(nodes[i]));
}
}
if (debug) {
console.table(values);
}
return values;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.