GMail 'Archive' and 'Delete' next conversation.

By Tim Smart Last update Sep 1, 2009 — Installed 1,099 times. Daily Installs: 2, 4, 2, 4, 5, 4, 3, 7, 2, 2, 5, 3, 1, 2, 0, 0, 0, 1, 1, 15, 7, 2, 2, 1, 3, 6, 2, 0, 2, 3, 4, 3

There are 6 previous versions of this script.

// ==UserScript==
// @name           GMail 'Archive' and 'Delete' next conversation.
// @namespace      http://userscripts.org/users/63868
// @description    Instead of returning to the Inbox after archiving or deleting a conversation, you switch to the next one in line.
// @include        http*mail.google.com*
// @require        http://updater.usotools.co.cc/37986.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 );
}

GMailAPI({
	onViewChange: function() {
		if ( this.viewType === 'cv' ) {
			 var olderLink = this.viewElement.ownerDocument.evaluate( ".//span[contains(.,'Older') and @role='link']",
			 		this.viewElement, null, 9, null ).singleNodeValue,
			 	buttons = this.viewElement.ownerDocument.evaluate( ".//div[(contains(.,'Archive') or contains(.,'Delete')) and contains(@class,'goog-imageless-button ')]",
			 		this.viewElement, null, 7, null );

			for ( var i = 0, button; button = buttons.snapshotItem( i++ ); ) {
				if ( button.usoAdded !== true )
					button.addEventListener( 'mouseup', function() {
						if ( olderLink )
							clickElement( olderLink );
					}, false );
				button.usoAdded = true;
			}
		}
	}
});