whatspop - Kunal Anand

Hacking up Gmail macros for pagination

12/25/2007

I have spent the last few days cleaning out my Gmail with a little help from Mihais' macros. I love spelunking through email using nothing but the keyboard - it takes me back to my Stanford days when I mucked around with Pine.

Despite the shortcuts, one thing has continuously irked me about Gmail - having to use the mouse to paginate. So, I hacked up Mihai's script to do pagination from the keyboard (using 1/2). Simply copy/paste the following blocks into 'actions':

// 1: older page for all mail
49: function() {
currentPage = GrabCurrentAllMailPage();
if (currentPage >= 2) {
window.location.hash = "#all/p" + (currentPage-1);
}
},

// 2: newer page for all mail
50: function() {
currentPage = GrabCurrentAllMailPage();
if (currentPage)
{
window.location.hash = "#all/p" + (currentPage+1);
}
else
{
window.location.hash = "#all/p2";
}
}

As you can see, both of those actions depend on the following helper function:

// Check the url for a pagination link - if you see /p# extract the #
// I should get a bit smarter and check the current page to do inbox routing
function GrabCurrentAllMailPage() {
var pageArray = window.location.hash.match(/^(.*)(\/)(p)([0-9]+)(.*)$/);
// If there is no hash, or the regex fails, then test for properties
if (pageArray)
{
if (pageArray.length != 6) {
return 1;
}
else {
return parseInt(pageArray[4]);
}
}
}

I had previously used -/+ for pagination, but the - key code is 0 - which was getting in the way of deleting, which is #. Oddly, that key code is also zero. Is it because of the shift key modifier?

Note, you must be on the all mail page for this to work properly. If you hit next page from the inbox, you will be routed to page 2 of all mail. Yeah, this is a bug and the code is totally ugly, but it's Christmas and I just want to read/clean my mail.

Happy holidays to all!

About I am currently a Senior Engineer at MySpace. Feel free to check out my personal collective.

Archives
April 2005
May 2005
June 2005
July 2005
August 2005
September 2005
October 2005
November 2005
December 2005
January 2006
March 2006
April 2006
May 2006
June 2006
July 2006
August 2006
September 2006
October 2006
November 2006
January 2007
February 2007
April 2007
November 2007
December 2007
January 2008
March 2008
April 2008
May 2008
June 2008

Subscribe to my feed