damien.h

Running Greasemonkey scripts on Ubiquity

Mozilla Ubiquity is not only a wonderful command engine and launcher. It can also be used to do stuff what Greasemonkey is good at, manipulating page DOM dynamically, by utilizing the “pageLoad_” function hook. To demonstrate this case I’ve quickly migrated the recently popular Twitter search on Google monkey script onto Ubiquity. You can get the Ubiq version of Twitter+Google search from here.

I retained the original DOM building code, but replaced the Ajax call with a JQuery one along with a couple hacks explained below to get it working from Ubiquity.

First, while Greasemonkey has built-in mechanism for filtering page URLs for selective script invocation, you have to do that on your own with Ubiquity. Look at the first few lines in the Ubiq command for the regex job to filter out Google search addresses.

    var href = doc.location.href;
    var q = (/^https?:\/\/(?:www\.)?google\..*\/.*[&?]q=([^&]*)(?:&|$)/(href)||0)[1];

Secondly, before publishing the script, you have to put such a line of comment in the script in order for Ubiquity to consider it an installable command and trigger the install bar at the top of the page. (Kudos to satyr for pointing out this hack)

//function cmd_

In similar ways, most of the Greasemonkey scripts can be migrated to Ubiquity.