Created
June 4, 2009 13:57
-
-
Save csamuel/123629 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment