Skip to content

Instantly share code, notes, and snippets.

@nathanathan

nathanathan/findText.js

Last active Dec 31, 2015
Embed
What would you like to do?
walk = document.createTreeWalker(document, NodeFilter.SHOW_TEXT, null, false);
prevSentence = "";
sentences = [''];
while(n=walk.nextNode()) {
nextSentences = n.nodeValue.split('.');
sentences[sentences.length - 1] += nextSentences.pop();
sentences = sentences.concat(nextSentences);
}
sentences.forEach(function(sentence){
if(/test/gi.test(sentence)) console.log(sentence);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment