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!