Firefox features that are only available to full-fledged browser extensions? You can turn your user script into a full-fledged
XPI with just a few clicks, thanks to Adrian Holovaty's amazing Greasemonkey compiler!
Procedure: Compile Butler into a browser extension
Visit the Butler user script source code. From the menu, select Edit → Select All (Ctrl-A) to copy the user script's source code to the clipboard.
Visit the Greasemonkey compiler.
In the “Creator” field, enter
In the “Version” field, enter the current version of the Butler user script (0.3 as of this writing, but check the script's metadata section for the actual version).
Open a new window or tab and visit GUID Generator to generate a random GUID. Copy the GUID to the clipboard, including the curly braces.
Switch back to the “Greasemonkey compiler” page. In the “GUID” field, paste the GUID you got from the GUID Generator.
In the “Homepage” field, enter
Click Create the Firefox extension. Firefox should pop up a dialog titled “Opening butler.xpi”. Select Save to disk and select a directory.
Tada! You now have a version of Butler as a browser extension. Before you install the Butler extension, you should first
disable the Butler user script and verify that it is disabled by searching for something on Google. Then install the Butler extension by selecting File → Open... and selecting the
butler.xpi file you created with the Greasemonkey compiler. Be sure to restart your browser to finish the installation.
.xpi file is really just a ZIP archive with a certain directory structure. You can use any ZIP program (such as 7-zip for Windows or Stuffit Expander for Mac OS X) to decompress the archive and look at the files that constitute the browser extension.
There are four files involved. The two RDF files are mostly Firefox boilerplate. The other two contain the actual code.
- Metadata about the extension itself, including name, version, description, and compatible versions of Firefox.
- Bootstrap code that checks the current URL against the script's
@excludeparameters, and then injects and executes the script.
- More metadata, Firefox boilerplate.
- The original user script's source code.
Basically, the Greasemonkey compiler creates a really, really stripped down version of Greasemonkey that has no user interface and automatically loads a single user script on the appropriate URLs. But now you have all the source files, and you can do anything you want: create custom dialogs, modify preference panes, register menu items outside the User Script Commands menu... go wild!