--- Revision None +++ Revision 326530663566 @@ -0,0 +1,29 @@ +// jQuery function to find all the text nodes inside an element +$.fn.textNodes = function() { + // array we will store all the text nodes in + var ret = []; + + // nodes we want to skip + var restricted_nodes = {'SCRIPT':1, 'NOSCRIPT':1, 'STYLE':1}; + + $.each(this[0].childNodes, function() { + if (this.nodeType == 3 && $.trim(this.nodeValue)) { + ret.push(this); + } else if (!restricted_nodes.hasOwnProperty(this.nodeName)) { + $.each(this.childNodes, arguments.callee); + } + }); + return ret; +} + +var textNodes = $('body').textNodes(); + +var text = ''; +for (var i = 0; i < textNodes.length; ++i) { + text += textNodes[i].nodeValue + ' '; +} +// text is now a string containing the full text of a webpage with no html + + +// see http://docs.jquery.com/Release:jQuery_1.3.2#:visible.2F:hidden_Overhauled +// for details on how jquery handles finding hidden elements