Hacking Gmail

(Grace) #1

108 Part II — Getting Inside Gmail


Listing 6-2(continued)

}

function _gd_button_event() {
try{
setTimeout(_gd_place_delete_buttons, 333);
gd_place_delete_buttons();
} catch(e) {
gd_dumpErr(e);
}
}

var s=window.document.location.search;
dump(‘Load gmail page: ‘+s+’\n’);
if (s.match(/\bsearch=(inbox|query|cat|all|starred|sent)\b/)
||
( s.match(/view=cv/) && !s.match(/search=(trash|spam)/) )
) {
dump(‘==== Apply Gmail Delete Button to: ====\n’+s+’\n’);
//put the main button in
try{_gd_place_delete_buttons();}catch(e){dump(e.message);}

//set events to try adding buttons when the user does
things
//because gmail might create new places to need buttons.
window.addEventListener(‘mouseup’, _gd_button_event,
false);
window.addEventListener(‘keyup’, _gd_button_event, false);
}

})();

Again, without going into JavaScript too deeply, there are two things to note here.
The first is how it draws a new button into the page. The second is that the script
checks the language the interface is being displayed in and labels the button
accordingly. Very pleasingly done.

GmailSecure


Mark Pilgrim’s userscript, GmailSecure, found at http://userscripts.org/
scripts/show/1404and in Listing 6-3, has a simple function: to force Gmail to
use HTTPS instead of HTTP.
Free download pdf