javascript - How to select all *renderable* text elements in browser -


how can select visible renderable html text nodes in browser document?

in other words, how can list of dom nodes can traverse via scripting in order obtain text visible user in browser, in document order?

i rely on browser tell me nodes constitute visible renderable text. i'm not sure start. help?

this tricky, here's i've come with:

function traverse(o) {   var = [];   [].foreach.call(o.childnodes, function(val) {     if(val.nodetype===3) {       if(val.nodevalue.trim()>'') a.push(val);     }     else {       var style= getcomputedstyle(val);       if(val.tagname!=='noscript' &&           style.getpropertyvalue('display')!=='none' &&          style.getpropertyvalue('visibility')!=='hidden' &&          style.getpropertyvalue('opacity')!=='0' &&          style.getpropertyvalue('color')!==style.getpropertyvalue('background-color')         ) {         a= a.concat(traverse(val));       }     }   });   return a; } //traverse  var textnodes= traverse(document.body); 

working fiddle

this not check if text nodes hidden behind other elements or if absolutely positioned offscreen.


Comments

Popular posts from this blog

java - Could not locate OpenAL library -

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

sorting - opencl Bitonic sort with 64 bits keys -