Teleporter – From Greasemonkey to Self-Contained Extension


p>My previous post outlined Domain Teleporter, a first attempt at a GM script. Continuing the experimentation (as I have a comlpetely different real example in mind), I wanted to see how easy it was to create a self-contained FF extension from the GM script … I figure there’s a significant population who have FF and can’t or don’t want to install Greasemonkey, even if this leads to a functionally trivially extension.


p>Converting a Greasemonkey script to a Firefox extension was stupidly simple, thanks to an online tool, Anthony Lieuallen’s User Script Compiler. I’d read about it a while ago, and assumed there must be some catch, but the conversion was indeed child’s play … enter your name and homepage, cut-and-paste the script, and submit. The XPI pops out immediately as a binary download.


p>FWIW, the extension is published here; I used htaccess in the distro directory to ensure it will be an installable download (so it can be installed immediately, as opposed to saved locally) as follows:

AddType application/x-xpinstall xpi

The Richer Plugin pattern talks about the importance of FF extensions and the like.

BTW The extension is Amazon Teleporter, not Domain Teleporter, because there’s no longer any way to change the default “Amazon*” domain for which it applies – GM supports that sort of thing as a built-in feature; whereas an extension would have to implement it manually … a lot more work, requiring a custom-made options dialog and a persistence mechanism.

Domain Teleporter – Greasemonkey Script

Update: As an experiment, converted this into a Firefox extension (Blog Article, Extension homepage)

DomainTeleporter, my first Greasemonkey script, is related to this blog post from last April:

If you shop at, you’re often out of luck when it comes to reader comments. So I often find myself editing the URL, switching back and forth between and .com. Luckily, this transatlantic adventure usually works out, as the crazy Amazon IDs match.

Domain Teleporter flips the location between .com and, retaining the rest of the URL. It would be nice to make it more generic – switch to an (quasi) TLD – but that would require more regexp parsing than was necessary here. Incidentally, I’d like to see a JS library that munges URLs – extract out the domain, the path, etc.

The script is configured to only run on Amazon, but you might find it useful with other sites too, in which case, change the applicable domains using the GM dialog.

Writing the GM script was fairly straightforward, began by copying Mark Pilgrim’s “Hello World”. It’s standard JS for the most part, but there was one gotcha: events don’t usually work with the usual, portable, solution of “control.onclick()” – you get a “component not found” error. You must instead use addEventListener().