Adding Persistent Searches to Gmail #
Update on 12/23/2005: The script has been updated to be compatible with Firefox 1.5. See this entry for more information.
Persistent searches (a.k.a. smart folders or saved searches) seem to be the feature du jour of email clients. Thunderbird has them, Evolution has them, and Mail.app soon will. On the other hand, Gmail is the web mail app to use. While one doesn't normally think of web apps as having such advanced power user features, it recently occurred to me that it should be possible to add persistent searches to Gmail:
- If you haven't already, install the excellent greasemonkey Firefox extension.
- Open up this user script (in Firefox).
- From the "Tools" menu, select "Install User Script.." and confirm all of the various prompts.
- Go to your Gmail account (some refreshing may be necessary).
- There should now be a "Searches" box on the left size, below the "Labels" and "Invite a friend" ones.
- Clicking on a search executes the saved query. To refresh result counts, click on the refresh icon in the upper right corner.
- Use the "Edit searches" link to customize your persistent searches.
- As a bonus feature, all threads now have a "Toggle font" link which switches the message font to a fixed size one - great for reading source code.
There are some caveats. Saved searches are stored in a cookie. This means that you cannot easily share them between computers. Ideally this could be remedied by storing the searches within Gmail itself (perhaps as a dummy contact or a special filter), but I'm not quite sure how to do that yet. Furthermore, result counts may not be accurate beyond a certain limit (e.g. Gmail itself reports "about 80" results when there are in fact 77). In general, the smaller the result size, the more accurate the search is.
The user script has a pretty straightforward implementation. It looks for the "Labels" box, and if it finds one, it inserts a "Searches" one. As previously mentioned, I store all the searches in a cookie. To actually perform a search, I created a an XMLHttpRequest
object and use it to fetch the search results for each saved search. The response contains in it the total number of messages that matched the query. It would've been nice to use the DOM (and then a JavaScript eval()
) to parse it, but this turned out to be more difficult than expected (XMLHttpRequest
only provides a parsed DOM for XML documents).
Rather than specifying all of the CSS properties inline or via the JavaScript style
object, an approach which separated appearance from structure was used. Effectively, a style sheet was embedded into the user script and inserted upon initialization. This style sheet was also used for the toggling of the font (the message body always appears to be in a <div>
of class mb
). It also has the advantage of making the script self-contained, since it doesn't depend on an external CSS file. Also for the same goal of encapsulation, the font toggling icon was embedded in the script itself via a data: URL (generated with hixie's tool).
Disclaimer: I happen to work for Google. This script was produced without any internal knowledge of Gmail, and is not endorsed by Google in any way. If you have any problems with it, please only contact me.
44 Comments
I have a very very small correction for your script. Just to say I'll correct someone from google once.
When you specify the class for the div where you put the image for toggle font and the text itself, you specify the class as 'al'. When it should be specified as 'ar'. Couse of this the link gets a little bit above where it should be.
Just change the line 544 as follow and it should be fine.
toggleFontLink.className = "ar";
Great script thanks.
1: I'm using FireFox 1.5. I don't know if it's been tested on 1.5 or not, or whether this would cause any issues
2: Google may have changed the name of the labels panel that your script is looking for. They've done it before and it would very well explain what I'm seeing
3: I'm in the UK, so Google have put up a slightly different page. As far as I know, the only real difference is that they are thinking of a domain change to googlemail.co.uk because there's already a gmail.co.uk which has confused users of both systems as well as invited a lawsuit.
Personally I reckon that they've just changed the name of that element. Is anyone else having the same trouble?
Anyway, I *kinda* fixed it: http://home.arcor.de/deckman/gmailtweaks.user.js
It's not beautiful or anything, but it's working for me. I couldn't get the result count to work though. (stupid XPCNativeWrapper)
thanks again, this is really great.
Thanks for updating everything... I'm now finally using Fx1.5 since all of my preferred customizations are available!
http://kay.smoljak.com/archives/?persistent-searches-in-gmail
But as of this morning, it's no longer working. I'm assuming that Google have changed something in the code that's stopping the script from running. It's the only Greasemonkey script that's enabled in my browser (FF 1.5.8). I'm totally stuck without my saved searches!
Is anyone else having the same problem?
I really waiting for fixing bugs
http://lukebaker.org/archives/2005/05/25/persistent-persistent-searches/
Couldn't you use his code specific to that to update your most recent one to do the same? (I love both, but haven't figured how to bring the searches in my contact list from his, into your newest script).
Thanks. This is great. One question: in the "Muted but unread" search, what does the label "^g" mean?
Thanks.
Len
Seems you removed the result count?
I prefer to have the recent searches sorted with the most recent one on top. Perhaps you'd consider adding an option for this?
Until then, this is a unidiff to reverse the sorting: http://pastie.textmate.org/48861
Just one question that I can't seem to figure out. How do I create a search to look for all unread messages in my Sent Mail?
Could you make the searchbox into a list instead with greasemonkey? then you wouldn't need the links inte the sidebar which take up space.
Just a thought...
Now that google has updated their gmail, lifehacker was forced to upgrade "Better Gmail" to "Better Gmail 2"... however, your script... one of my favorites, was gone. I loved it. Please please update it to work with better gmail, and the updated (newer) version of gmail!
Thank you for your hard work!
Just to let you know that it doesn't work anymore since latest Gmail update. One can still use it by choosing to use the older version though.
Thanks for this great script...
I am sure you have already noticed but it doesn't work with the new Gmail layout (I call it the "glossy" Gmail)... it still works if I select "Older version" from the top right of the page. It still works on my Gmail hosted domain which has the old layout. Is there an easy fix for this?
I also wanted to know what "Add Focus" and "Muted but unread" meant.
Again, thanks for this great script! Now I am completely free of desktop clients.
any plans on an update?
i miss having my saved searches available.
Please please please convert it to make it work with the new GMail! Thanks!!
it adds a few more clicks but it's not difficult to use
Post a Comment