Here you go. I've manually added the javascript tag to the .aslx so it loads randomjs.js, and I've fixed randomjs.js so it's a proper JS file.
As an example, I added a "changedparent" script to the player object so it triggers the singledice function every time the player moves.
As you can see, gamebook mode is not really set up for this kind of thing so there are some manual hacks to make - but it shows that in principle you can get JS running from gamebook mode (as there's not really anything special about gamebooks - they just use a more limited standard library)