Select only text visible on webpage, from DOM parent element

Select only text visible on webpage, from DOM parent element

Inside a content script of my work-in-progress Firefox add-on, I have a variable named ` element ` containing the reference toward a generic DOM element. This element may contain children or grandchildren, which in turn may contain text nodes visible on the rendered webpage.

My goal is to extract all the visible text contained in this DOM ` element `. Internet Explorer has the innerText method, which does exactly what I need but, unfortunately, that is not a standard method and does not work/exist outside of IE.

Firefox comes with a similar textContent property which closely imitates ` innerText `, but fails to filter off invisible text contained within tags such as ` <script> ` and ` <style> `.
   
Looking for a jQuery solution, I believe I'm close to find one; I've come to:
  1. text = $(element).filter(":visible").text();
This statement correctly extracts the text contained in all the children of ` element `, but invisible text from ` <script> ` tags is not filtered off. Googling around, I couldn't find any reference solution to the problem.