May 282011

Whilst browsing for movies on Netflix this weekend, I started to ponder why they didn’t offer the ability to apply more complex filters to their browsing experience, akin to letting the user generate their own database queries for what they’re interested in seeing. Netflix is certainly technically capable. Rather than jumping over to their blogs to pose such a question, which would probably end up unanswered, I took it upon myself to put together a small little jQuery script, that when executed via the Firefox extension GreaseMonkey, would offer the user two things to improve their browsing experience:

  1. The ability to hide movies Netflix presumes we won’t like. After all, if Netflix presumes we won’t like them, and you’ve given them enough data points (ratings), then isn’t it technically a waste of time to look at them?
  2. The ability to hide movies that were made before 2000. Yes I know, what a horrible thing to do, for there are tons of masterpieces before the year 2000, but I’m particularly picky about production quality and enjoy the faster pace of today’s movies.

jQuery Script

// ==UserScript==
// @name           Netflix - Show me the good stuff!
// @namespace      http://ChristopherBallLLC.com
// @include        http://*netflix.com/*
// @require        http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js
// ==/UserScript==

// ==Credits==
// Author          Christopher M. Ball
// Website         http://ChristopherBallLLC.com
// Date Authored   5/28/11
// Version         1.0
// ==/Credits==

$(function(){
	//When browsing in gallery or sortable list mode, hiding all movies (or movie rows) with a best guess rating of anything less than 3 stars.
	$("[class*=sbmf-1]").closest(".agMovie").hide();
	$("[class*=sbmf-2]").closest(".agMovie").hide();

	//When browsing in sortable list mode, hiding all movie rows made before the year 2000.
	$(".year").each(function(){
		if ($(this).text().toString().search(new RegExp(/1(8|9)\d\d/i)) != -1)
			$(this).closest(".agMovie").hide();
	});
});

Now back to the movies…
Chris

If you google terms such as “localhost becomes www.localhost.com” or the likes, you’ve likely pulled up countless pages that go into the details of various “about:config” hidden settings within Firefox that you can adjust in an attempt to disable this functionality.  If you’re like me, you will have tried every setting under the sun, only to get as far as “www.localhost”.  Yep, very odd looking, but still equally irritating.  You may have have also been directed to other ideas including the examination of your hosts file and the removal of things such as “::1″ which is part of ipv6 (not a great idea).  This too was not helpful.  Before going onwards, let me set the stage for the technical symptoms so you can decide whether you too are facing such a conundrum:

  1. This behavior only appears in Firefox, IE7/8 still resolve localhost correctly.
  2. You’ve disabled all the magical about:config settings within Firefox that tack the prefix “www.” and suffix “.com”  onto the ends of URL’s, although you still see the prefix ironically.
  3. You’ve made sure your hosts file has “127.0.0.1 localhost” present, flushed your DNS and it made no notable difference.

With the above said, I got into this little pickle because I was writing myself a software solution to force non-www requests to my domain to always have www at the beginning.  You might be asking yourself, why on earth didn’t I do this at the IIS level?  Simple answer, shared hosting provider, so no access to IIS (yay!).  It all started when I had just buttoned up the first round of implementation whereby when a request comes in that doesn’t begin with “www.”, I was taking the request and tacking on “www.”, then sending the request on its merry way.  Sounds pretty logical right?  I ran it, everything worked great…until I tried to debug my site for a different reason, at which point Firefox began trying to resolve www.localhost.com.

I quickly realized what I had done wrong, I couldn’t simply check whether the inbound request started with “www.” but also needed to check whether it started with “localhost”, otherwise I’d be routing localhost requests through the same mechanism.  So after fixing this I figured all would be well.  Nope! Same issue existed, even after rebooting my machine.  I said enough was enough at this point and I literally commented out all of my code so that absolutely nothing was being done with inbound requests.  The issue still remained!

I was really puzzled at this point.  I started to wonder whether there was a problem with the Cassini web server that VS 2010 leverages, so I tweaked the project settings so that the port for debugging was no longer auto-assigned but rather manually set.  Each time I manually picked a new port, the same problems would occur, so it wasn’t port-specific.

Then all of the sudden it hit me, I thought, I guess I can try clearing Firefox’s cache as a absolute last possible idea, voila!  Yes, this issue was stemming from Firefox’s cache, even though I was doing forced full refreshes every step of the way (which is suppose to ignore the browser cache).  What’s even stranger is that if I was changing the port, that would have also qualified as a new URL and ignored the browser cache, but the issue wasn’t going away.

In a future post I will go over the very light-weight code I wrote that shows how to force requests to be prefixed with “www.”, with an exception built in for “localhost” requests.