GMail Auto Login & Secure Connection Forcer

By JoeSimmons Last update Jul 2, 2009 — Installed 1,298 times. Daily Installs: 0, 1, 1, 1, 0, 0, 2, 3, 2, 2, 0, 1, 2, 0, 4, 1, 1, 3, 4, 0, 0, 1, 1, 2, 2, 0, 1, 2, 0, 1, 4, 2

There are 8 previous versions of this script.

// ==UserScript==
// @name           Gmail Auto Login & Secure Connection Forcer
// @description    Auto logs into Gmail for you if Firefox remembers your password. Switches to a secure connection if you're not using one. Even allows the saving of passwords by turning autocomplete on.
// @namespace      http://userscripts.org/users/23652
// @include        https://www.google.com/accounts/ServiceLogin?service=mail*
// @include        http://www.google.com/accounts/ServiceLogin?service=mail*
// @copyright      JoeSimmons
// @version        1.0.5
// @license        Creative Commons Attribution-Noncommercial 3.0 United States License
// ==/UserScript==

if(window.location.href.indexOf('http://')==0) window.location.replace(window.location.href.replace(/^http:\/\//, 'https://'));
var username = GM_getValue('gm_un', '');
var password = GM_getValue('gm_pw', '');
if(!/^https?:\/\/www\.google\.com\/accounts\/ServiceLogin\?service=mail/.test(location.href)) return;
if(username=='' || password=='') options();

// Get ID
function $(ID) {return document.getElementById(ID);}

// center by JoeSimmons
// Instructions: Supply an id string or node element as a first argument
function center() {
var node = $('timer_box');
if(!window || !node || !node.style || node.style.display=='none') {return;}
var style = node.style;
style.display = 'block';
style.top = Math.floor((window.innerHeight/2)-(node.offsetHeight/2)) + 'px';
style.left = Math.floor((window.innerWidth/2)-(node.offsetWidth/2)) + 'px';
style.opacity = '1';
}

// Create by avg, modified by JoeSimmons
function create(a,b) {
	var ret=document.createElement(a);
	if(b) for(var prop in b) {
		if(prop.indexOf('on')==0) ret.addEventListener(prop.substring(2),b[prop],false);
		else if(prop=="kids" && (prop=b[prop])) {
			for(var i=0;i<prop.length;i++) ret.appendChild(prop[i]);
		}
		else if('style,accesskey,id,name,src,href'.indexOf(prop)!=-1) ret.setAttribute(prop, b[prop]);
		else ret[prop]=b[prop];
	}  return ret;
}

function options() {
var gm_un = prompt('Username to remember');
var gm_pw = prompt('Password to remember');
if(gm_un && gm_pw && gm_un!='' && gm_pw!='') {
GM_setValue('gm_un', gm_un);
GM_setValue('gm_pw', gm_pw);
if(confirm('Reload to apply changes?')) window.location.reload();
} else if(confirm('Invalid username/password. Retry?')) options();
}

window.addEventListener('load', function(){
document.body.appendChild(create('div', {id:'timer_box',style:'border:2px solid #008ED2; background:#EAEAEA; color: #464646; font:18px tahoma; padding:20px; -moz-border-radius:6px; position:fixed; opacity:0; top:0; left:0; width:50%; height:20%; display:block; z-index:9999999;',kids:new Array(
create('span', {id:'timer_span',textContent:'Logging on in: 3...',style:'display:block;'}),
create('input', {type:'button',value:'Cancel',style:'border:1px solid #464646;color:#464646;background:#EAEAEA;-moz-border-radius:4px;margin:6px;',onclick:function(){
	clearInterval(si);
	$('timer_box').style.display='none';
	}})
)}));
center();


var s = document.getElementsByName('signIn')[0],
	n = $('Email'),
	p = $('Passwd');
if(!s || !n || !p) return;

function countdown() {
if(i>0) {
$('timer_span').textContent = 'Logging on in: '+i+'...';
i--;
} else {
clearInterval(si);
$('timer_span').textContent = "Logging in now!";
if(s && n && p) {
n.value = username;
p.value = password;
s.click();
}
}
}

var i=3, si=setInterval(countdown, 1000); countdown();
window.addEventListener('resize', center, false);
}, false);

GM_registerMenuCommand('Gmail Auto Login Options', options);