User script

From GreaseSpot Wiki
Revision as of 12:52, 16 March 2010 by 180.191.16.239 (talk)
Jump to navigationJump to search

// ==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'); }