Modified version of this script that adds a Headings tools Document menu allowing you to:
- auto number Heading
- clear Headings numbers
- Open your document > Tools > Script editor...
- Start a blank project
- Paste the code from the code.gs file and save with your preffered name
- Select Run > onOpen and authorize the script for the first time
- Select Run > onOpen
- Change to your Document and try the functions on the Headings tools custom menu created.
Disclaimer: you may have issues with empty Headings.. But you can always fix them and run action again.