Yeah. If you still want to use JavaScript, you could use something like Puppeteer which is a headless Chromium web scraper, much like Selenium and Beautiful Soup for Python. In fact using Puppeteer if you're wanting to keep it JavaScript would probably save you some time and headaches.
I wrote a broken script for Puppeteer which is in this GitHub gist, just to give you a feel for how it works:
https://gist.github.com/twhite96/38b...05de2990dcbb9c
I am not sure how to share the automation with the community though. Maybe the creator of Calibre has some ideas? I think I have his name right but don't want to misspell it in this comment.
The docs are here:
https://pptr.dev/