// ==UserScript==
// @name           Gmail Signature
// @namespace      http*://mail.google.com*
// @description    AƱade automaticamente una firma a gmail
// @include        http*://mail.google.com*
// ==/UserScript==

//window._window = document.getElementById("canvas_frame").contentWindow;
window.__change = function(data){

	if( data == "#compose" ){
		var canvasWindow = unsafeWindow.document.getElementById("canvas_frame").contentWindow;
		var composeWindow = canvasWindow.document.getElementsByTagName('iframe')[0].contentWindow;
		var composeBody = composeWindow.document.body;
		var currentValue = ( composeBody.innerHTML ) ? composeBody.innerHTML : "";
		
		composeBody.innerHTML = 'MI TEXTO' + currentValue;
	}
	unsafeWindow.console.log(data);

};
window.__check = function(){
	try{
		if( unsafeWindow.__hash != unsafeWindow.location.hash ){
			unsafeWindow.__hash = unsafeWindow.location.hash;
			__change( unsafeWindow.__hash );
		}
	}catch(e){};
};
window.__iniciar = function(){
	try{
		if( unsafeWindow.gmonkey ){
			try{
				if( document.getElementById("canvas_frame") ){
					unsafeWindow.__hash = "";
					//unsafeWindow.console.log( unsafeWindow.__hash  );
					window.setInterval( function(){ __check(unsafeWindow);}, 1000 );
				}
			}catch(e){};	
		} else {
			window.setTimeout( __iniciar, 1400 );
		}

	}catch(e){};
};
document.addEventListener("load", function(){
	window.setTimeout(function(){
		__iniciar();
	}, 1000);
}, true);