//remove duplicated names
function removeDuplicated(names)
{
return names.reduce(function(a,b){if(a.indexOf(b)<0)a.push(b);return a;},[]);
}
// array dif function
Array.prototype.diff = function(a){
return this.filter(function(i) {return a.indexOf(i) < 0;});
};
function httpGet(url)
{
var xmlHttp = null;
xmlHttp = new XMLHttpRequest();
xmlHttp.open( "GET", url, false );
xmlHttp.send( null );
return xmlHttp.responseText;
}
function getmutualfriends(page)
{
var friends = new Array();
while (page){
start_index = page.indexOf('<a href="https://www.facebook.com/') + 34;
var finish_index = page.indexOf('?fref=pb_other', start_index);
if (finish_index != -1){
var friend = page.substring(start_index,finish_index);
if (friend.length < 40){
console.log(friend);
friends.push(friend);
}
page = page.substring(finish_index+15);
} else {
page = false;
}
}
return friends;
}
function get_mutual_friends_stranger(friendid, amount, j){
var urlfriendship = 'https://www.facebook.com/'+userid+'?and='+friendid+'&sk=friends';
var xmlHttp = new XMLHttpRequest();
xmlHttp.open( "GET", urlfriendship, true);
xmlHttp.onload = function () {
if (this.readyState === 4) {
if (this.status === 200) {
var morefriends = getmutualfriends(this.responseText);
var msg = "getting mutual friends #"+recieved+" / "+amount+" from: "+friendid+" - "+morefriends.length+" friends found. <br />";
var node = document.getElementsByClassName("fb_finder_result_container")[0];
node.innerHTML = msg;
if (morefriends.length == 50){
goodfriends.push(friendid);
}
resultfriends = resultfriends.concat(morefriends);
recieved++;
if (recieved == amount){
recieved = 0;
resultfriends = removeDuplicated(resultfriends);
resultfriends = resultfriends.diff(allfriends);
allfriends = allfriends.concat(resultfriends);
if (resultfriends.length > 0){
getmorefriends(resultfriends);
} else {
// FOUND ALL FRIENDS
goodfriends = removeDuplicated(goodfriends);
allfriends = allfriends.diff(goodfriends);
writeFriends(goodfriends, allfriends);
}
}
} else {
console.error(this.statusText);
}
}
};
xmlHttp.send( null );
}
function getmorefriends(friends)
{
resultfriends = new Array();
var amount = friends.length;
var j = 0;
recieved = 0;
friends.forEach(function(friendid) {
j++;
get_mutual_friends_stranger(friendid, amount, j)
});
}
function writeFriends(goodfriends, allfriends)
{
var close_button = '<button class="fb_close_button" style="position:absolute;top:20px;right:20px">Close</button>';
var friends_string = "<h2>Total of "+goodfriends.length+" close friends (more than 50 friends in common) were found for "+userid+"</h2><p>";
goodfriends.forEach(function(friendid){
friends_string += '<a href="https://www.facebook.com/'+friendid+'">'+friendid+'</a> ';
});
friends_string += '</p>';
friends_string += "<h2>Total of "+allfriends.length+" regular friends were found for "+userid+"</h2><p>";
allfriends.forEach(function(friendid){
friends_string += '<a href="https://www.facebook.com/'+friendid+'">'+friendid+'</a> ';
});
friends_string += '</p>';
var node = document.getElementsByClassName("fb_finder_result_container")[0];
node.innerHTML = close_button+friends_string;
close_button_node = document.getElementsByClassName("fb_close_button")[0];
close_button_node.onclick = function(){
var node = document.getElementsByClassName("fb_finder_result_container")[0];
node.style.display = "none";
};
}
function create_view(){
var node = document.createElement("div");
node.className = "fb_finder_result_container";
node.style.position = "fixed";
node.style.background = "rgba(201, 213, 236, 0.9)";
node.style.top = "200px";
node.style.width = "70%";
node.style.left = "10%";
node.style.zIndex = "9999";
node.style.padding = "30px";
node.style.overflow = "scroll";
node.style.maxHeight = "60%";
document.getElementsByTagName("body")[0].appendChild(node);
}
function insert_reveal_button(node){
current_url = window.location.href;
current_url = current_url.replace("https://www.facebook.com/", "");
current_url = current_url.replace("https://facebook.com/", "");
var slash_index = current_url.indexOf('/');
var question_index = current_url.indexOf('?');
if (slash_index != -1){
userid = current_url.substring(0, slash_index);
} else if (question_index != -1) {
userid = current_url.substring(0, question_index);
} else {
userid = current_url;
}
var parent_node = node[0].onclick = function() {
return false;
};
var my_node = '<span class="fb_execute_button" style="padding:10px;font-size:12px;color:rgb(124,156,224);cursor:pointer;">(Reveal Friends)</span>';
node[0].innerHTML += my_node;
var button_node = document.getElementsByClassName('fb_execute_button')[0];
button_node.onclick = function(){
create_view();
var page = httpGet('https://www.facebook.com/me?and='+userid+'&sk=friends');
friends = getmutualfriends(page);
allfriends = friends;
getmorefriends(friends);
};
}
var recieved = 0;
var iterations_counter = 0;
var resultfriends = new Array();
var goodfriends = new Array();
var allfriends = new Array();
var userid = "";
var curr_location = parent.location.pathname;
var d = new Date();
var start_time = d.getTime();
window.onload = function(){
set_interval();
url_interval = setInterval(function(){ check_url() }, 500);
};
function check_url(){
if (curr_location != parent.location.pathname){
set_interval();
curr_location = parent.location.pathname;
var d = new Date();
start_time = d.getTime();
}
}
function set_interval(){
inter_var = setInterval(function(){ check_exist() }, 500);
}
function check_exist() {
var mynode = document.getElementsByClassName('fb_execute_button');
var node = document.getElementsByClassName('_gs6');
if (mynode.length == 0){
if (node.length > 0) {
insert_reveal_button(node);
clearInterval(inter_var);
}
} else {
clearInterval(inter_var);
}
var d = new Date();
var curr_time = d.getTime();
if (curr_time - start_time > 10000){
clearInterval(inter_var);
}
}
1 Response
Write a comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.