Choice Splitter -- allows use of 'choice.123.ash' formatted overrides
Choice Splitter 1.1
This simple little script's purpose is to help awesome script authors who are overriding choice.php, so that they can create one script per choiceAdventure number rather than one convoluted script that handles all choices. This will facilitate script sharing, allowing script authors to maintain individual ownership and support for their scripts, and preventing users from getting befuddled by having to maintain some kind of master aggregate script. This has been heretofore impossible using the normal methods because the page must first be visited before we can know which choice it is; but thanks to the magic of sufficiently developed technology we can simply load the page, then, after it's loaded, send the whole HTML body to the appropriately-numbered script, which then alters the body as desired and sends it back to the browser, which replaces the old body with the new one.
To use this script, simply download it into your relay/ directory. Then, anytime you visit a choice page, it will add some nifty jQuery to your HTML that reads the choice number from the page and sends the whole body of the page to choice.XX.ash, and if that returns anything other than an empty string it will replace the body with the new content.
This means that a choice.XX.ash script will operate infinitesimally differently than a normal relay override script. You won't use the parameter-less visit_url(), because the page has already been visited. Instead, the page source will be present in form_fields()["page"]. Also, only the contents of the <body> tag will be present there, rather than all the HTML, so you won't have access to everything in the <head> tag. Fortunately, these limitations are unlikely to be bumped into for most purposes.
As an example of how it works, I've also added a couple of example scripts:
- choice.1067.ash adds some spoilers to Maint Misbehavin' in Barf Mountain.
- choice.1114.ash adds some spoilers to Walford in the Glaciest.
You don't need to download the examples, but they are handy as copy-paste starting points, and are actually also handy as scripts in their own right.
I'm not putting this script on SVN for now as I don't believe it's likely to need any updating. If you would like to publish a choice override that takes advantage of this script, simply add it to your SVN package or direct users here. If this script sees wide enough adoption that it would be beneficial for dependency purposes to be on SVN, then I'll move it there.
Last edited by zarqon; 09-18-2017 at 05:22 AM.
I've also written a library for this.