Feb 272009
 

Ok so if you have hundreds of people asking to be “friends” with you then you’ll need some program to click ok for you else you’re life will drain away.

This code, partially borrowed from elsewhere as you can see from the comments will auto add everyone who has requested you as friend on facebook. It will add them into a group numbered as the index of the dropdown.

This is the complete code for the core of a plugin for firefox. If anyone actually wants it to install let me know here and I’ll make some install instructions and a better package.

var FBAckReqs = {
Tab:undefined,
Browser:undefined,
ExpectedURL:undefined,
BrowserTimeOutRef:undefined,
HeartbeatTimeRef:undefined,
BrowserTimeOut:30000,
UIds:undefined,
FormFilled:false,
Target:"http://www.facebook.com/reqs.php",
Enabled:true,
TotalAdded:0,
Debug:true,
ProgramName:"FBAckReqs",
FriendGroupIndex:5,
HighlightStyle:"border: 2px solid rgb(255, 0,  0); margin: 1px;",

PrintToDebug:function(Function,Text){
if(this.Debug) window.dump(this.ProgramName+" : "+Function+" :  "+Text+"\n");
},

SetNewTimeout:function(Command,  Mills){
window.clearTimeout(this.BrowserTimeOutRef);
this.BrowserTimeOutRef = window.setTimeout(Command,Mills);
},

GoURL:function(URL,refresh){
this.PrintToDebug("GoURL","Refresh = "+refresh+" URL = "+URL);
if (!this.Enabled) {
this.Disable();
return;
}
if (refresh || this.ExpectedURL != URL){
this.SetNewTimeout(this.ProgramName+".GoURL('" + URL +  "',true);",this.BrowserTimeOut);
this.ExpectedURL = URL;
//this.Browser.loadURI(URL);
window.setTimeout(this.ProgramName+".Browser.loadURI('"+URL+"');",500);
}
},

ClickLink:function(Anchor,Link){
var Links = Anchor.getElementsByTagName("A");
for (var  a=0;a<Links.length;a++){
if (Links[a] &&  Links[a].childNodes[0] &&  Links[a].childNodes[0].nodeValue==Link) {
var event =  document.createEvent("MouseEvents");
event.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false,  false, false, false, 0, null);
Links[a].setAttribute("style",this.HighlightStyle);
Links[a].dispatchEvent(event);
return true;
}
}
return false;
},

ClickButton:function(Anchor,Text){
var Tags =  Anchor.getElementsByTagName("INPUT");
for (var  a=0;a<Tags.length;a++){
if (Tags[a] &&  Tags[a].hasAttribute("value") &&  Tags[a].getAttribute("value")==Text) {
var event =  document.createEvent("MouseEvents");
event.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false,  false, false, false, 0, null);
Tags[a].setAttribute("style",this.HighlightStyle);
Tags[a].dispatchEvent(event);
return true;
}
}
return false;
},

SelectDropDown:function(DropDown,Index){
DropDown.setAttribute("style",this.HighlightStyle);
DropDown.selectedIndex=Index;
},

SubmitForm:function(Form){
var  InputTags=Form.getElementsByTagName("INPUT");
for (var  a=0;a<InputTags.length;a++){
if  (ThisForm[a].getAttribute("type") == "submit"){
ThisForm[a].setAttribute("style",this.HighlightStyle);
break;
}
}
Form.submit();
},

OpenWorkerTab:function(){
this.PrintToDebug("OpenWorker","Started");
//this.ExpectedURL =  this.GameTarget;
this.Tab = gBrowser.selectedTab;
this.Browser = gBrowser.getBrowserForTab(this.Tab);
this.Browser.addEventListener("load", function(e)  {FBAckReqs.OnPageLoad(e);}, true);
if (!this.HeartbeatTimeRef)  HeartbeatTimeRef =  window.setInterval(this.ProgramName+".HeartBeat();",500);
if  (!this.Work()){
this.GoURL(this.Target,false);
}
},

HeartBeat:function(){
if  (FBAckReqs.Browser.contentWindow == undefined) this.Disable();
},

Work:function(){
if  ((this.Browser.contentDocument.documentURI.search(/http:\/\/www.facebook.com\/reqs.php/)==0)){
this.ConfirmFriends();
return true;
}
return false;
},

ConfirmFriends:function(){
var FriendSection =  this.Browser.contentDocument.getElementById("friend_add");
if  (FriendSection){
for (var  a=1;a<FriendSection.childNodes.length;a++){
var  ThisFriend = FriendSection.childNodes[a];
var FBID =  ThisFriend.getAttribute("id").match(/\d{1,}/);
this.ClickLink(ThisFriend,"Add to a Friend List");
this.SelectDropDown(this.Browser.contentDocument.getElementById("add_to_friend_list_widget_select_"+FBID),this.FriendGroupIndex);
this.ClickButton(ThisFriend,"Confirm");
//this.SubmitForm(ThisFriend.getElementsByTagName("FORM")[0]);
}
}
},

Disable:function(){
window.clearInterval(this.BrowserTimeOutRef);
window.clearInterval(this.HeartbeatTimeRef);
this.Browser.removeEventListener("load", function(e)  {BWFadd.OnPageLoad(e);}, true);
this.PrintToDebug("Disbale","Program Disabled");
},

OnPageLoad:function(aEvent){
this.PrintToDebug("OnPageLoad","Load Event");
if  (!this.Enabled) {
this.Disable();
return;
}

this.SetNewTimeout(this.ProgramName+".GoURL('" +  this.ExpectedURL + "',true);",this.BrowserTimeOut);

if (this.Browser.contentDocument.getElementById("pagefooter")){
window.clearTimeout(this.BrowserTimeOutRef);
this.Work();
} else {
this.PrintToDebug("OnPageLoad","No Page Footer");
}
}
}
/*
CanAdd:function(){
if  (this.Browser.contentDocument.getElementById("error")) {
if  (this.Browser.contentDocument.getElementById("standard_error").firstChild.nodeValue=="You  are approaching the limit for adding friends!"){
this.Enabled = false;
alert("Added Today :  "+this.TotalAdded);
}
return false;
}
if (this.Browser.contentDocument.getElementById("standard_status"))  return false;
return true;
},

GetIDs:function(){
this.UIds = new Array();
var forms  = this.Browser.contentDocument.getElementsByTagName("FORM");
for (var a=1;a<11;a++){
if  (parseInt(forms[a].parentNode.parentNode.getElementsByClassName("g")[0].nextSibling.nodeValue.replace(/[$]|g/g,""))  < 1000)
this.UIds.push(forms[a].childNodes[15].getAttribute("value"));
}
if (this.UIds.length) {
this.GoURL("http://www.facebook.com/addfriend.php?id="+this.UIds[0],false);
} else {
this.GoURL(this.GameTarget,true);
}
},

FillForm:function(){
var ID =  this.Browser.contentDocument.documentURI.match(/\d{1,}/);
this.ClickLink("[ Add a personal message ]");
var TextArea =  this.Browser.contentDocument.getElementById("message");
TextArea.value = "Please Join My Blood Line in the world of Blood  Series."
var DropDown =  this.Browser.contentDocument.getElementById("add_to_friend_list_widget_select_"+ID);
DropDown.selectedIndex=5;
this.Browser.contentDocument.getElementsByTagName("FORM")[1].submit();
this.TotalAdded++;
}
*/

Share

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>