Netflix Tivo Mashup

By Robert Simmons Last update Aug 30, 2008 — Installed 304 times. Daily Installs: 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 3, 0, 3, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0

There are 2 previous versions of this script.

// Netflix Tivo Mashup script
// version 0.3 BETA!
// 2007.02.26
// Copyright (c) 2007, Robert Simmons
// Released under the GPL license
// http://www.gnu.org/copyleft/gpl.html
//
// This is a Greasemonkey user script.
//
// To install, you need Greasemonkey: http://www.greasespot.net/
// Then restart Firefox and revisit this script.
// Under Tools, there will be a new menu item to "Install User Script".
// Accept the default configuration and install.
//
// To uninstall, go to Tools/Manage User Scripts,
// select "Netflix Tivo Mashup", and click Uninstall.
//
// ==UserScript==
// @name Netflix Tivo Mashup
// @namespace http://runningasroot.com/
// @description Adds a TiVo button to Netflix queue items that appear in TiVo search.
// @include http://www.netflix.com/Queue*
// ==/UserScript==

var allItems, thisItem, tivoSearch;

allItems = document.evaluate("//table[@class='qtbl']//a", document, null,
    XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);

for (var i = 0; i < allItems.snapshotLength; i++) {
    thisItem = allItems.snapshotItem(i);

    tivoSearch = "http://www3.tivo.com/tivo-tco/search.do?tsn=&dispatch=advancedsearch&searchTitle=%22" + escape(thisItem.text) + "%22&searchDesc=&searchCastCrew=&searchCategory=&searchGenre=&searchWhen=14&advanced_button.x=0&advanced_button.y=0";

    tivoCheck(tivoSearch, thisItem, document);
}

function tivoCheck(tivoUrl, thisItem, document) {
    GM_xmlhttpRequest({
        method: 'GET',
        url: tivoUrl,
        onload: function(responseDetails) {
          var page = responseDetails.responseText;

          var searchPattern = /Found shows with Title/g;
          var searchResults = page.match(searchPattern);

          if ( searchResults != null && typeof(searchResults)!='undefined' && searchResults.length >= 1) {	
                var newAnchor = document.createElement("a");
                newAnchor.setAttribute("href", tivoUrl);
                newAnchor.setAttribute("style","color:red; background:#ffc; padding:1em;");
                var linkText = document.createTextNode("TiVo");
                
                newAnchor.appendChild(linkText);
                                
                var newText = document.createTextNode(" ");

                thisItem.parentNode.insertBefore(newText, thisItem.nextSibling);

                thisItem.parentNode.insertBefore(newAnchor, newText.nextSibling);
            }
        }
    });
}