// --------------------------------------------------------------------
//
// ==UserScript==
// @name            Netflix Rent Now
// @namespace       http://www.christopherthomas.name
// @description     Adds movies to the head of rental queue.
// @include         http://netflix.com/*
// @include         http://www.netflix.com/*
// ==/UserScript==

(function() {

  var rentLinks;
  // Find all the "Add to queue links"
  rentLinks = document.evaluate(
                                "//A[contains(@href,'/AddToQueue?')]",
                                document,
                                null,
                                XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
                                null);

  for (var i = 0; i < rentLinks.snapshotLength; i++) {

    var elm = rentLinks.snapshotItem(i);

    // Create a similar link that adds the movie to the 
    // front of the queue, by adding the 'add to top' parameter
    // to the URL.

    var rentFirst = document.createElement('a');
    rentFirst.setAttribute('href', elm.getAttribute('href').replace('AddToQueue?', 'AddToQueue?addtotop=Y&'));

    // Add the 'add to top' button image.

    var img = document.createElement('IMG');
    img.src="http://image.netflix.com/NetFlix_Assets/email/buttons/rent_add_top.gif";
    img.border=0;
    rentFirst.appendChild(img);
    rentFirst.appendChild(document.createElement('BR'));

    // Put the new link right before the existing "add to end" link
    elm.parentNode.insertBefore(rentFirst, elm);
  }
})();


