Show me the code! – By Davanum Srinivas

November 9, 2007

Greasemonkey GMail shortcuts (Stopgap for the broken GMail saved searches)

Filed under: Uncategorized — Davanum Srinivas @ 12:07 am

Latest GMail user interface updates broke Mihai’s brilliant Saved Searches Greasemonkey script among others. Others have begg^H^H^H^Hasked Mihai to bring back that script. I’d be very happy to beg him to do the same as well.

In the mean while, here’s a humble newbie script to get people going…This is probably the second Greasemonkey script using the new the semi-official docs.
Install GMail shortcuts Script

UPDATED: 10:52 AM EST 11/09/2007 – Slightly better looking drop down

// ==UserScript==
// @name          GMail with Preconfigured Search ShortCuts
// @namespace     https://davanum.wordpress.com/
// @include       http://mail.google.com/*
// @include       https://mail.google.com/*
//by Davanum Srinivas (https://davanum.wordpress.com/)
// ==/UserScript==

const optSiteMap = {
    'me': 'davanum OR dims',
    'jira': 'subject: \"[jira]\" ',
    'geronimo': 'geronimo',
    'unread': 'is:unread',
    'moderate': 'subject:MODERATE in:inbox',
    'geronimo': 'from:geronimo OR to:geronimo',
    'harmony': 'from:harmony OR to:harmony',
    'incubator': 'from:incubator OR to:incubator',
    'jakarta': 'from:jakarta OR to:jakarta',
};

window.addEventListener('load', function() {
    if (unsafeWindow.gmonkey) {
        unsafeWindow.gmonkey.load('1.0', init)
        }
}, true);

function init(gmail) {
    var dropdown = gmail.getNavPaneElement().ownerDocument.createElement('select');
    with(dropdown.style) {
        id = 'myShortCutID';
        name = 'myShortCutDropDown';
        position = 'absolute';
        zIndex = 1000000;
        // Make sure it's on top
        color = 'blue';
        fontFamily = 'arial,helvetica,sans-serif';
        fontSize = '80%';
    }

    dropdown.addEventListener('change', function(evt) {
        if (dropdown.selectedIndex > 0) {
            window.location.hash = '#search/' + encodeURIComponent(optSiteMap[dropdown.value]);
        }
    }, false);

    var opt = document.createElement('option');
    opt.appendChild(document.createTextNode('Shortcuts'));
    dropdown.appendChild(opt);
    for (lbl in optSiteMap) {
        opt = document.createElement('option');
        opt.appendChild(document.createTextNode(lbl));
        dropdown.appendChild(opt);
    }

    var module = gmail.addNavModule('', '', 'rgb(143,188,143)');
    module.getTitleElement().appendChild(dropdown);
}

1 Comment »

  1. This script is like the old Saved Searches one:

    http://userscripts.org/scripts/show/20214

    Comment by Andrin von Rechenberg — January 14, 2008 @ 1:27 pm


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: