Just wrote a little blog and made a video about this to hopefully make it easier for folks to figure this out. I’ve looked it up a few times throughout the years and it was always a little tricky to find.
https://blog.rayberger.org/how-to-add-a-brand-preset-to-openstreetmap
Thanks for sharing your script. I added a link to your comment at the end of the post 👍 I gotta learn JSOM one day.