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 Amazon.co.uk, 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 .co.uk and .com. Luckily, this transatlantic adventure usually works out, as the crazy Amazon IDs match.

Domain Teleporter flips the location between .com and .co.uk, 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().

2 thoughts on Domain Teleporter – Greasemonkey Script

  1. Regarding the basics, there is already some rather decent URL handling mechanics available. (url=document.createElement(‘a’)).href=’/fie?foe#fum’; lets you pick url.pathname, url.hostname, url.search, url.hash and so on, giving easy access to all the data of urls just as the objects in the document.links array.

  2. Thank you for this extension… I juste modified the script to use the german and french amazon sites too (I’m Swiss and mainly buy my CDs from those two sites…)

    If you’re interested by the modification, ask me… but this is juste To do that I just some || to your if statements. Nothing very brilliant…

    So thank you, I was looking for this for months!

Leave a Reply