Created
January 31, 2013 21:08
-
-
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.
This file contains 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
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