Adventures in jQuery and Greasemonkey

I just got a copy of a great book from a friend about jQuery and Greasemonkey. These two tools form the basis for a good deal of the duct-tape and glue of the Internet. It's time to hack me together some goodness. I'll take a closer look at this tonight and see if I can put something together.

The tentative project plan is to write a Greasemonkey script to handle the different URL shorteners and show you the full URL inline. This seems like it shouldn't be too challenging. The steps are straightforward:

for each link in the document...
 examine the URL
 is it a link from a known URL compressor?
 if so:
  decompress the URL using a method specific to each compressor
  append the URL of the decompressed link to the body of the <a> tag

The highest complexity is probably in the second-to-last line, where a particular URL is decompressed. For example, TinyURL is decompressed differently from is.gd. Each site will have its own decompression method, so this needs to be different for each URL we support. In practice, though, this also looks like it will be pretty simple:

look up the appropriate compressor as a key in a map
use part of the corresponding map value as the URL for a GET request
use another part of the corresponding map value to identify the redirection URL
make the GET request
identify the redirection URL from the resulting page
save the identified result

Effectively, we'll make a map of each compressor we support to a tuple containing that compressor's "preview URL" and a signature that tells us where to expect the answer on the preview page. Then we make a GET request for each match we find on supported URLs and save the results. Good stuff!

Trackbacks (none)

TrackBack URL: http://distilledb.com/mt/mt-tb.cgi/12

leave new comment