You were actually quite close. You just need to put it this way:
javascript:(function(){mycode})();
In your example, you can try this:
javascript:(function(){function text(){this.type="text"};function password(){this.type="password"};function addHandlers(){var e=false;var t=document.evaluate("//input[@type='password']",document,null,6,null);for(var n=t.snapshotLength-1,r;r=t.snapshotItem(n);n--){if(!e){r.addEventListener("mouseover",text,false);r.addEventListener("mouseout",password,false)}else{r.addEventListener("focus",text,false);r.addEventListener("blur",password,false)}}};addHandlers()})();
Please pay attention to semicolons when you minify your code, you were missing some of them.