// ==UserScript==
// @name          Pure Google v1.2
// @description	  Cleans Google's interface of extraneous links and text.
// @namespace     http://justinsomnia.org/
// @include       http://google.*/
// @include       http://www.google.*/
// ==/UserScript==

(function() {
	// get all the tables used to layout the interface (tsk tsk tsk)
	tables = document.getElementsByTagName("table");
	
	// check if google logo is spliced in the first table
	// which occurs in most of the international logos

	if (tables[0].getElementsByTagName("img").length > 1)
	{
		tables[1].setAttribute("style", "display:none;");
		search_table = 2;
	}

	// google.com personalized home
	else if (tables.length == 3)
	{
		tables[0].setAttribute("style", "display:none;");		
		tables[1].setAttribute("style", "display:none;");
		search_table = 2;
	}
	else
	{
		tables[0].setAttribute("style", "display:none;");
		search_table = 1;
	}

	// remove table cells on either side of search box
	search_table = tables[search_table];
	search_table_cells = search_table.getElementsByTagName("td");

	// yey! google.com stores the td's inside a tbody, unlike any of the other sites
	if (search_table_cells.length == 0)
	{
		search_table_cells = search_table.getElementsByTagName("tbody")[0].getElementsByTagName("td");
	}

	search_table_cells[0].setAttribute("style", "display:none;");
	search_table_cells[2].setAttribute("style", "display:none;");
	
	// some sites have extra rows which contain radio buttons
	// to limit search to country or the whole web
	seach_table_rows = search_table.getElementsByTagName("tr");
	for (var i = 1; i < seach_table_rows.length; i++)
	{
		seach_table_rows[i].setAttribute("style", "display:none;");
	}

	// remove buttons
	// v1.1 made this code a little less order dependent
	// and more functional
	inputs = document.getElementsByTagName("input");
	for (var i = 0; i < inputs.length; i++)
	{
		if (inputs[i].type == "submit")
		{
			inputs[i].setAttribute("style", "display:none;");
		}
	}
	
	// remove boilerplate copyright (hmm... legality?)
	paragraphs = document.getElementsByTagName("p");
	for (var i = 0; i < paragraphs.length; i++)
	{
		paragraphs[i].setAttribute("style", "display:none;");
	}

	// remove misc business related links stored in font tags (tsk tsk tsk)
	fonts = document.getElementsByTagName("font");
	for (var i = 0; i < fonts.length; i++)
	{
		// some language names are integrated into the table that splices
		// the google logo. sometimes the language name is an image,
		// other times it's a font tag. this if-statement prevents hiding
		// font tags nested in table cells
		if (fonts[i].parentNode.nodeName != "TD" && fonts[i].parentNode.nodeName != "td")
		{
			fonts[i].setAttribute("style", "display:none;");
		}
	}

	// for whatever reason, the Korean interface has some links in a span
	// thankfully this doesn't break any other pages
	spans = document.getElementsByTagName("span");
	for (var i = 0; i < spans.length; i++)
	{
		spans[i].setAttribute("style", "display:none;");
	}

})();
