Tag Archives: firefox

Ajax Blog Eclipse extension Google Greasemonkey how-to IDE iframe Javascript lifehack procrastination Projects spam spyware web-development WordPress

TinyUrl Trouble: Greasemonkey drops the location header in GM_xmlhttpRequest

I get a lot of ideas. Most of them wander aimlessly in my head until they become obsolete, but once in a while I’ll get an idea that seems useful and simple enough to do in my free time.

If you’ve used Twitter, you’ve seen the myriad of url shortening services like TinyUrl and Bit.ly. Url shortening services are a kludge and they break one useful, built-in feature of the web, which is the ability to know where you’re going when you click a link.

So I thought, this is something that I could fix in an hour or so with a Greasemonkey script. If you have no idea what I’m talking about, Greasemonkey is a Firefox Plugin that runs in your browser and lets you run your own Javascript on pages you load. Greasemonkey comes with a handy-dandy AJAX function called GM_xmlhttpRequest.

I figured all I have to do is grab all the anchors on the page, see if they match a list of shortener urls, do an xmlhttpRequest for each one and grab the final location (after the service finishes with it’s redirecting) from the headers.

Something along these lines:

function getTargetUrl(short_url) {

  GM_log('Getting '+short_url);

  GM_xmlhttpRequest({
      method: 'GET',
      url: short_url,
      headers: {
          'User-agent': 'Mozilla/4.0 (compatible) Greasemonkey',
          'Accept': 'text/html'
      },
      onload: function(responseDetails) {
          GM_log('Done.  Status ' + responseDetails.status +
                ' Text ' + responseDetails.statusText + '\n\n' +
                ' Headers:\n' + responseDetails.responseHeaders);
      }
  });
}

Continue reading

How to link to an individual question in Google Moderator

The Obama administration’s just finished “Open for Questions“, where the President answered questions suggested and voted by the general public over the web. This is pretty cool – political openness, interaction, and democracy via the web. It’s also interesting to me because the site uses Google Moderator, a product we use at work all the time.

What’s not quite so cool is that Moderator apparently doesn’t play well with the rest of the web. I’m not sure why it was designed this way (and if I did know, I probably couldn’t tell you anyway). The design is the exact opposite of unobtrusive javascript. That’s fine for highly interactive web apps but it would be nice to see the mostly text content in Moderator made searchable just like any other collection of web pages.

Continue reading

Creating a Favicon

My site's favicon, blown up to ridiculous proportions Nelson reminded me today that I didn’t have a favicon for this site. I took a few moments and created the amazing little pencil that’s sitting in the address bar above.

For all the non-techies and new webmasters out there who have stumbled across this page, a favicon is the little icon that show up next to a web site’s URL and next to the page’s title in your bookmarks. They’re very small (16 by 16 pixels) but they can add a dash of branding to your site and are a helpful visual signal for bookmark navigation, increasing the information scent.

Want to create your own favicon? You can draw one pixel-by-pixel at this site, but I’d recommend busting out Photoshop and creating one yourself. Try to pick initials, a logo, or an object that can be expressed very simply – I used an apple for Mealographer, for example. You can go as simple as a couple of squares that fit your site’s color scheme and still create a memorable association for your users.

Modern browsers like Firefox allow you to use .gif and .png files directly, with some code like this:

<link rel="shortcut icon" type="image/png href="http://www.jasonmorrison.net/favicon.png" />

That means you can have an animated favicon… just make sure you’re doing it for some useful or artistic purpose, otherwise you will annoy your users.

From what I’ve heard Internet Explorer still has some issues, so you may want to use the older .ico format. This site will convert the image for you.

<link rel="shortcut icon" type="image/ico" href="http://www.jasonmorrison.net/favicon.ico" />

If you want to get really crazy, you can use Javascript to dynamically alter the favicon, which is great if you want to play Defender on the smallest display ever.