Saucsse / RespawnChat - Alpha

// ==UserScript==
// @name         RespawnChat - Alpha
// @namespace    
// @version      0.8
// @description  Bug fixé
// @author       Craftbukkit
// @require      http://code.jquery.com/jquery-2.2.0.min.js
// @match        http://www.jeuxvideo.com/forums/42-*
// @match        http://www.jeuxvideo.com/forums/1-*
// @match        http://www.jeuxvideo.com/jvchat*
// @grant        none
// @license MIT
// ==/UserScript==
var _BaseClassName="JvCare";jsli={getElementsByClassName:function(b){if(!document.getElementsByClassName){var d=new Array();var a=document.getElementsByTagName("span");for(i=0;i<a.length;i++){var c=a[i].className.split(" ");for(j=0;j<c.length;j++){if(c[j]===b){d[d.length]=a[i]}}}return d}else{return document.getElementsByClassName(b)}},LocalIterations:0,SpansTransform:0,IterationsVides:0,IsRunning:false,IsDone:false,Transformation:function(){jsli.IsRunning=true;try{var a=this.getElementsByClassName(_BaseClassName);var t=a.length;var o="0A12B34C56D78E9F";var x="charset,name,rel,rev,target,accesskey,id,style,tabindex,title".split(",");var y="blur,click,dblclick,focus,mousedown,mousemove,mouseover,mouseup,keydown,keyppress,keyup".split(",");var m,b="";var u,q,f=null;var g,c,r,h,w=0;var s=t;while(s--){u=a[s];h=u.className.indexOf(" ");w=u.className.indexOf(" ",h+1);if(w===-1){w=u.className.length}b="";if(h>0){m=u.className.substr(h+1,w-h-1);for(r=0;r<m.length;r+=2){g=o.indexOf(m.charAt(r));c=o.indexOf(m.charAt(r+1));b+=String.fromCharCode((g*16)+c)}}q="xXx "+u.className.substr(w+1,u.className.length-w-1);f=document.createElement("a");f.href=b;r=x.length;while(r--){try{h=x[r];if(w=u.getAttribute(h)){f[h]=w}}catch(v){}}for(var s=0,l=u.attributes,k=l.length;s<k;s++){if(l[s].nodeName.substring(0,5)==="data-"){try{f.setAttribute(l[s].nodeName,l[s].nodeValue)}catch(v){}}}r=y.length;while(r--){try{h=y[r];if(w=u["on"+h]){if(f.addEventListener){f.addEventListener(h,w,false)}else{if(f.attachEvent){f.attachEvent("on"+h,w)}}}}catch(v){}}f.className=q;r=u.childNodes.length;while(r--){f.appendChild(u.childNodes[0])}u.parentNode.insertBefore(f,u);u.parentNode.removeChild(u)}}catch(v){}jsli.LocalIterations++;jsli.SpansTransform+=t;if((jsli.SpansTransform>0)&&((t==0)&&(document.body))){jsli.IterationsVides++}if(jsli.IterationsVides<5){setTimeout("jsli.Transformation()",200)}else{jsli.IsRunning=false;jsli.IsDone=true;if(jsli.callbackStoreScript){jsli.callbackStoreScript()}}}};jsli.Transformation();

if(document.location.href.indexOf("/jvchat") != "-1")
{
var h = '';
    
h += '<style type="text/css">';
    
h += '#contenumessage';
h += '{';
h += 'height:700px;';
h += '/* width:57%; */';
h += 'overflow-y:auto;';
h += 'overflow-x:hidden;';
h += '}';
h += '#tabli tr';
h += '{';
h += '	vertical-align:top;';
h += '	border collapse:none;';
h += '}';
h += '.pseupseudo';
h += '{';
h += '	text-align:right;';
h += '	font-weight:bold;';
h += '	max-width:150px;';
h += '	width:150px;';
h += '}';
h += '.messmessage, .messmessage1';
h += '{';
h += '	border: 1px solid #969696;';
h += '	font-size:14px;';
h += '	padding: 4px 4px 4px 4px;';
h += '	width:880px;';
h += '	box-shadow: 0px 0px 5px black;';
h += '}';
h += '.messmessage';
h += '{';
h += '	background-color:#FFFFFF;';
h += '}';
h += '.messmessage1';
h += '{';
h += '	background-color:#F4F4F4;';
h += '}';
h += '.date';
h += '{';
h += '	font-size:15px;';
h += '	vertical-align:middle;';
h += '	color:gray;';
h += '}';
h += '#messi';
h += '{';
h += 'font-size:14px;';
h += 'width:100%;';
h += '}';
    h += 'blockquote.blockquote-jv {';
h += '    text-align: left;';
h += '    margin-bottom: 15px;';
h += '    border-left: 5px solid #CFCFCF;';
h += '    color: #8B8B8B;';
h += '    margin-left: 15px;';
h += '    padding: 10px;';
h += '    background: none;';
h += '    font-style: normal;';
h += '    font-size: inherit';
h += '}';
h += 'blockquote.blockquote-jv>blockquote:not([data-visible+="1"]) {';
h += '    position: relative;';
h += '    height: 0px;';
h += '    color: transparent;';
h += '    overflow: hidden;';
h += '    cursor: pointer';
h += '}';
h += 'blockquote.blockquote-jv>blockquote:not([data-visible+="1"])>blockquote {';
h += '    display: none';
h += '}';
h += 'blockquote.blockquote-jv>blockquote:not([data-visible+="1"]) * {';
h += '    visibility: hidden';
h += '}';
h += 'blockquote.blockquote-jv>blockquote:not([data-visible+="1"]):after {';
h += '    content: \'• • •\';';
h += '    display: inline-block;';
h += '    vertical-align: middle;';
h += '    position: absolute;';
h += '    left: 18px;';
h += '    top: 5px;';
h += '    height: 12px;';
h += '    padding: 0px 4px;';
h += '    line-height: 10px;';
h += '    font-size: 0.7rem;';
h += '    border-radius: 2px;';
h += '    background-color: #EEF1F4;';
h += '    border: 1px solid #BBBEC1;';
h += '    color: #878A8D';
h += '}';
h += 'blockquote.blockquote-jv>blockquote:not([data-visible+="1"]):hover:after {';
h += '    background-color: #EEE;';
h += '    border: 1px solid #999;';
h += '    color: #444';
h += '}';
h += '</style>';
h += '<script>';
h += 'var interinter = true;';
h += 'window.setInterval(function() { if(interinter){document.getElementById("contenumessage").scrollTop = document.getElementById("contenumessage").scrollHeight;}}, 1000);</script>';
h += '</script>';
h += '<div id="contenumessage" onmouseout="interinter = true;" onmouseover="interinter = false;" >';
h += '<table id="tabli" cellspacing="7" style="border-spacing:7px; border-collapse:initial;">';
h += '   <tr class="trr">';
h += '       <td class="pseupseudo">Oxygenation</td>';
h += '       <td class="messmessage1"><table id="tableu"><tr><td id="messi"></td><td> <span class="date">11:53:33</span></td></tr></table></td>';
h += '   </tr>';
h += '</table>';
h += '</div>';
h += '<div>';
h += '<table cellspacing="7">';
h += '   <tr class="trr">';
h += '       <td class="pseupseudo"></td>';
h += '       <td class="messmessage"><textarea style="resize:vertical; width:90%"></textarea> <div class="formform"></div> <input style="vertical-align:top;" type="button" name="btnbtn" value="Envoyer" /></td>';
h += '   </tr>';
h += '</table>';
h += '</div>';
document.getElementsByClassName("row")[0].innerHTML = h;
    document.getElementById("tabli").innerHTML = "";

var lastK = "";
var lastPage = "1";
var newMessagee = false;

var urlTopic = document.location.href.split("#")[1];
console.log(urlTopic.split("-")[0]+"-"+urlTopic.split("-")[1]+"-"+urlTopic.split("-")[2]+"-1-0-1-0-h.htmtest");

urlTopic = urlTopic.split("-")[0]+"-"+urlTopic.split("-")[1]+"-"+urlTopic.split("-")[2]+"-1-0-1-0-h.htm";

$.get("http://"+urlTopic, function(data){traitment(data);});

var urlTopic1 = "";
var bibitre = "";
function traitment(contentTopic)
{
var bibitre = contentTopic.split("<title>")[1].split("</title>")[0];
document.title = bibitre;

if(contentTopic.split('bloc-pagi-default">')[1].split('<div class="bloc-message')[0].indexOf('class="lien-jv">') == "-1")
{
	lastPage = "1";
}
else if(contentTopic.split('bloc-pagi-default">')[1].split('<div class="bloc-message')[0].indexOf('»') == "-1")
{
	lastPage = contentTopic.split('bloc-pagi-default">')[1].split('class="lien-jv">')[contentTopic.split('bloc-pagi-default">')[1].split('class="lien-jv">').length-1].split('<')[0];
}
else
{
	lastPage = contentTopic.split('bloc-pagi-default">')[1].split('class="lien-jv">')[contentTopic.split('bloc-pagi-default">')[1].split('class="lien-jv">').length-2].split('<')[0];
}
urlTopic1 = urlTopic.split("-")[0]+"-"+urlTopic.split("-")[1]+"-"+urlTopic.split("-")[2]+"-"+lastPage+"-0-1-0-h.htm";
$.get("http://"+urlTopic1, function(data){ traitment2(data);});
}


function traitment2(contentTopic)
{
	var fssession = contentTopic.split('<input type="hidden" name="fs_session" value="')[1].split('"')[0];
	var fstimestamp = contentTopic.split('<input type="hidden" name="fs_timestamp" value="')[1].split('"')[0];
	var fsversion = contentTopic.split('<input type="hidden" name="fs_version" value="')[1].split('"')[0];
	var fs_1 = contentTopic.split('<input type="hidden" name="fs_')[4].split('"')[0];
	var fs_12 = contentTopic.split('<input type="hidden" name="fs_'+fs_1+'" value="')[1].split('"')[0];
	var fs_2 = fs_1;
    var fs_22 = fs_12;
    //var fs_2 = contentTopic.split('<input type="hidden" name="fs_')[5].split('"')[0];
	//var fs_22 = contentTopic.split('<input type="hidden" name="fs_'+fs_2+'" value="')[1].split('"')[0];
	var urllll = contentTopic.split('640px)" href="http://m.')[1].split('"')[0];
	if(contentTopic.indexOf('captcha-boot-jv"') != "-1")
	{
	document.getElementsByClassName("formform")[0].innerHTML = contentTopic.split('captcha-boot-jv">')[1].split("<hr")[0];
	document.getElementsByName("btnbtn")[0].onclick = function() { $.post("http://www."+urllll, "fs_session="+fssession+"&fs_timestamp="+fstimestamp+"&fs_version="+fsversion+"&fs_"+fs_1+"="+fs_12+"&fs_"+fs_2+"="+fs_22+"&form_alias_rang=1&fs_ccode="+document.getElementsByName("fs_ccode")[0].value+"&message_topic="+document.getElementsByTagName("textarea")[0].value+"",  function(data){});  };
	}

	else{

	document.getElementsByClassName("formform")[0].innerHTML = "";
document.getElementsByName("btnbtn")[0].onclick = function() { $.post("http://www."+urllll, "fs_session="+fssession+"&fs_timestamp="+fstimestamp+"&fs_version="+fsversion+"&fs_"+fs_1+"="+fs_12+"&fs_"+fs_2+"="+fs_22+"&form_alias_rang=1&message_topic="+document.getElementsByTagName("textarea")[0].value+"",  function(data){});  };

}
		
	var t = contentTopic.split('<div class="bloc-header">');
	var t3 = contentTopic.split('<div class="bloc-contenu">');
	var tmpContent = "";
	for(var k=0;k<t.length-1;k++)
	{

		if(t[k+1].indexOf("text-user\"") != "-1")
			var t1 = t[k+1].split('text-user" target="_blank">')[1].split("</span>")[0].split(" ").join("").split("\n").join("");
		else if(t[k+1].indexOf("text-modo\"") != "-1")
			var t1 = "<font color='#FF0000'>"+t[k+1].split('text-modo" target="_blank">')[1].split("</span>")[0].split(" ").join("").split("\n").join("")+"</font>";
        else if(t[k+1].indexOf("blacklist") != "-1")
            var t1 = "blacklister";
		else
			var t1 = false;

		if(t1 == false)
			var t2 = t[k+1].split(" à ")[1].split("\n")[0];
		else
			var t2 = t[k+1].split(" à ")[1].split("<")[0];
		if(k==(t.length-2))
		{
			if(t3[k+1].split('enrichi-forum ">')[1].indexOf('<div class="signature-msg') != "-1")
				var t4 = t3[k+1].split('enrichi-forum ">')[1].split('<div class="signature-msg')[0];
			else
				var t4 = t3[k+1].split('enrichi-forum ">')[1].split('<div class="bloc-pagi-default">')[0];
		}
		else
		{
			if(t3[k+1].split('enrichi-forum ">')[1].indexOf('<div class="signature-msg') != "-1")
				var t4 = t3[k+1].split('enrichi-forum ">')[1].split('<div class="signature-msg')[0];
			else
				var t4 = t3[k+1].split('enrichi-forum ">')[1].split('<div class="bloc-message')[0];
		}
		
		t4 = t4.split("<p>").join("<p style='margin:0px 0px 0px'>");
		tmpContent += '<tr class="trr">';
		tmpContent += '<td class="pseupseudo">'+t1+'</td>';
		tmpContent += '<td class="messmessage'+((k%2==0)?'':'1')+'"><table id="tableu"><tr><td id="messi">'+t4+'</td><td> <span class="date">'+t2+'</span></td></tr></table></td>';
		tmpContent += '</tr>';
		
		if(k==(t.length-2))
		{
			console.log("LastK :"+k);
			lastK=k;
		}
	}
	document.getElementById("tabli").innerHTML += tmpContent;

	refreshfresh();
	 refreshfresh2();
}

function formformform(contentTopic)
{
	var fssession = contentTopic.split('<input type="hidden" name="fs_session" value="')[1].split('"')[0];
	var fstimestamp = contentTopic.split('<input type="hidden" name="fs_timestamp" value="')[1].split('"')[0];
	var fsversion = contentTopic.split('<input type="hidden" name="fs_version" value="')[1].split('"')[0];
	var fs_1 = contentTopic.split('<input type="hidden" name="fs_')[4].split('"')[0];
	var fs_12 = contentTopic.split('<input type="hidden" name="fs_'+fs_1+'" value="')[1].split('"')[0];
	var fs_2 = fs_1;
    var fs_22 = fs_12;
    //var fs_2 = contentTopic.split('<input type="hidden" name="fs_')[5].split('"')[0];
	//var fs_22 = contentTopic.split('<input type="hidden" name="fs_'+fs_2+'" value="')[1].split('"')[0];
	var urllll = contentTopic.split('640px)" href="http://m.')[1].split('"')[0];
	if(contentTopic.indexOf('captcha-boot-jv"') != "-1")
	{
	document.getElementsByClassName("formform")[0].innerHTML = contentTopic.split('captcha-boot-jv">')[1].split("<hr")[0];
	document.getElementsByName("btnbtn")[0].onclick = function() { $.post("http://www."+urllll, "fs_session="+fssession+"&fs_timestamp="+fstimestamp+"&fs_version="+fsversion+"&fs_"+fs_1+"="+fs_12+"&fs_"+fs_2+"="+fs_22+"&form_alias_rang=1&fs_ccode="+document.getElementsByName("fs_ccode")[0].value+"&message_topic="+document.getElementsByTagName("textarea")[0].value+"",  function(data){document.getElementsByTagName("textarea")[0].value="";});  };
	}

	else{

	document.getElementsByClassName("formform")[0].innerHTML = "";
document.getElementsByName("btnbtn")[0].onclick = function() { $.post("http://www."+urllll, "fs_session="+fssession+"&fs_timestamp="+fstimestamp+"&fs_version="+fsversion+"&fs_"+fs_1+"="+fs_12+"&fs_"+fs_2+"="+fs_22+"&form_alias_rang=1&message_topic="+document.getElementsByTagName("textarea")[0].value+"",  function(data){document.getElementsByTagName("textarea")[0].value="";});  };

}
}

function newMessage(contentTopic)
{



	
	
	console.log(lastK);
	newMessagee = true;
	if(lastK != 99)
	{
	if(lastK < 19)
	{
		var t = contentTopic.split('<div class="bloc-header">');
		var t3 = contentTopic.split('<div class="bloc-contenu">');
		var tmpContent = "";
		for(var k=lastK+1;k<t.length-1;k++)
		{
			if(t[k+1].indexOf("text-user\"") != "-1")
				var t1 = t[k+1].split('text-user" target="_blank">')[1].split("</span>")[0].split(" ").join("").split("\n").join("");
			else if(t[k+1].indexOf("text-modo\"") != "-1")
				var t1 = "<font color='#FF0000'>"+t[k+1].split('text-modo" target="_blank">')[1].split("</span>")[0].split(" ").join("").split("\n").join("")+"</font>";
            else if(t[k+1].indexOf("blacklist") != "-1")
                var t1 = "blacklister";
			else
				var t1 = false;

			if(t1 == false)
				var t2 = t[k+1].split(" à ")[1].split("\n")[0];
			else
				var t2 = t[k+1].split(" à ")[1].split("<")[0];

			if(k==(t.length-2))
			{
				if(t3[k+1].split('enrichi-forum ">')[1].indexOf('<div class="signature-msg') != "-1")
					var t4 = t3[k+1].split('enrichi-forum ">')[1].split('<div class="signature-msg')[0];
				else
					var t4 = t3[k+1].split('enrichi-forum ">')[1].split('<div class="bloc-pagi-default">')[0];
			}
			else
			{
				if(t3[k+1].split('enrichi-forum ">')[1].indexOf('<div class="signature-msg') != "-1")
					var t4 = t3[k+1].split('enrichi-forum ">')[1].split('<div class="signature-msg')[0];
				else
					var t4 = t3[k+1].split('enrichi-forum ">')[1].split('<div class="bloc-message')[0];
			}
			
			t4 = t4.split("<p>").join("<p style='margin:0px 0px 0px'>");

			tmpContent += '<tr class="trr">';
			tmpContent += '<td class="pseupseudo">'+t1+'</td>';
			tmpContent += '<td class="messmessage'+((k%2==0)?'':'1')+'"><table id="tableu"><tr><td id="messi">'+t4+'</td><td> <span class="date">'+t2+'</span></td></tr></table></td>';
			tmpContent += '</tr>';
			console.log("Last2 :"+lastPage);
			if(k==(t.length-2))
			{
				console.log("LastK :"+k);
				lastK=k;
			}
		}
		document.getElementById("tabli").innerHTML += tmpContent;
  document.getElementById("contenumessage").scrollTop = document.getElementById("tabli").scrollHeight;
		jsli.Transformation();
	}
	else
	{
		lastK = 99;
	}
	}
	else{
		if(contentTopic.indexOf('" class="lien-jv">'+(Number(lastPage)+1)) != "-1")
		{
			lastK=-1;	
			lastPage = Number(lastPage)+1; 
			urlTopic1 = urlTopic.split("-")[0]+"-"+urlTopic.split("-")[1]+"-"+urlTopic.split("-")[2]+"-"+(lastPage)+"-0-1-0-h.htm";
		}
	}
	
}

function refreshfresh()
{
	$.get("http://"+urlTopic1, function(data){setTimeout(refreshfresh, 1000); newMessage(data);}).fail(function() {refreshfresh();});
	
}
function refreshfresh2()
{
	$.get("http://"+urlTopic1, function(data){setTimeout(refreshfresh2, 5000); formformform(data);}).fail(function() {refreshfresh2();});
	
}
//window.onerror = function (errorMsg, url, lineNumber, column, errorObj) { if(!newMessagee){ window.location.reload();} }

}
else
{
        setTimeout(function(){    document.getElementsByClassName("moder")[0].innerHTML += '<a href="#" onclick="javascript:document.location.href=\'http://www.jeuxvideo.com/jvchat#\'+document.location.href.split(\'http://\').join(\'\');"><span class="btn btn-actu-new-list-forum">RespawnChat</span></a>';}, 2000);

    document.getElementsByClassName("group-two")[0].innerHTML += '<a href="#" onclick="javascript:document.location.href=\'http://www.jeuxvideo.com/jvchat#\'+document.location.href.split(\'http://\').join(\'\');"><span class="btn btn-actu-new-list-forum">RespawnChat</span></a>';
}