// ==UserScript==
// @name           Google Proxy
// @namespace      http://greasemonkey.orsomethinglikethat.com
// @description    Proxy web sites through Google Translate
// @include        *
// ==/UserScript==

/**
* Check for User Script Command Compatibility.
* Note: This acts as a wrapper around all other processing
*/
if( GM_registerMenuCommand ) {

	/**
	* Prompt for a url to navigate to via google proxy/translate
	* Register the command under Tools->Greasemonkey->User Script Commands
	*/
	GM_registerMenuCommand( "Google Proxy - Prompt URL", function(event) {
		var proxyURL = prompt( "Google Proxy", "[URL to Proxy]" );
		
		if( proxyURL ) {
			window.location.href = "http://translate.google.com/translate?u=" + encodeURI(proxyURL) + "&langpair=es|en";
		}
	});

	/**
	* Convert all <a href>'s on the current page to google proxy/translate links
	* Register the command under Tools->Greasemonkey->User Script Commands
	*/
	GM_registerMenuCommand( "Google Proxy - This Page's Links", function(event) {
		var allLinks, thisLink;
		allLinks = document.evaluate(
		    '//a[@href]',
		    document,
		    null,
		    XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
		    null);
			
		for (var i = 0; i < allLinks.snapshotLength; i++) {
		    thisLink = allLinks.snapshotItem(i);
			thisLink.href = "http://translate.google.com/translate?u=" + encodeURI(thisLink.href) + "&langpair=es|en";
		}
	});

} // End GM_registerMenuCommand check (wrapper)
