I actually did write this up if it helps anyone... I did something similar, my WordPress site only had ~100 pages, so I just put the page map in a table in the js:
https://www.hotelexistence.ca/something-mildly-different/
(my ?p=### script is near the bottom)