Webmail Auto-Login

By Mads Hansen Last update Feb 17, 2009 — Installed 632 times. Daily Installs: 0, 1, 0, 0, 0, 0, 0, 0, 6, 0, 0, 9, 0, 0, 2, 0, 0, 0, 0, 2, 0, 3, 1, 5, 0, 2, 0, 2, 1, 0, 1, 0

There are 1 previous version of this script.

// ==UserScript==
// @name          Webmail Auto-Login
// @namespace     https://webmail.bah.com
// @description	  Automatically login to webmail
// @include       https://webmail.bah.com/
// @include       https://webmail.bah.com/owa/auth/logon*
// @include       https://webmail.bah.com/exchweb/bin/auth/owalogon*
// @include       https://webmail.bah.com/CookieAuth.dll?GetLogon?*
// ==/UserScript==
// Notes:
//   * is a wildcard character
//   .tld is magic that matches all top-level domains (e.g. .com, .co.uk, .us, etc.)

(function() {
var form = document.forms.namedItem("logonForm");
var owaUsername;

//Username may already be set
if(form.elements.namedItem("username")!=null){
	owaUsername = form.elements.namedItem("username");
}
var owaPassword = form.elements.namedItem("password");
var loginFlag = true;

//Register a function that will collect login info, and store in GM using GM_setValue()
   window.setLogin = function(event){
      	loginFlag=false;
  		
  	owaUsername=prompt("Enter your username");
  	GM_setValue("owaUsername", owaUsername);
  	owaUsername=GM_getValue("owaUsername",false);
  
  	 owaPassword=prompt("Enter your password");
  	GM_setValue("owaPassword", owaPassword);
  	owaPassword=GM_getValue("owaPassword",false);
  
  	loginFlag=true;  
  	event.preventDefault()
   } 

//Create a button for users to set/clear login info  
   var links = document.createElement("a");
    links.innerHTML = '<div id="owaSetAuth" style="cursor: pointer; border-style:outset;border-color:#AAAAAA;width:280px;margin:5px;font-size:large;text-align:center;background-color:#EFEFEF; height:30px;color: #000000;"><p style="margin: 2px 2px 2px 2px;">Set/Change Login Info</div>';
    links.addEventListener('click', setLogin, true); 
    document.body.insertBefore(links, document.body.firstChild);	
	
//Function that will login	 
   window.owaLogin = function(){ 
	   	if(!(GM_getValue("owaUsername",false)==false) && !(GM_getValue("owaPassword",false)==false) && loginFlag==true){
			//Only attempt to set username if login form variable is available, to prevent error
			if(form.elements.namedItem("username")!=null){
				owaUsername.value = GM_getValue("owaUsername",false);
			}
	   		owaPassword.value = GM_getValue("owaPassword",false);
	   
			form.submit();
		}else{
		    //alert("Username:" + GM_getValue("owaUsername",false) + " Password:" + GM_getValue("owaPassword",false));
		    setTimeout(owaLogin,2000);
		}
    }
    //call owaLogin onLoad, pausing in case user wants to set/change username/password first
    setTimeout(owaLogin,1500);
})();