Script for word gathering and sorting in InDesign Dictionary

Here is a Javascript to do the word gathering and sorting. There are straightforward ways to do this, but this script uses a couple of shortcuts that are possible with both Javascript (split arrays on a regular expression; remove duplicates by feeding the result into an object) and InDesign (using everyItem to quickly gather all possible text). So it may be kind of unclear what happens where.
A problem is how to determine what a 'word' is. This script replaces common punctuation and digits with a space, and then only gathers what's left between the spaces. You are sure to find some weird "words" this way, but then again so does your manual way.
After processing, the script prompts for a Save File name and then opens it in your default plain text editor.

Here is the script written by Jongware, and here is a version made by Hans.

The original link is here.