maloomf9 / Tigerdile Narrowed

// ==UserScript==
// @name        Tigerdile Narrowed
// @namespace   http://www.furaffinity.net/user/maloo
// @description Puts the chat under the stream for a narrower website. Good for side-by-side watching of streams. Also gives you a userlist in the chat.
// @include     *tigerdile.com/stream/*
// @version     2.0
// @grant       none
// ==/UserScript==

var vHeight = (window.innerWidth / 4 * 3);
if (vHeight > 768) vHeight = 768;
var cHeight = window.innerHeight - vHeight + 35;
if (cHeight < 200) cHeight = 200;

function addGlobalStyle(css) {
	try {
		var elmHead, elmStyle;
		while (document.getElementsByTagName('head')[0] === null)
		{
			/*var ms;
			ms = 10;
			ms += new Date().getTime();
			while (new Date() < ms){}*/
		}
		elmHead = document.getElementsByTagName('head')[0];
		elmStyle = document.createElement('style');
		elmStyle.type = 'text/css';
		elmHead.appendChild(elmStyle);
		elmStyle.innerHTML = css;
	} catch (e) {
		if (!document.styleSheets.length) {
			document.createStyleSheet();
		}
		document.styleSheets[0].cssText += css;
	}
}

var elem = document.querySelector("#chatbox");

elem.src = elem.src.replace("&small=1","");

addGlobalStyle(
'body {overflow-x: hidden;}' +
'#stream-container {width: 100% !important; max-width: 1024px;}' +
'#chatbox {height:  '+cHeight+'px !important; width: 100% !important; border: 0px none;}' +
'.fr {position: absolute !important; right: 5px;}' +
'#header .menu li {margin-right: -30px !important;}' +
'#myPlayerElement {width: 100%;}' +
'#my_video {height: 100% !important; width: 100% !important; padding-top: 75%;}' +
'.header {width: 100% !important;}'

);

function chRes() { //Resize chat height when window is resized.
	var vHeight = (window.innerWidth / 4 * 3);
	if (vHeight > 768) vHeight = 768;
	var cHeight = window.innerHeight - vHeight + 35;
	if (cHeight < 200) cHeight = 200;
	document.querySelector('#chatbox').style = ('Height: ' + cHeight + 'px !important;');
}
window.addEventListener("resize", chRes, true);