TVGuide.com Cleanup

By krog Last update Aug 17, 2008 — Installed 342 times. Daily Installs: 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0

There are 1 previous version of this script.

// ==UserScript==
// @name           TVGuide.com Cleanup
// @namespace      CRD
// @description    Clean up the TVGuide.com Listing Page
// @include        http://www.tvguide.com/Listings/default.aspx
// @author         crd
// ==/UserScript==

var divs = document.getElementsByTagName( 'div' );

function removeHeadersAndAds()
{
	for( var i = 0, len = divs.length; i < len; i++ )
	{
		if( divs[ i ].className == 'ccTopAdContainer' )
		{
			divs[ i ].style.display = 'none';
		}
		else if( divs[ i ].className == 'ghead-w' )
		{
			divs[ i ].style.display = 'none';	
		}
		else if( divs[ i ].className == 'shop-noncontextual' )
		{
			divs[ i ].style.display = 'none';	
		}
	}
}

function removeAdRows()
{
	var trs = document.getElementsByTagName( 'tr' );
	
	for( var i = 0, len = trs.length; i < len; i++ )
	{
		if( trs[ i ].className == 'gridAdRow' )
		{
			trs[ i ].style.display = 'none';
		}
	}
	
	var iframes = document.getElementsByTagName( 'iframe' );
	
	for( var i = 0, len = iframes.length; i < len; i++ )
	{
		if( iframes[ i ].id.indexOf( 'GridAd' ) > -1 )
		{
			iframes[ i ].style.display = 'none';
		}	
	}
}

function dropGridDiv()
{
	var gridDiv = document.getElementById( 'gridDiv' );

	if( gridDiv )
	{
		var leftcol = document.getElementById( 'leftcol' );

		leftcol.parentNode.style.display = 'none';
		
		document.getElementById( 'pageSubHeader' ).style.display = 'none';
		document.getElementById( 'gridpagefooter' ).style.display = 'none';
		document.getElementById( 'TvGridDiv' ).style.width = "940px";
		
		removeHeadersAndAds();
		
		removeAdRows();

		window.addEventListener( "resize", resizeWindow, false );
		resizeWindow();
		
		processIMDB();
	}
	else
	{
		// content is mostly async in this web app, so timeout until we can cleanup the page
		setTimeout( dropGridDiv, 200 );
	}
}

function trim( str )
{
	return str.replace(/^\s+|\s+$/g,"");
}

function processIMDB()
{
	var allElements, thisElement;
	allElements = document.evaluate(
	    '//*[@class]',
	    document,
	    null,
	    XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
	    null);
	    
	for (var i = 0; i < allElements.snapshotLength; i++) 
	{
	    thisElement = allElements.snapshotItem(i);
	    switch (thisElement.nodeName.toUpperCase()) {
	        case 'A':
	        	var text = trim( thisElement.textContent );
	        		
	        	var imdbSearchString = "{query}";
	        		imdbSearchString = imdbSearchString.replace( /{query}/g, thisElement.textContent.replace( /[ ]/g, "+" ) );
	        		imdbSearchString = imdbSearchString.replace( /\</g, "" );
	        		imdbSearchString = imdbSearchString.replace( /\>/g, "" );
	        		imdbSearchString = imdbSearchString.replace( /&lt;/g, "" );
	        		imdbSearchString = imdbSearchString.replace( /&gt;/g, "" );
	        		imdbSearchString = imdbSearchString.replace( /\(CC\)/ig, "" );
	        		imdbSearchString = imdbSearchString.replace( /:/g, "+" );
	        		imdbSearchString = imdbSearchString.replace( /"/g, "" );
	        		
	        	if( imdbSearchString.indexOf( "..." ) > -1 )
	        		imdbSearchString = imdbSearchString.substr( 0, imdbSearchString.indexOf( "..." ) );
	        	
	        	imdbSearchString = "http://www.imdb.com/find?s=tt&q=" + imdbSearchString;
	        		
	        	var imdbElementString = "<a href=\"{url}\"><img src='http://dec4.org/ext/imx/imdbicon.png' border='0' /></a>&nbsp;&nbsp;";
	        		imdbElementString = imdbElementString.replace( /{url}/g, imdbSearchString );
	        		imdbElementString = trim( imdbElementString );
	        		
	        	var span = document.createElement( "span" );
	        		span.innerHTML = imdbElementString;
	        	
	        	if( thisElement.parentNode.innerHTML.indexOf( 'imdb' ) == -1 &&
	        		thisElement.innerHTML.toLowerCase().indexOf( 'programmin' ) == -1 && 
	        		thisElement.innerHTML.toLowerCase().indexOf( 'infomercial' ) == -1
	        		)
	        	{
	        		thisElement.parentNode.appendChild( span );
	        		thisElement.parentNode.appendChild( thisElement );
        		}
	            break;
	    }
	}	
}
function resizeWindow()
{
	try
	{
		var gridDiv = document.getElementById( 'gridDiv' );
		
		var heightOffset = 220;
		var newHeight = ( parseInt( document.body.clientHeight ) - heightOffset ) + "px";
		gridDiv.style.height = newHeight;
	}
	catch( e ) {}
}

dropGridDiv();