// ==UserScript==
// @name         niconico assist
// @namespace    http://bmky.net/diary/log/1566.html
// @include      http://www.nicovideo.jp/watch/*
// @version      1.5
// ==/UserScript==

//wrapper を使っているなら true
var flvplayer_wrapper = false;
//フルスクリーン拡大用倍率。 2.2 は 1280*1024 用
var fullScreenRate = 2.3;
//市場を表示したくないなら true
var hidden_ichiba = true;




( function( ) {

var container_width = 952; //flvplayer の幅
var container_height = 540;//flvplayer の高さ
var niwa_height = 66; //ニワニュースの高さ

//市場を自動で読み込ませない
if( ichiba_bootstrap )
	window.removeEventListener( "load", ichiba_bootstrap, false );

//F5キャンセラーキャンセラー
keyPRESS = function( ){ };

var link = document.createElement( "link" );
link.rel = "stylesheet";
link.href = 'data:text/css;abbr, #PAGEHEADER, #PAGEFOOTER, #WATCHFOOTER > p /* 使い方等 */, *[class^="ad"] /* 広告の類 */, img[src$="sm.gif"] /* smilevideo */, img[src$=".ico"] /* smilevideo */, #des_1 /* 省略モード */, #des_2 > table:first-child > tbody > tr > td:last-child /* 説明文・メニューを閉じるボタン */, #des_2 > table:last-child > tbody > tr > td:last-child > div p /* 貼り付けHTML */, #des_2 > table:last-child > tbody > tr > td:last-child > div > div:last-child /* ブログ貼り付け */, #des_2 > table:last-child > tbody > tr > td:first-child > div > p > span /* この動画を・・・ */, #des_2 > table:last-child > tbody > tr > td:first-child > p /* 投稿者コメント */, .tag_txt > strong, #subinfo > tbody > tr > td:last-child /* 下部詳細 */, #WATCHHEADER > table:last-child > tbody > tr > td:last-child > form > table > tbody > tr > td > strong /* マイリスト */{ display : none !important; }* {padding : 0 !important;margin : 0 !important;background-image : none !important;border-spacing : 0;}#des_2 {display : block !important;}table, td, th {width : auto !important;display : block !important;}#des_2 > table:last-child > tbody > tr > td:first-child > div > div{ border : 0 !important; }#des_2 > table > tbody > tr > td > div > table:last-child > tbody > tr > td, form td{ display : table-cell !important; }#subinfo {display : none !important; /* 初期状態では隠す */}#WATCHHEADER {display : none; /* 初期状態では隠す */width : auto !important;height : auto !important;border-left: 1px solid #666 !important;}#WATCHFOOTER {width : auto !important;}.ichiba_frm {width : auto !important;border : 0 !important;}.TXT10 {font-size : 100% !important;}body {padding-left : 8px !important;width : auto !important;overflow-x : hidden !important;}img.video_img_M {width : auto !important;height : auto !important;}.toolButton {position : absolute;display : block;height : 48px;width : 8px;left : 0;padding : 0;}.info {top : 0;background-color : #fdd;}.full {top : 48px;background-color : #dfd;}.reload {bottom : 0;background-color : #ddf;}/*ニコニコ動画のプレイヤーをキーボードで操作する user.js - m2O - チーム俺等http://orera.g.hatena.ne.jp/miya2000/20081005/p0*/#nicovideo_hotkey {position : absolute;left : 0;top : 96px;height : 192px;width : 8px;border : 0;}'
link.type = "text/css";
document.getElementsByTagName( "head" )[ 0 ].appendChild( link );

if( hidden_ichiba ) {
	var link = document.createElement( "link" );
	link.rel = "stylesheet";
	link.href = 'data:text/css;abbr, #WATCHFOOTER > div { display : none !important; }'
	link.type = "text/css";
	document.getElementsByTagName( "head" )[ 0 ].appendChild( link );
}

//動画情報表示ボタン
var infoButton = document.createElement( "input" );
document.body.appendChild( infoButton );
infoButton.type = "button";
infoButton.className = "info toolButton";
infoButton.onmousedown = function( ) {
	var flv = $( "flvplayer_container" );
	if( flv.style.visibility == "hidden" ) {
		flv.style.visibility = "visible";
		flv.style.height = container_height + "px";
		$( "WATCHHEADER" ).style.display = "none";
		$( "WATCHFOOTER" ).style.display = "none";
		$( "subinfo" ).style.display = "none !important";
	}
	else {
		flv.style.visibility = "hidden";
		flv.style.height = "0px";
		$( "WATCHHEADER" ).style.display = "block";
		$( "WATCHFOOTER" ).style.display = "block";
		$( "subinfo" ).style.display = "block !important";
	}
}
infoButton.onmouseup = function( ) {
	var nicovideo_hotkey = document.getElementById( "nicovideo_hotkey" ) || document.getElementById( "video_tags" ).nextSibling;
	if( nicovideo_hotkey ) {
		nicovideo_hotkey.focus( );
	}
}

//フルスクリーンボタン
var fullButton = document.createElement( "input" );
document.body.appendChild( fullButton );
fullButton.type = "button";
fullButton.className = "full toolButton";
fullButton.onmousedown = function( ) {
	var p = $( "flvplayer" );
	var c = $( "flvplayer_container" );
	p.SetVariable( 'Stage.scaleMode', "showAll" );
	
	if( fullButton.mode == "full" ) {
		fullButton.mode = "normal";
		var r = 1;
		if( !flvplayer_wrapper )
			c.style.marginTop = "0px";
	}
	else {
		fullButton.mode = "full";
		var r = fullScreenRate;
		if( !flvplayer_wrapper )
			c.style.marginTop = "-" + ( niwa_height * r ) + "px";
	}
	
	p.style.width  = c.style.width  = container_width  * r;
	p.style.height = c.style.height = container_height * r;
}

//リロードボタン
var reloadButton = document.createElement( "input" );
document.body.appendChild( reloadButton );
reloadButton.type = "button";
reloadButton.className = "reload toolButton";
reloadButton.onmousedown = function( ) {
	document.location.href = document.location.href;
}

//市場表示ボタン
var ichiba = $( "ichiba_placeholder" ).parentNode;
var ichibaButton = document.createElement( "button" );
ichiba.appendChild( ichibaButton );
ichibaButton.innerHTML = "&#x30CB;&#x30B3;&#x30CB;&#x30B3;&#x5E02;&#x5834;&#x3092;&#x8868;&#x793A;";
ichibaButton.className = "ichibaButton";
ichibaButton.onmousedown = function( ) {
	ichiba_bootstrap( );
}

window.addEventListener( "load", function( ) {
	var nicovideo_hotkey = document.getElementById( "video_tags" ).nextSibling;
	if( nicovideo_hotkey ) {
		document.body.appendChild( nicovideo_hotkey );
		nicovideo_hotkey.id = "nicovideo_hotkey";
		nicovideo_hotkey.focus( );
	}
}, false );

} )( );
