Thursday, November 8th, 2007

Gmail adds Greasemonkey Helper API

Category: Google, Library

We discussed the Gmail facelift (or is it a backlift?) last week. Subtle features have been noticed, and one is particularly cool for expert users.

There have always been many Greasemonkey scripts to tweak your Gmail experience. You spend a lot of time in email, so it makes sense that you would want to optimize your world. It is fantastic that the Web has a way to do that. Google employs the Greasemonkey author, the author of two Greasemonkey books, and the author who put in some of the most widely used userscripts, so it only makes sense that we would put in some effort here. The effort shows in an experimental API to allow for easy monkeying around.

Basically, you can programatically load up a helper object that gives you nice hooks into the Gmail API. The following script demonstrates how to load and reference the gmonkey bindings. It will add a nav box to Gmail that updates with the the current view type:

javascript

  1. window.addEventListener('load', function() {
  2.   if (unsafeWindow.gmonkey) {
  3.     unsafeWindow.gmonkey.load('1.0', function(gmail) {
  4.       function setViewType() {
  5.         var str = '';
  6.         switch (gmail.getActiveViewType()) {
  7.           case 'tl': str = 'Threadlist'; break;
  8.           case 'cv': str = 'Conversation'; break;
  9.           case 'co': str = 'Compose'; break;
  10.           case 'ct': str = 'Contacts'; break;
  11.           case 's': str = 'Settings'; break;
  12.           default: str = 'Unknown';
  13.         }
  14.         module.setContent(str);
  15.       }
  16.       var module = gmail.addNavModule('View Monitor');
  17.       gmail.registerViewChangeCallback(setViewType);
  18.       setViewType();
  19.     });
  20.   }
  21. }, true);

This is a nice pattern that I hope other sites fall into. Not only giving APIs to their site in traditional forms, but also letting the experts tweak their wares via gmonkey objects.

Posted by Dion Almaer at 7:07 am
1 Comment

+++--
3.6 rating from 23 votes

1 Comment »

Comments feed TrackBack URI

This API encourages the use of damn unsafe coding practices as simple as “in a gm script, never call a page’s functions”.

The short story: there’s a reason, why “unsafeObject” has this name.

The long story is on my blog: http://maltekraus.de/blog/english/why-the-gmail-greasemonkey-api-is-evil-52.html

Comment by malte — November 8, 2007

Leave a comment

You must be logged in to post a comment.