Create a javascript function that extracts the text from a document