This solution isn’t as sexy as a script, but I export my InDesign docs as PDFs, open the PDF in Acrobat Pro, and then export again as a text file. Or you can save as text through the free Acrobat Reader. You may have to tweak the final text file slightly depending on how many stories you have per page, but it works for me.