All | 43 Folders | Accessibility | BoingBoing | Books | Computer Related | Family | Films | General | Hacking | Hobbies | Humor | Java | Links | Omni | OpenSolaris | Puzzles and Games

« Previous day (Feb 4, 2008) | Main | Next day (Feb 6, 2008) »
20080205 Tuesday February 05, 2008

Working GreaseMonkey Script to Firefox Extension Conversion

See the previous post for the background to this. Thanks to Tyler Trafford for pointing me in the direction of a working GreaseMonkey script compiler.

I first checked it out of SVN with:

  $ svn co http://svn.devjavu.com/greasemonkey/branches/compiler

I then successfully build a Firefox extension for my Lists of Bests GreaseMonkey script with:

  $ cd /home/richb/DVD/GreaseMonkey/compiler/xpi-build
  $ ./gm2xpi.rb "Rich Burridge" "http://blogs.sun.com/richb" "0.5" \
      "4d52f0b8-eaed-4d5f-9c2e-e2ec19510737" \
      /home/richb/DVD/GreaseMonkey/rich_stuff/listsofbests/listsofbests.user.js

This generated a Lists of Bests Firefox Extension which I installed and successfully tested with a sample list.

[]

[]

( Feb 05 2008, 02:16:10 PM PST ) [Listen] Permalink

Trying To Convert A GreaseMonkey Script Into A Firefox Extension

To save potential users of my GreaseMonkey scripts having to first install GreaseMonkey, I thought I'd investigate how easy it was to automatically turn them into Firefox extensions.

I came across two potential solutions and failed with both of them.

The first one was written almost three years ago and clearly states on the blog entry that "there's no support yet for the proprietary Greasemonkey JavaScript functions", but I was curious to see what would happen.

I had to change the minimum and maximum Firefox versions supported in the script. From this, running:

% python greasemonkey_compiler.py

creates a Google Suggest Firefox extension which I was able to install and successfully run.

I then wrote a simple script to take one of my existing GreaseMonkey scripts and convert it to a Firefox extension. There is a small configurable section, so it could easily be adjusted to read and convert any GreaseMonkey script. Note that this is a Quick Hack. If I was writing a proper application I'd find a nicer simpler way of getting the user's input parameters.

#!/usr/bin/env python
#
# make_ext.py - v0.1
#
# Copyright (c) 2008 - Rich Burridge - Sun Microsystems Inc.
# All Rights Reserved.
#
# Usage: python make_ext.py
#
# Script to turn a GreaseMonkey script into a Firefox extension.
# It uses the GreaseMonkey compiler written by Adrian Holovaty
# (http://www.holovaty.com).
#
# Compiler source code originally at:
# http://www.letitblog.com/code/python/greasemonkey.py.txt
#

from greasemonkey_compiler import UserScript

# ----- Start of configurable section -------

grease_monkey_script_name = "listsofbests.user.js"
extension_name            = "listofbests.xpi"

creator  = u'Rich Burridge'
homepage = u'http://blogs.sun.con/richb/'
version  = u'0.5'
guid     = u'{4d52f0b8-eaed-4d5f-9c2e-e2ec19510737}'

# ----- End of configurable section -------

if __name__ == "__main__":
    fin = open(grease_monkey_script_name, 'r')
    gm_script = fin.readlines()

    e = UserScript("".join(gm_script), creator, version, guid, homepage)
    f = open(extension_name, 'w')
    e.write_xpi(f)
    f.close()

This happily generated a listofbests.xpi file which I was able to install, but when I went to a sample Lists of Best book list, nothing seemed to happen and Firebug didn't report any problems.

I then removed that extension, restarted Firefox and tried the second one. I pasted in the same listsofbests.user.js script and the online web page generated a listsofbests.xpi extension.

After installing it and restarting Firefox, when I went to the same sample list, an alert dialog came up with:

Error: missing } after function body

Unfortunately I don't know PHP at the moment, so I'm unable to debug it.

Oh well, enough for one day. Back to RealWork™

[]

[]

( Feb 05 2008, 09:37:11 AM PST ) [Listen] Permalink Comments [7]