GMail POP3 Quick Checker

By Tim Smart Last update Oct 26, 2009 — Installed 5,660 times.

There are 8 previous versions of this script.

// ==UserScript==
// @name           GMail POP3 Quick Checker
// @namespace      http://userscripts.org/users/tim
// @description    Add's a link next to 'Refresh' to quickly check all POP3 Accounts
// @include        http://mail.google.com*
// @include        https://mail.google.com*
// @require        http://updater.usotools.co.cc/51516.js
// @require        http://userscripts.org/scripts/source/56812.user.js
// ==/UserScript==

function clickElement( element ) {
	var clickEvent = document.createEvent("MouseEvents");
	clickEvent.initMouseEvent( "click", true, true, document.defaultView, 1, 0, 0, 0, 0, false, false, false, false, 0, null );
	element.dispatchEvent( clickEvent );
}

var navigating = false;

GMailAPI({
	onViewChange: function() {
		if ( this.viewType === 'tl' ) {
			var divs = this.viewElement.ownerDocument.evaluate( ".//div[@act='20']", this.viewElement, null, 7, null );
			for ( var i = 0, div, refreshCont, refreshLink; div = divs.snapshotItem( i++ ); ) {
				if ( div.added === true )
					return;

				refreshCont = document.createElement('div');
				refreshLink = document.createElement('div');
				refreshCont.className = div.parentNode.className;
				refreshLink.className = div.className;
				refreshLink.appendChild( document.createTextNode('Refresh POP3 Accounts') );
				refreshCont.appendChild( refreshLink );

				refreshCont.addEventListener( 'click', function() {
					if ( top.location.hash && top.location.hash.length > 1 )
						navigating = top.location.hash;
					else
						navigating = true;

					top.location.hash = '#settings/accounts';
				}, false );

				div.parentNode.parentNode.appendChild( refreshCont );
				div.added = true;
				refreshLink = refreshCont = null;
			}
			divs = null;
		}
		else if ( this.viewType === 's' ) {
			if ( navigating === false )
				return;

			var links = this.viewElement.ownerDocument.evaluate( ".//span[@role='link' and @class='rP sA']", this.viewElement, null, 4, null );
			for ( var link; link = links.iterateNext(); )
				clickElement( link );

			top.location.hash = navigating === true ? '#inbox' : navigating;
			navigating = false;
		}
	}
});