Skip to content

Instantly share code, notes, and snippets.

@kadamwhite
Created January 31, 2013 21:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kadamwhite/4686458 to your computer and use it in GitHub Desktop.
Save kadamwhite/4686458 to your computer and use it in GitHub Desktop.
Based on https://twitter.com/the55/status/295991439484137472, this is (will be) a script to fetch text nodes from the current page, pick a few random phrases, and combine them into an entertaining song name with band, track, and optionally remixer/remix name.
function findTextNodes( node ) {
var text = [];
if ( node.nodeType === 3 ) {
text.push( node.nodeValue );
// TODO: Filter out carriage returns, whitespace.
// POSSIBLE TODO: Restrict to nodes within the main content area of the page? (so don't get ads, etc)
} else {
for ( var i = 0, max = node.childNodes.length; i < max; i++ ) {
text = text.concat( findTextNodes( node.childNodes[i] ) );
}
}
return text;
}
var textNodes = findTextNodes( document.body );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment