I can't think of a script, but if you're willing to ssh to the localhost, that could work for passwordless access.
Make sure your user has an ssh key generated via:
Press enter throughout the prompts, the key here is to not enter a password, rather, have a blank password. Once this is done, copy the ssh id to the root profile so it has the matching key for authentication
Then to escalate without a password - ssh root@localhost.
If that's too much typing, put it in a bash shell with a short name in your bin directory. I just tested and it works
(You'll need the openssh-clients package for commands such as ssh-copy-id, just fyi)