// ==UserScript==
// @name         NicoVideo Auto Login
// @namespace    http://bmky.net/
// @include      http://www.nicovideo.jp/*
// ==/UserScript==

( function( ) {
	var mail = "";
	var pass = "";
	var wand = true;
	
	var form = gid( "login" ) || gid( "login_bar" );
	
	if( form && mail != "" && pass != "" ) {
		var login_url = "https://secure.nicovideo.jp/secure/login?site=niconico&mail=" + mail + "&password=" + pass;
		
		if( wand ) {
			( gid( "mail" ) || gid( "bar_mail" ) ).value = mail;
			( gid( "password" ) || gid( "bar_password" ) ).value = pass;
			form.submit( );
		}
		else {
			var iframe = document.createElement( "iframe" );
			iframe.src = login_url;
			iframe.style.display = "none";
			iframe.addEventListener( "load", function( ) { location.href = location.href }, false );
			document.body.appendChild( iframe );
		}
	}
	
	function gid( id ) { return document.getElementById( id ) }
} )( );
