// ==UserScript==
// @name           YouTube Trimmer
// @namespace      http://www.orangeninja.com
// @description    Trim YouTube down
// @include        http://www.youtube.com/watch?v=*
// ==/UserScript==

var yt_style = 
	/* Hide the areas we don't want */
	"#asDiv { display: none; } #commentsDiv { display: none !important; } #footerDiv { display: none !important; } #leaderboardAd { display: none !important; } #embedDiv { display: none !important; } " +
	
	/* Resize the video */
	"#vidTitle { margin: 0px !important; } #thisVidDiv { width: 520px !important; } #movie_player { width: 520px !important; height: 420px !important; } #thisVidCell { padding: 0px !important; } #otherVidsCell { padding: 0px 0px 0px 22px !important; } " +
	
	/* Maximise text */
	"#maximiser span:after { content: 'zoom)'; } body.maximised #maximiser span:after { content: 'shrink)'; } " +
	
	/* Show/hide text */
	"#commentHider span:after { content: 'show)'; } #thisVidDiv.comments #commentHider span:after { content: 'hide)'; } " +
	
	/* Resize the video and tidy up when its maximised */
	"body.maximised #vrParentDiv { display: none; } body.maximised #otherVidsCell { display: none !important; } body.maximised #actionsAreaDiv { display: none !important; } body.maximised #ratingAndStatsDiv	{ display: none !important; }	body.maximised #videoStatsDiv		{ display: none !important; }	body.maximised #embedDiv			{ display: none !important; }	body.maximised #thisVidDiv h2		{ display: none !important; }	body.maximised #movie_player		{ width: 875px !important; height: 688px !important; } " +
	
	/* Style for shown comments */
	"#thisVidDiv.comments #commentsDiv { display: block !important; } " +
	
	/* Style the top bar to contain the title too */
	"input.searchField { width: 150px; } #searchDiv { padding: 8px !important; } #searchDiv form { float: right !important; } #searchDiv div { float: left !important; } " +

	/* Keep the links we add tidy */
	"#commentHider { outline: none !important; } #maximiser { outline: none !important; } " +
	
	/* Add my new background image without the 'powered by google' bit */
	"#gNavBottom { background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAA2sAAAAkCAIAAACYMTXjAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAUBJREFUeNrs2jFqhEAYhuEdEQsrwQsI3v9IghcYUBQLQcyEhLAhJDjFgpDnAZstp3r59g/neT6exBinadq2bd/3BwAA/1hVVXVdN03Ttu3z7+GrIFM1DsMgHAEA+JmSfd+nmvxWkDHGcRy9DgAAv+m67mOMLNK3LIt8BADgb6kYUzd+FqR8BADgYkS+F2SM0e0jAABXpG5M9VjO8xxC8BwAAFyR6rFc11VBAgBwUarH4jgODwEAwEWpHksDJAAAWRQkAAAKEgCAVyo8AQAAWWyQAAAoSAAAXsm/2AAA5LFBAgCgIAEAUJAAANyHO0gAAPLYIAEAUJAAAChIAADuwx0kAAB5bJAAAChIAAAUJAAA9+EOEgCAPDZIAAAUJAAAChIAgPtwBwkAQB4bJAAAChIAAAUJAMB9uIMEACDPmwADAEOjUZMH4qNqAAAAAElFTkSuQmCC); } " +
	
	/* Move the site maintenance box up a bit */
	".confirmBox { margin-top: -10px !important; }";


(function(){
	// Add the stylesheet
	var ss = document.createElement('style');
	ss.setAttribute('type', 'text/css');
	ss.appendChild(document.createTextNode(yt_style));
	document.getElementsByTagName('head')[0].appendChild(ss);
	
	
	if(document.getElementById('commentsDiv').getElementsByTagName('h2')[0]){
		// Create a link to show the comments again after they're hidden
		var hider = document.createElement('a');
		hider.setAttribute('id', 'commentHider');
		hider.setAttribute('href', '#');
		hider.addEventListener('click', function(){
			var div = document.getElementById('thisVidDiv');
			div.className = div.className == 'comments' ? '' : 'comments';
		}, true);
		var hiderContent = document.createElement('span');
		hiderContent.appendChild(document.createTextNode('('));
		hider.appendChild(hiderContent);
		
		// Add the link to the existing comments header
		var h2 = document.getElementById('commentsDiv').getElementsByTagName('h2')[0];
		h2.appendChild(document.createTextNode(' '));
		h2.appendChild(hider);
		
		// Move the H2 out into the parent element
		h2.parentNode.removeChild(h2);
		document.getElementById('thisVidDiv').insertBefore(h2, document.getElementById('commentsDiv'));
	}
	
	
	
	// Remove the promoted videos section
	var others = document.getElementById('otherVidsDiv');
	if(others) others.removeChild(others.lastChild.previousSibling);
	
	
	
	// Create a resize link
	var max = document.createElement('a');
	max.setAttribute('id', 'maximiser');
	max.setAttribute('href', '#');
	document.getElementById('vidTitle').appendChild(document.createTextNode(' '));
	document.getElementById('vidTitle').appendChild(max);
	max.addEventListener('click', function(){
		var body = document.getElementsByTagName('body')[0];
		body.className = body.className == 'maximised' ? '' : 'maximised';
		return false;
	}, true);
	var maxContent = document.createElement('span');
	maxContent.appendChild(document.createTextNode('('));
	max.appendChild(maxContent);
	
	
	// Move the title into the top bar
	var bar = document.getElementById('searchDiv');
	var title = document.getElementById('vidTitle');
	if(title && bar){
		title.parentNode.removeChild(title);
		bar.insertBefore(title, bar.firstChild);
	}
	
})();