Saucsse / Respawn Topic Save

// ==UserScript==
// @name         Respawn Topic Save
// @version      1.2
// @description  Craftbukkit
// @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-*
// @grant        none
// ==/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();

function download(filename, text) {
  var element = document.createElement('a');
  element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
  element.setAttribute('download', filename);

  element.style.display = 'none';
  document.body.appendChild(element);

  element.click();

  document.body.removeChild(element);
}
document.getElementsByClassName("group-two")[0].innerHTML += '<a href="#" class="buttonsrch"><span class="btn btn-actu-new-list-forum">Télécharger</span></a>';

var inc = 1;
var didiv = new Array();
var tmpSearch = "";
function loadToPage(page, data)
{
	if(data.indexOf('"http://m.jeuxvideo.com/forums/'+window.location.href.split("forums/")[1].split("-")[0]+'-'+window.location.href.split("-")[1]+'-'+window.location.href.split("-")[2]+'-1-0-1-0') == "-1" || inc == 1){
	var data2 = data.split('<div class="bloc-header">');
	var data4 = data.split('<div class="bloc-date-msg">');
	var data3 = data.split('<div class="bloc-contenu">');
	var titre = data.split('<span id="bloc-title-forum">')[1].split('</span>')[0];
	tmpSearch += "*********** PAGE N°"+inc+" ***********\n\n\n\n";
	for(var k=1;k<data2.length;k++)
	{
		var pseudoTmp = data2[k].split('>')[1].split('<')[0].trim();
		var dateTmp = data4[k].split('">')[1].split('</span>')[0].trim();
		if(k+1<data2.length){ 
			var messageTmp = data3[k].split('<div class="signature-msg  text-enrichi-forum ">').join('\n\nSIGNATURE :\n').split('<span id="')[0].split('<blockquote class="blockquote-jv">').join('\n******* DEBUT CITATION : *******\n').split('</blockquote>').join('\n******* FIN CITATION *******\n').replace(/<a href="(.+?)" data-def="NOELSHACK" target="_blank">/gm, '$1').replace(/<img (.+) alt="(.+?)" data-def="SMILEYS" (?:.|\n)*?>/gm, '$2').replace(/<(?:.|\n)*?>/gm, '').trim();}
		else{ 
			var messageTmp = data3[k].split('<div class="signature-msg  text-enrichi-forum ">').join('\n\nSIGNATURE :\n').split('<div class="bloc-pagi-default">')[0].split('<blockquote class="blockquote-jv">').join('\n******* DEBUT CITATION : *******\n').split('</blockquote>').join('\n******* FIN CITATION *******\n').replace(/<a href="(.+?)" data-def="NOELSHACK" target="_blank">/gm, '$1').replace(/<img (.+) alt="(.+?)" data-def="SMILEYS" (?:.|\n)*?>/gm, '$2').replace(/<(?:.|\n)*?>/gm, '').trim(); }
		var dataTmp = '<div class="bloc-message-forum "'+data.split('<div class="bloc-message-forum "')[k];
		if(k<data2.length)
			dataTmp = '<div class="bloc-message-forum "'+data.split('<div class="bloc-message-forum "')[k].split('<div class="bloc-pagi-default">')[0];
		tmpSearch += "*********************\n";
		tmpSearch += "Écrit par "+pseudoTmp+" le "+dateTmp+" : \n"+messageTmp+"\n";
		tmpSearch += "*********************\n\n\n";
	}
	tmpSearch += "**********************\n\n\n\n";

	jsli.Transformation();
	inc++;
	document.getElementById('papage').innerHTML = "Scan Page "+inc;
	page = page.split("-")[0]+"-"+page.split("-")[1]+"-"+page.split("-")[2]+"-"+inc+"-0-1-0-o.htm";

	if(data.indexOf('<div class="bloc-liste-num-page"><span class="page-active">1</span></div><div class="pagi-after"></div></div>') == "-1" && inc <= 5001) 
	{
		$.get(page, function(data,succes){loadToPage(page, data); });
	}
	
	if(data.indexOf('<span class="page-active">'+Number(inc-1)+'</span></div><div class="pagi-after"></div>') != "-1")
	{
		var date = new Date();
		download(""+titre+"_"+date.getTime()+".txt", tmpSearch);
	}
	
	}
}
function commence(page)
{
	document.getElementsByClassName("conteneur-messages-pagi")[0].innerHTML = "<span id='papage'>Scan Page 1</span>";
	page = page.split("-")[0]+"-"+page.split("-")[1]+"-"+page.split("-")[2]+"-1-0-1-0-o.htm";
	$.get(page, function(data,succes){loadToPage(page, data); });
}
document.getElementsByClassName("buttonsrch")[0].onclick = function(){ commence(window.location.href); };