User script: Difference between revisions

From GreaseSpot Wiki
Jump to navigationJump to search
No edit summary
No edit summary
Line 1: Line 1:
// ==UserScript==
// ==UserScript==
// @name         FFS Commander
// @name           FFS USER STATISTIC
// @description   used to automatically get your pets working in Friends For Sale
// @description   Replace ads top panel by ratio info in all the profiles you visit. It also removes these blocks of ads at the top and bottom in Dashboard.
// @include       http://apps.facebook.com/friendsforsale/chores*
// @include       http://apps.facebook.com/friendsforsale/users/show/*
// @require      http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js
// @include        http://apps.new.facebook.com/friendsforsale/users/show/*
// @version   1.0.2
// @include        http://apps.facebook.com/friendsforsale/
// @include        http://apps.new.facebook.com/friendsforsale/
// ==/UserScript==
// ==/UserScript==
var Worker={
 
doClick : function(node){
 
var evt=document.createEvent("MouseEvents")
// This is a subfunction to remove commas from text and
evt.initEvent("click",true,false)
// turn it into a number.
node.dispatchEvent(evt)
function removecommas(txt) {
},
return parseInt(txt.substring(1).replace(/,/g,""), 10);
goNext : function(){
}
var next=$('#app7019261521_pet_value div.pagination a:last')
 
if(next.html()=='Next'){
// And this is the subfunction to add commas to a number
Worker.doClick(next[0])
function addcommas(num) {
window.setTimeout(Worker.refresh,5000)}
var txt = String(num);
else{
var oRegEx = new RegExp('(-?[0-9]+)([0-9]{3})');
alert('DONE')}
while(oRegEx.test(txt)) {
},
txt = txt.replace(oRegEx, '$1,$2');
work : function(){
}
Worker.doClick($('div.left_column div.headline ul.filters li:eq(1) a')[0])
return txt;
var pets=$('#app7019261521_pet_value span.pet_container a')
}
pets.each(function(i){
 
var pet=pets.eq(i)
//alert('DEBUG -->' + document.location.href);
Worker.doClick(pet[0])
if ( document.location.href != "http://apps.facebook.com/friendsforsale/" &&
var energy=$('span.energy',pet).html()
document.location.href != "http://apps.new.facebook.com/friendsforsale/") {//we are not in the dashboard
var point=parseInt(energy.match(/([0-9]+)/i)[1])
//alert('DEBUG -->' + 'Dang xem Profile');
var hadWorked=false
 
if(point>=100){
// Get all money amounts on the page
hadWorked=true
var money = document.getElementsByClassName("money");
var work
/*alert('money ' + money[0].innerHTML); //--> self cash****
var friend
alert('money ' + money[1].innerHTML); //--> self value
if(point==100){
alert('money ' + money[2].innerHTML); //--> self cash
work=$('span.chore_container:eq(0) a')}
alert('money ' + money[3].innerHTML); //--> owner value
Worker.doClick(work[0])
alert('money ' + money[4].innerHTML); //--> owner cash
friend=$('span.friend_container:eq(0) a')
alert('money ' + money[5].innerHTML); //--> first pet value
Worker.doClick(friend[0])
alert('money ' + money[6].innerHTML); //--> first pet cash
work=$('div.buy a')
alert('money ' + money[7].innerHTML); //--> second pet value
Worker.doClick(work[0])}
alert('money ' + money[8].innerHTML); //--> second pet cash
else if(point<100&&point>=90){
...
hadWorked=true
*/
var work
var friend
// The second one is the user's value
if(point>=90){
var value = removecommas(money[1].innerHTML);
work=$('span.chore_container:eq(7) a')}
 
Worker.doClick(work[0])
// The third one is the user's cash
friend=$('span.friend_container:eq(0) a')
var cash = removecommas(money[2].innerHTML);
Worker.doClick(friend[0])
 
friend=$('span.friend_container:eq(1) a')
//alert('DEBUG ' + ' value[' + value + '], cash[' + cash + ']');
Worker.doClick(friend[0])
 
friend=$('span.friend_container:eq(2) a')
// Get the parent of the last shown pet list
Worker.doClick(friend[0])
// which should be the user's pets.
work=$('div.buy a')
var pets = document.getElementsByClassName("pets-item");
Worker.doClick(work[0])}
//pets = pets[pets.length - 1].getElementsByClassName("user_preview");
else if(point<90&&point>=80){
 
hadWorked=true
// initialize sum and sum2 to zero
var work
var pet, sum = 0, sum2 = 0;
var friend
 
if(point>=80){
// iterate through pets
work=$('span.chore_container:eq(9) a')}
for (pet in pets) {
Worker.doClick(work[0])
// ignore any pets not displayed
friend=$('span.friend_container:eq(0) a')
if (pets[pet].getElementsByClassName) {
Worker.doClick(friend[0])
// first money amount is value, add to sum
friend=$('span.friend_container:eq(1) a')
var petvalue = removecommas(pets[pet].getElementsByClassName("money")[0].innerHTML);
Worker.doClick(friend[0])
sum += petvalue;
work=$('div.buy a')
 
Worker.doClick(work[0])}
// name of the pet is innerHTML of second anchor
else if(point<80&&point>=75){
var petname = pets[pet].getElementsByTagName("a")[1].innerHTML;
hadWorked=true
 
var work
// sum2 will exclude pets named private
var friend
if (petname != "private") { sum2 += petvalue; }
if(point>=75){
}
work=$('span.chore_container:eq(4) a')}
}
Worker.doClick(work[0])
 
friend=$('span.friend_container:eq(0) a')
// Calculate prices for money spent and potential money once sold
Worker.doClick(friend[0])
var sumB = Math.ceil(1.01*sum);
work=$('div.buy a')
var sum2B = Math.ceil(1.01*sum2);
Worker.doClick(work[0])}
var sumC = Math.ceil(1.05*sum);
else if(point<75&&point>=70){
var sum2C = Math.ceil(1.05*sum2);
hadWorked=true
 
var work
// Calculate assets to value ratio,
var friend
// format with three decimal places.
if(point>=70){
var atv = (sum + cash)/value;
work=$('span.chore_container:eq(2) a')}
var atv2 = (sum2 + cash)/value;
Worker.doClick(work[0])
var atvB = (sumB + cash)/value;
friend=$('span.friend_container:eq(0) a')
var atv2B = (sum2B + cash)/value;
Worker.doClick(friend[0])
var atvC = (sumC + cash)/value;
friend=$('span.friend_container:eq(1) a')
var atv2C = (sum2C + cash)/value;
Worker.doClick(friend[0])
 
work=$('div.buy a')
// Calculate percent invested,
Worker.doClick(work[0])}
// format as percentage with two decimal places
else if(point<70&&point>=50){
var pctInv = 100*(1-(cash/(sum + cash)));
hadWorked=true
var pctInv2 = 100*(1-(cash/(sum2 + cash)));
var work
var pctInvB = 100*(1-(cash/(sumB + cash)));
var friend
var pctInv2B = 100*(1-(cash/(sum2B + cash)));
if(point>=65){
var pctInvC = 100*(1-(cash/(sumC + cash)));
work=$('span.chore_container:eq(8) a')}
var pctInv2C = 100*(1-(cash/(sum2C + cash)));
if(point>=60){
 
work=$('span.chore_container:eq(11) a')}
// Calculate total assets; format with commas
if(point>=50){
var assets = addcommas(sum + cash);
work=$('span.chore_container:eq(6) a')}
var assetsB = addcommas(sumB + cash);
Worker.doClick(work[0])
var assetsC = addcommas(sumC + cash);
friend=$('span.friend_container:eq(0) a')
 
Worker.doClick(friend[0])
// Caculate total assets excluding private
work=$('div.buy a')
var assets2 = addcommas(sum2 + cash);
Worker.doClick(work[0])}
var assets2B = addcommas(sum2B + cash);
else if(point<50&&point>=45){
var assets2C = addcommas(sum2C + cash);
hadWorked=true
 
var work
// Put together final output!
var friend
// Calculations excluding private go in parens.
if(point>=45){
var statistic_info =
work=$('span.chore_container:eq(1) a')}
"<table cellspacing=\"1\" width=\"100%\" border=\"0\">" +
Worker.doClick(work[0])
 
friend=$('span.friend_container:eq(0) a')
<tr>" + //headers
Worker.doClick(friend[0])
"    <th scope=\"col\" style=\"color: #FF0000\">USER STATISTIC</th>" +
friend=$('span.friend_container:eq(1) a')
"    <th scope=\"col\">ACTUAL VALUE RATIO</th>" +
Worker.doClick(friend[0])
"    <th scope=\"col\">SPENT MONEY RATIO</th>" +
friend=$('span.friend_container:eq(2) a')
"    <th scope=\"col\">ONCE SOLD RATIO</th>" +
Worker.doClick(friend[0])
"  </tr>" +
work=$('div.buy a')
 
Worker.doClick(work[0])}
"  <tr>" + //headers
else if(point<45&&point>=25){
"    <td style=\"border-bottom: 1px solid #AAAAAA\" colspan=\"0\"></td>" +
hadWorked=true
"  </tr>" +
var work
 
var friend
"  <tr class=\"odd\">" + //Pet Value
if(point>=40){
"    <th scope=\"col\">Pet Value</th>" +
work=$('span.chore_container:eq(9) a')}
"    <th scope=\"col\">$" + addcommas(sum) + "</th>" +
if(point>=35){
"    <th scope=\"col\">$" + addcommas(sumB) + "</th>" +
work=$('span.chore_container:eq(2) a')}
"    <th scope=\"col\">$" + addcommas(sumC) + "</th>" +
if(point>=30){
"  </tr>" +
work=$('span.chore_container:eq(7) a')}
if(point>=25){
"  <tr class=\"even\">" + //Assets Value
work=$('span.chore_container:eq(5) a')}
"    <th scope=\"col\">Assets Value</th>" +
Worker.doClick(work[0])
"    <th scope=\"col\">$" + assets + "</th>" +
friend=$('span.friend_container:eq(0) a')
"    <th scope=\"col\">$" + assetsB + "</th>" +
Worker.doClick(friend[0])
"    <th scope=\"col\">$" + assetsC + "</th>" +
work=$('div.buy a')
"  </tr>" +
Worker.doClick(work[0])}
else if(point<25&&point>=20){
"  <tr class=\"even\">" + //A/V Ratio
hadWorked=true
"    <th scope=\"col\">A/V Ratio</th>" +
var work
"    <th scope=\"col\">" + atv.toFixed(3) + "</th>" +
var friend
"    <th scope=\"col\">" + atvB.toFixed(3) + "</th>" +
if(point>=20){
"    <th scope=\"col\">" + atvC.toFixed(3) + "</th>" +
work=$('span.chore_container:eq(3) a')}
"  </tr>" +
Worker.doClick(work[0])
friend=$('span.friend_container:eq(0) a')
"  <tr class=\"even\">" + //% Invested
Worker.doClick(friend[0])
"    <th scope=\"col\">% Invested</th>" +
friend=$('span.friend_container:eq(1) a')
"    <th scope=\"col\">" + pctInv.toFixed(2) + "%</th>" +
Worker.doClick(friend[0])
"    <th scope=\"col\">" + pctInvB.toFixed(2) + "%</th>" +
work=$('div.buy a')
"    <th scope=\"col\">" + pctInvC.toFixed(2) + "%</th>" +
Worker.doClick(work[0])}
"  </tr>" +
else if(point<20&&point>=10){
 
hadWorked=true
"</table>";
var work
var friend
var imgStatus, txtColor, txtStatus, imgFocus = "";
if(point>=15){
if (sum == 0 || pctInv == 0) {
work=$('span.chore_container:eq(1) a')}
imgStatus = "http://photos-d.ak.fbcdn.net/hphotos-ak-snc1/hs199.snc1/6732_124540464628_809274628_2224995_5768216_s.jpg";
if(point>=10){
txtColor = "#ffff00";
work=$('span.chore_container:eq(3) a')}
txtStatus = "InActive";
Worker.doClick(work[0])
}
friend=$('span.friend_container:eq(0) a')
else {
Worker.doClick(friend[0])
if (pctInvC > 50) {
work=$('div.buy a')
imgFocus = "<img src=\"http://dl2.glitter-graphics.net/pub/629/629752qjwkcxihg4.gif\" style=\"position: absolute; left: 65px; top: 71px;\" alt=\"FOCUS STARS\"/>";
Worker.doClick(work[0])}
}
if(i==pets.length-2){
Worker.goNext()}
imgStatus = "http://photos-c.ak.fbcdn.net/hphotos-ak-snc1/hs199.snc1/6732_124540459628_809274628_2224994_4009002_n.jpg";
if(hadWorked){
if (pctInvC > 85) {
return false}
txtColor = "#ff0000";
})}}
txtStatus = "Hot";
window.setTimeout(Worker.work,7000)
}
else if (pctInvC > 60) {
txtColor = "#770033";
txtStatus = "Profit";
}
else {
txtColor = "#444444";
txtStatus = "Active";
}
}
statistic_rank = "" +
//"<div>" +
"  <img src=\"" + imgStatus + "\" style=\"position: absolute; left: 65px; top: 71px;\" alt=\"PET STATUS\"/>" +
"  <a href=\"" + document.location.href + "\" style=\"width: 68px; height: 66px; display: block; color: " + txtColor + "; font-size: 14px; text-align: center; position: absolute; left: 67px; top: 88px;\" onclick=\"return wait_for_load(this, event, function() { (new Image()).src = &#039;/ajax/ct.php?app_id=7019261521&amp;action_type=3&amp;post_form_id=b21a05f78cb29762e39a7b37b6dec4f7&amp;position=3&amp;&#039; + Math.random();return true; });\">" + txtStatus +
"    <span style=\"font-size: 13px; display: block;\">pet</span>" +
"  </a>" +
//"</div>" +
imgFocus;
statistic_tag = "" +
"<table class=\"user_statistic_rank\" cellspacing=\"1\" width=\"70%\" border=\"1\" align=\"center\">" +
 
"  <tr>" + //headers
"    <th scope=\"col\" width=\"80px\">" + statistic_rank + "</th>" +
"    <td colspan style=\"text-align: right;\">" + statistic_info + "</td>" +
"  </tr>" +
"</table>";
 
document.body.innerHTML = document.body.innerHTML.replace("<ul class=\"navigation clearbox\"",
"<ul>" + statistic_tag + "</ul>" +
"<ul class=\"navigation clearbox\"");
//document.body.innerHTML = statistic_tag;
}
else {
//alert('DEBUG -->' + 'Dang xem Dashboard');
}

Revision as of 12:52, 16 March 2010

// ==UserScript== // @name FFS USER STATISTIC // @description Replace ads top panel by ratio info in all the profiles you visit. It also removes these blocks of ads at the top and bottom in Dashboard. // @include http://apps.facebook.com/friendsforsale/users/show/* // @include http://apps.new.facebook.com/friendsforsale/users/show/* // @include http://apps.facebook.com/friendsforsale/ // @include http://apps.new.facebook.com/friendsforsale/ // ==/UserScript==


// This is a subfunction to remove commas from text and // turn it into a number. function removecommas(txt) { return parseInt(txt.substring(1).replace(/,/g,""), 10); }

// And this is the subfunction to add commas to a number function addcommas(num) { var txt = String(num); var oRegEx = new RegExp('(-?[0-9]+)([0-9]{3})'); while(oRegEx.test(txt)) { txt = txt.replace(oRegEx, '$1,$2'); } return txt; }

//alert('DEBUG -->' + document.location.href); if ( document.location.href != "http://apps.facebook.com/friendsforsale/" && document.location.href != "http://apps.new.facebook.com/friendsforsale/") {//we are not in the dashboard //alert('DEBUG -->' + 'Dang xem Profile');

// Get all money amounts on the page var money = document.getElementsByClassName("money"); /*alert('money ' + money[0].innerHTML); //--> self cash**** alert('money ' + money[1].innerHTML); //--> self value alert('money ' + money[2].innerHTML); //--> self cash alert('money ' + money[3].innerHTML); //--> owner value alert('money ' + money[4].innerHTML); //--> owner cash alert('money ' + money[5].innerHTML); //--> first pet value alert('money ' + money[6].innerHTML); //--> first pet cash alert('money ' + money[7].innerHTML); //--> second pet value alert('money ' + money[8].innerHTML); //--> second pet cash ... */

// The second one is the user's value var value = removecommas(money[1].innerHTML);

// The third one is the user's cash var cash = removecommas(money[2].innerHTML);

//alert('DEBUG ' + ' value[' + value + '], cash[' + cash + ']');

// Get the parent of the last shown pet list // which should be the user's pets. var pets = document.getElementsByClassName("pets-item"); //pets = pets[pets.length - 1].getElementsByClassName("user_preview");

// initialize sum and sum2 to zero var pet, sum = 0, sum2 = 0;

// iterate through pets for (pet in pets) { // ignore any pets not displayed if (pets[pet].getElementsByClassName) { // first money amount is value, add to sum var petvalue = removecommas(pets[pet].getElementsByClassName("money")[0].innerHTML); sum += petvalue;

// name of the pet is innerHTML of second anchor var petname = pets[pet].getElementsByTagName("a")[1].innerHTML;

// sum2 will exclude pets named private if (petname != "private") { sum2 += petvalue; } } }

// Calculate prices for money spent and potential money once sold var sumB = Math.ceil(1.01*sum); var sum2B = Math.ceil(1.01*sum2); var sumC = Math.ceil(1.05*sum); var sum2C = Math.ceil(1.05*sum2);

// Calculate assets to value ratio, // format with three decimal places. var atv = (sum + cash)/value; var atv2 = (sum2 + cash)/value; var atvB = (sumB + cash)/value; var atv2B = (sum2B + cash)/value; var atvC = (sumC + cash)/value; var atv2C = (sum2C + cash)/value;

// Calculate percent invested, // format as percentage with two decimal places var pctInv = 100*(1-(cash/(sum + cash))); var pctInv2 = 100*(1-(cash/(sum2 + cash))); var pctInvB = 100*(1-(cash/(sumB + cash))); var pctInv2B = 100*(1-(cash/(sum2B + cash))); var pctInvC = 100*(1-(cash/(sumC + cash))); var pctInv2C = 100*(1-(cash/(sum2C + cash)));

// Calculate total assets; format with commas var assets = addcommas(sum + cash); var assetsB = addcommas(sumB + cash); var assetsC = addcommas(sumC + cash);

// Caculate total assets excluding private var assets2 = addcommas(sum2 + cash); var assets2B = addcommas(sum2B + cash); var assets2C = addcommas(sum2C + cash);

// Put together final output! // Calculations excluding private go in parens. var statistic_info =

"

" + " " + //headers " " + " " + " " + " " + " " + " " + //headers " " + " " + " " + //Pet Value " " + " " + " " + " " + " " + " " + //Assets Value " " + " " + " " + " " + " " + " " + //A/V Ratio " " + " " + " " + " " + " " + " " + //% Invested " " + " " + " " + " " + " " + "
USER STATISTICACTUAL VALUE RATIOSPENT MONEY RATIOONCE SOLD RATIO
Pet Value$" + addcommas(sum) + "$" + addcommas(sumB) + "$" + addcommas(sumC) + "
Assets Value$" + assets + "$" + assetsB + "$" + assetsC + "
A/V Ratio" + atv.toFixed(3) + "" + atvB.toFixed(3) + "" + atvC.toFixed(3) + "
% Invested" + pctInv.toFixed(2) + "%" + pctInvB.toFixed(2) + "%" + pctInvC.toFixed(2) + "%

";

var imgStatus, txtColor, txtStatus, imgFocus = ""; if (sum == 0 || pctInv == 0) { imgStatus = "http://photos-d.ak.fbcdn.net/hphotos-ak-snc1/hs199.snc1/6732_124540464628_809274628_2224995_5768216_s.jpg"; txtColor = "#ffff00"; txtStatus = "InActive"; } else { if (pctInvC > 50) { imgFocus = "<img src=\"http://dl2.glitter-graphics.net/pub/629/629752qjwkcxihg4.gif\" style=\"position: absolute; left: 65px; top: 71px;\" alt=\"FOCUS STARS\"/>"; }

imgStatus = "http://photos-c.ak.fbcdn.net/hphotos-ak-snc1/hs199.snc1/6732_124540459628_809274628_2224994_4009002_n.jpg"; if (pctInvC > 85) { txtColor = "#ff0000"; txtStatus = "Hot"; } else if (pctInvC > 60) { txtColor = "#770033"; txtStatus = "Profit"; } else { txtColor = "#444444"; txtStatus = "Active"; } } statistic_rank = "" +

//"

" +

" <img src=\"" + imgStatus + "\" style=\"position: absolute; left: 65px; top: 71px;\" alt=\"PET STATUS\"/>" + " <a href=\"" + document.location.href + "\" style=\"width: 68px; height: 66px; display: block; color: " + txtColor + "; font-size: 14px; text-align: center; position: absolute; left: 67px; top: 88px;\" onclick=\"return wait_for_load(this, event, function() { (new Image()).src = '/ajax/ct.php?app_id=7019261521&action_type=3&post_form_id=b21a05f78cb29762e39a7b37b6dec4f7&position=3&' + Math.random();return true; });\">" + txtStatus + " pet" + " </a>" +

//"

" +

imgFocus;

statistic_tag = "" +

"

" + " " + //headers " " + " " + " " + "
" + statistic_rank + "" + statistic_info + "

";

document.body.innerHTML = document.body.innerHTML.replace("<ul class=\"navigation clearbox\"",

"

    " + statistic_tag + "

" + "

    ' + 'Dang xem Dashboard'); }