Script written and tested in Chrome