Returning to this I made a couple quick mods to ui_scratchpad.js (modded version attached)
It now allows for the insertion of code from the global extra field using {| GLOBAL_EXTRA |} similar to the existing {| ANSWER_CODE |} and {| SCRATCHPAD_CODE |} functionality.