This script basically lies in wait. Once activated, the script does the following:
The failsafe of 5 tries is there for whatever server you come against which requires either auth (you shouldn't be running the script then anyway) or some special login first before grabbing master, and avoids the spam.
Add it to your autoexec.cfg, or whatever other file you have for placing stuff in.
To run it, just do /wrapper.
OR bind it to some key of your choosing. (bind "key" wrapper).