// ==UserScript==
// @name           NicoLiveHack
// @namespace      NicoLiveHack
// @author         Hazisarashi
// @version 0.0.1
// @include http://live.nicovideo.jp/editstream
// @exclude�@http://live.nicovideo.jp/editstream?
// @exclude *.css
// @exclude *.js
// ==/UserScript==

(function() {
	
	var formbox = document.getElementById("form_box");
	var a = formbox.innerHTML.match(/captcha/);
	
	if ( a == null ){
		document.forms[0].submit();
	}else{
		try{
			var head = document.createElement('script');
			    head.type = 'text/javascript';
			    head.innerHTML = "function check(x){ document.forms[0].elements['captcha'].value = x; document.forms[0].submit(); } ";
			document.getElementsByTagName('head')[0].appendChild(head);
			
			var img = formbox.getElementsByTagName('img')[1].src;
			console.log('image src = '+img);
			
			var inner = 'var subWin = window.open("about:blank","sub","width=320,height=240");';
			inner += 'str = "<img src='+img+'>";';
			inner += 'str += "<br>";';
			inner += 'str += "<script type=text/javascript>function subwin(text){if(text.value.length==4){ window.opener.check(text.value); window.close();} }</script>";';
			inner += 'str += "<input type=text name=n1 onKeyPress=subwin(this)>";';
			console.log(inner);
			inner += 'subWin.document.open();';
			inner += 'subWin.document.write(str);';
			inner += 'subWin.document.close();';
			
			
			var script = document.createElement("script");
			script.setAttribute("type","text/javascript");
			script.innerHTML = inner;
			document.body.appendChild(script);
			
		}catch(e){
			console.log( 'errer : "'+e+'"' )
		}
	}
	
	function closeSub(){
		subWin.close();
	};
	
	
})();
