If you inspect the rendered HTML for a CodeRunner question, you should see the original textarea element with an attribute data-global extra that contains what you want. i think you should be able to modify the scratchpad wrapper code to find that textarea and extract the globalextra code from it. I don't think I've ever done exactly that, though, but give it a go and report back.
Don't forget that there will in general be multiple questions on a page so you need to find the right one.
Don't forget that there will in general be multiple questions on a page so you need to find the right one.