Adding handlers to Operator

Over at labs.mozilla.com you'll see the announcement of a microformats extension I created called Operator. I figured the release of this extension was a good reason for me to start blogging again, since people have questions and comments about the extension. So that's what I'll be doing here.

So far, the response has been great. Here are some posts from LouderVoice blog, microformatique, wizardishungry/blog, guillermoesteves.com, pixelsebi's repository (in German), and Not So Relevant.

So far I think the one thing that everyone has missed about Operator is that it is extensible out of the box. Here's an example.

I got this question on the mozilla.dev.apps.firefox newsgroup:

Will a newer version have a built in mechanism that
will allow me to extend it without it being built
into the operator extension?

For example, I want to add an additional service
such as Yedda.com to show me questions and answers
on a certain tag.

In Yedda's case (and others with similar URL structure)
it simply means the ability to add a parameterized URL
handler so I can define something like:

http://yedda.com/questions/tags/{tags}

as the handler where {tags} will be replaced by the
values of the various rel-tags on the page.

And here's my answer:

Operator already supports this functionality. Check
out the file handler-example.js in the directory where
the extension is called. For yedda, here is what it
would look like:

Microformats.tag.handlers['yedda'] = {
description: "Find questions on Yedda",

action: function(doc, item) {
tag = Microformats.tag.create(doc,item);
url = "http://yedda.com/questions/tags/" + tag.tag;
Microformats.loadUrl(url);
}
};
Save this to a file called "yedda.js" and place it
in a directory called "microformats" in your profile
directory and you have yedda support.

So as you can see, Operator was designed to be extensible out of the box.

I'll go into more detail about the architecture of Operator with my next post. The main thing to remember is that it is NOT a microformats toolbar! It is a microformats architecture that is currently using a toolbar as the UI. I have kept the microformats part separate from the toolbar part.

5 Responses to “Adding handlers to Operator”

  1. Stoyan December 17, 2006 at 11:31 am #

    Thanks for this example and the Operator, Mike! The extensibility is one of the best features.

    This example worked for me with no hiccups, the only thing you may want to add to the instructions is "... and then restart your browser"

    Is there a place where I can check the JS API of the Microformats class.

    Thanks again, amazing work!

  2. Jon Williams January 9, 2007 at 2:14 pm #

    Of course, with this kind of feature, a clearinghouse for extending Operator is needed, like UserScripts.org is for Greasemonkey. Have you talked with the Microformats.org people about providing it? That seems like a logical place.

  3. Peter Rukavina February 13, 2007 at 7:02 am #

    Thanks for this; I used what you provided, added a little detective work, and came up with a new handler for OpenStreetMap, the process of which I documented at:

    http://ruk.ca/w/index.php/Making_an_OpenStreetMap_handler_for_Operator

Trackbacks/Pingbacks:

  1. Mike’s Musings » Adding new microformats to Operator - January 9, 2007

    [...] Creating a handler was already covered in this post, so the main thing we need to see is how to access the hResume we just created. [...]

  2. Mike’s Musings » Operator 0.7 is available - April 4, 2007

    [...] This release introduces a basic user interface for installing user scripts. Note that ability to add user scripts has always been there, I’ve just never had a good UI. User scripts can be used to add new microformats and new actions to Operator. As a part of the introduction of this UI, I’m moving some of what I call the non tier 1 microformats out of the core Operator and made them available as user scripts. My decision as to which ones to remove was mainly based on which microformats fit best into the Operator model; that is to say it is easy to provide actions that relate to the microformat. It is very important for you to realize that user scripts have FULL JavaScript privileges. Do NOT install Operator user scripts unless you trust the people that are providing them. I am going to make all my scripts available at http://www.kaply.com/weblog/operator-user-scripts/. If you want to write your own actions or microformats, feel free to look at my scripts, but please be aware that this API is very much in flux. I don’t a good versioning mechanism right now, so at some point your scripts would cease to work. Note that I continue to support the original Operator action model, but not the original Operator microformats model. The microformats model is actually pretty close to final. [...]

Leave a Reply:

Gravatar Image