Free javascript Hosting


JGrabAllGifts2.js

Uploaded on Sep 19 2009 21:21 by dudge669

/* JGrabAllGifts - Josh Miller - Sept 2009
Changes:
0.82 Changed the way the div is added to look more like it's own
section under Requests and above suggestions in the right column of the FB requests page
Add 'Scan for apps' button and text box
Fixed applist cookie saving
Fixed multi-app processing
0.81 Bug fix with show/hide friends area
0.80 Initial (BETA) release

Sharing is caring! :) Thanks to Vern for ideas and the base for my script! You rock! http://vern.com/mwtools/
*/

javascript:(
function(){
var version="GrabAllGifts 0.82 *BETA*",
content=document.getElementsByClassName('sidebar_item requests')[0],
mwtools_div=$('mwtools'),
wait,
show,
applist,
maxwindows=5,
winnum=0,
numgifts=0,
otherapps="app_10979261223 (Mafia Wars)\napp_102452128776 (FarmVille)\napp_56748925791 (FarmTown)\napp_112462268161 (Mobsters 2)\n",
winopts="width=750,height=500,toolbar=0,directories=0,menubar=0,scrollbars=1,resizable=1",
max;
if(!content)
content=document.getElementsByClassName('PYMK_Reqs_Sidebar')[0];
wait=readCookie('jmwtgag_wait'); if(wait==null) wait="2.5";
max=readCookie('jmwtgag_max'); if(max==null) max=10;
applist=readCookie('jmwtgag_applist'); if(applist==null || applist=="") applist="app_10979261223 (Mafia Wars)\n";
applist=applist.replace(/\\n/g,"\n");
removefr=readCookie('jmwtgag_removefr'); if(removefr==null) removefr="checked";
if(!mwtools_div) {
mwtools_div=document.createElement('div');
mwtools_div.setAttribute('id','mwtools');
mwtools_div.setAttribute('id','mwtools');
mwtools_div.setAttribute('class','PYMK_Reqs_Sidebar UIHomeBox UITitledBox');
//if(content) content.appendChild(mwtools_div);
if(content) content.parentElement.insertBefore(mwtools_div,content.nextSibling);
// Thank you! to: https://developer.mozilla.org/En/DOM/Node.insertBefore
}
//<div class="sidebar_item_header clearfix">
//<div class="UITitledBox_Top clearfix">
mwtools_div.innerHTML=
'<hr style="background-color:#bbd;color:#bbd;border:solid 1px #bbd;margin:0 5px 9px"/>'+
'<div class="sidebar_item_header clearfix">'+
'<h2 class="withoption">'+version+'</h2>'+
'<div class="option">'+
'<a href="http://joshmiller.com/jmwtools.html">Josh\'s MW Tools</a>'+
'</div>'+
'</div>'+
'<div class="sidebar_item_body clearfix" id="mwtools_main">'+
'<form name="mwtform" onsubmit="return false">'+
'<table>'+
'<tr>'+
'<td>Hide friend requests?</td>'+
'<td><input type="checkbox" name="removefr" id="removefr" '+removefr+'/></td>'+
'</tr>'+
'<tr>'+
'<td>Max gifts at a time:</td>'+
'<td><input type="text" name="max" value="'+max+'" size="4"/></td>'+
'</tr>'+
'<tr>'+
'<td>Seconds between:</td>'+
'<td><input type="text" name="wait" value="'+wait+'" size="4"/></td>'+
'</tr>'+
'<tr>'+
'<td>Apps to accept gifts for:</td>'+
'</tr>'+
'<tr>'+
'<td colspan="2"><textarea name="applist" id="applist" rows="3" cols="36">'+applist+'</textarea></td>'+
'</tr>'+
'<tr>'+
'<td></td>'+
'<td><input type="button" name="start" id="start" value="Start" class="inputbutton"/></td>'+
'</tr>'+
'<tr>'+
'</tr><td> </td>'+
'<tr>'+
'<td colspan="2"><center><input type="button" name="scan" id="scan" value="Scan page for apps I use" class="inputbutton"/></center></td>'+
'</tr>'+
'<tr>'+
'<td colspan="2"><div id="otherappsarea" style="display:none"><textarea name="otherapps" id="otherapps" rows="3" cols="36" style="color:yellow;background-color:blue">'+otherapps+'</textarea></div></td>'+
'</tr>'+
'</table>'+
'</form>'+
'</div>';
window.scroll(0,0);
showHideFriends();
document.getElementById("removefr").onclick=showHideFriends;

function showHideFriends() {
xpath = "//div[@id='friend_suggestion' or @id='friend_connect']";
doc=document.evaluate(xpath,document,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null);
for(i=0;i<doc.snapshotLength;i++){
doc.snapshotItem(i).style.display=document.mwtform.removefr.checked?"none":"inline";
}
}
function createCookie(name,value) {
// expire one month from now
var expires = new Date();
expires.setDate(expires.getDate()+30);
document.cookie = name+"="+value+";expires="+expires.toGMTString()+"; path=/";
}
function readCookie(name) {
var c, i, nameEQ = name + "=",
ca = document.cookie.split(';');
for(i=0;i < ca.length;i++) {
c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if(c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
function log(line) {
var log_p=document.createElement('p');
log_p.innerHTML=line;
$("mwtools_main").appendChild(log_p);
//window.scroll(0,0);
}

function Jclick_add_platform_app(req_id,app_id,type_index,from_id,is_invite,req_type,url){
//replacement for Facebook's app request button handler - launch in new window
var obj_type='app_'+app_id+'_'+type_index;update_request_status_msg(obj_type,req_id,_tx("Loading (in new window/tab)..."));
new AsyncRequest().setURI('/ajax/reqs.php').setData({'type':'platform_request','id':req_id,'action':(url?'accept':'reject'),'params':{'from_id':from_id,'req_type':req_type,'app_id':app_id,'is_invite':is_invite}}).setHandler(function(response){
if(url){
//goURI(url);
jWin=window.open(url,"jWin"+winnum,winopts);
winnum++;
//log("jwin:"+jWin+winnum);
if(winnum>=maxwindows) winnum=0;
} else {
handle_async_response(obj_type,req_id,response.getPayload());
}
}).send();
}

function getgifts(appsxpath,max,wait) {
log("Accepting Gifts...");
var request = document.evaluate( appsxpath+"//input[@class='inputbutton' and substring(@value,1,6)='Accept']", document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null );
var timer = setInterval( function() {
if(( request.snapshotItem(numgifts) == null) || (numgifts>=max)) {
clearInterval(timer);
log("All done. "+numgifts+" gift"+(numgifts==1?"":"s")+" grabbed.");
}
else {
jreq=request.snapshotItem(numgifts).attributes["onclick"].value;
jreq=jreq.replace("return click_add","Jclick_add");
log('Grabbing gift: '+request.snapshotItem(numgifts).value.replace("Accept ",""));
eval(jreq);
}
numgifts++;
}, wait*1000);
}

$("start").onclick=function(e){
applist=document.mwtform.applist.value.replace(/\n/g,"\\n"); createCookie("jmwtgag_applist",applist);
wait=document.mwtform.wait.value; createCookie("jmwtgag_wait",wait);
max=document.mwtform.max.value; createCookie("jmwtgag_max" ,max);
removefr=document.mwtform.removefr.checked?"checked":""; createCookie("jmwtgag_removefr",removefr);
$("mwtools_main").innerHTML="";
appsxpath="";
for(i=0; i<applist.split("\\n").length; i++) {
if(m=/^([^ ]+)/.exec(applist.split("\\n")[i])) {
if(appsxpath=="") appsxpath="//div["; else appsxpath+=" or ";
//appsxpath+="substring(@id,1,15)='"+m[1]+"'";
appsxpath+="contains(@id,'"+m[1]+"')";
}
}
getgifts(appsxpath+"]",max,wait);
}
$("scan").onclick=function(e){
if(document.mwtform.scan.value.substring(0,4)=="Scan") {
xpath = "//span[contains(@id,'_label') and contains(.,'You have') and contains(.,'gift request')]";
//xpath = "//div[@id='friend_suggestion' or @id='friend_connect']";
doc=document.evaluate(xpath,document,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null);
otherapps='';
for(i=0;i<doc.snapshotLength;i++){
aid=doc.snapshotItem(i).id; aht=doc.snapshotItem(i).innerHTML;
aht=aht.replace("<strong>","");aht=aht.replace("</strong>","");
otherapps+=aid.match(/(app_\d+)/)[1]+' ('+
aht.match(/You have [a\d]+ (.*) gift request/)[1]+')\n';
}
$("otherappsarea").style.display="inline";
$("otherapps").innerHTML=otherapps;
document.mwtform.scan.value="Grab all apps";
alert(doc.snapshotLength+" apps found. Copy and paste the apps you want to grab gifts for from the blue textbox into the 'Apps to accept gifts for' box above it or just click the 'Grab all apps' button.");
} else { //Now the scan button is the Grab all apps button
applist=otherapps; document.mwtform.applist.value=applist;
$("scan").style.display="none";
$("otherapps").style.display="none";
}
}
if(!content) {
alert("Facebook's requests page has been changed since script was made. Will have to be updated...");
}
})();

Back to list