Background Sequential Adding Contribution
|
|
I finally managed to get background sequential adding via AJAX done now!!! This takes slightly longer but it also doesn't overload the server/browser, and limit's become unnecessary (though to be safe i've put in 500). But you have to leave it running for a few minutes if your list is large.
I've left in the old option as well.
There is no error checking in there right now though. (selecting elements using jQuery would have been very easy though!).
// ==UserScript==
// @name Mafia wars quick invite.
// @namespace InTheMafiaQuickInvite
// @description Adds quick invite links to mafia wars, needs the facebook invites script to work.
// @include http://apps*.facebook.com/inthemafia/*
// @include http://apps*.facebook.com/mobwars/mob/*
// @include http://apps*.facebook.com/*/recruit
// ==/UserScript==
// not working, at least for dragonwars... http://apps.facebook.com/dragonwars/recruit.php?action=accept&user_id=622345183
// include http://apps*.facebook.com/*/recruit.php
/* VIXAY Notes
Mon March 30, 2009 08:47:25 PM
I finally managed to get background sequential adding via AJAX done now. This takes slightly longer but it also doesn't overload the server/browser, and limit's become unnecessary
(though to be safe i've put in 500). But you have to leave it running for a few minutes if your list is large.
There is no error checking in there right now though. (selecting elements using jQuery would have been very easy though!).
*/
var limit=50;
var added_links=false;
function GetUrl(f) {
var href=location.href;
if(href.indexOf('/mobwars/')>=0) {
return 'http://apps.facebook.com/mobwars/mob/do.php?join_id='+f;
} else if(href.indexOf('/inthemafia/')>=0) {
return 'http://apps.facebook.com/inthemafia/status_invite.php?from='+f;
} else if(href.indexOf('/recruit.php')>=0) {
var acceptUrl=href.replace('/recruit.php','/recruit.php?action=accept&user_id=');
return acceptUrl+f;
} else if(href.indexOf('/recruit')>=0) {
var acceptUrl=href.replace('/recruit','/Connection/Accept/');
return acceptUrl+f;
}
}
function OpenAll() {
var l=limit;
for(var f in window.friendsWithAppNotInvited) {
GM_openInTab(GetUrl(f));
if(l--<=0) { break; }
}
}
function OpenAllSilent() {
var l=500;
for(var f in window.friendsWithAppNotInvited) {
takeAction(f,l); //just initiate the recurisve call with the first element
break;
}
}
function takeAction(f,l)//,element)
{
GM_log("adding:"+f+" limit:"+l); //DEBUG
if (l <= 0) {
GM_log("hit limit");
return false; // end condition
}
//GM_setValue('actionType',action);
GM_xmlhttpRequest({ method: "GET",
url: GetUrl(f),
headers: window.navigator.userAgent,
onload: function(response) {
/*GM_log([
response.status,
response.statusText,
response.readyState,
// response.responseHeaders,
// response.responseText,
response.finalUrl
// f,
// l
].join("\n")); //DEBUG*/
// match friend invited kind of thing
//if (\invited\.test(response.responseText))
//var q=document.evaluate(link,obj,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null);
//if(q && q.singleNodeValue) { return q.singleNodeValue; }
element = document.getElementById(f); // find link to remove from list
//GM_log("link:"+element.innerHTML);
if (element) {
var nextsib=nextSibling(nextSibling(element)); // find next element
GM_log("next:"+nextsib.id);
//nextsib = element.nextSibling.nextSibling;
//GM_log("next:"+nextsib.innerHTML);
//element.parentNode.removeChild(element);// remove calling address from list
element.innerHTML="Added Friend!";
// this chains additions without overloading browser/server
if (/:/.test(nextsib.innerHTML)) {
//GM_log("calling next");
takeAction(nextsib.id,--l); //call recursively
}
}
}});
return true;
}
//nextSibling function that skips whitespace
function nextSibling(startSib){
if (!(nextSib=startSib.nextSibling)) return false;
while (nextSib.nodeType!=1) if (!(nextSib=nextSib.nextSibling)) return false;
return nextSib;
}
function CheckFriends() {
if(window.friendsWithAppNotInvited) {
var friendsDiv=document.getElementById('InviteFriendsDiv');
if(friendsDiv) {
var d=document.getElementById('FriendsLinks');
if(!d) {
d=document.createElement('div');
d.id='FriendsLinks';
// d.style.border='20px solid #f00';
friendsDiv.insertBefore(d,friendsDiv.childNodes[0]);
}
var str='';
var totalFriends=0;
for(var f in window.friendsWithAppNotInvited) {
http://apps.facebook.com/mobwars/mob/do.php?join_id=
str+="<a href="\"+GetUrl(f)+\"" id="\"+f+\"">Add friend: "+f+"
|
|
|
Thanks very much! I've put it in, but this website does funny things to source code, some of the html bits got chopped off. |