THIS IS NOW UNSUPPORTED CODE. Mafia wars has successfully bored the hell our of me.

I am leaving this code as an example on accessing remote apps on myspace via javascript. If you have any questions or requests related to trainers for opensocial apps like Mafia Wars, Get ahold of me via my myspace page. All email sent to this domain just gets sucked up by the spamcloud.

Do NOT clog my peepz.us email unless you seriously have something intellectual to contribute.


1. Get Firefox (if you don't have it already, shame on you.)

2. Get a plugin called Firebug and install it into Firefox. (this is the javascript interpreter we will use to execute our code)

3. Go to your myspace account and log in with firefox. Click on Mafia wars so it opens up

4. In the middle of the mafia wars page, right click somewhere in the space.

5. Go to This Frame -> View only this frame (this will cause just the mafia wars url to be displayed and opens up the javascript that was once hidden nicely inside that iframe.

6. You will notice a little bug in the lower right hand corner of the firefox window. Click that to open up firebug window.

7. You will see tabs on the right. go ahead and click the arrow next to "console" and choose "enabled" (this opens a pane on the right where we can run any nifty javascript we darn well please on the page.

8. Paste the below code into that window on the right and hit run. (Of course you pasted it into a text editor first, so you could edit all the parameters before you ran it, right?)

This is completely unsupported code. it will become a piece of a much larger set of framework so if it works for you, great, but don't do trying anything stupid and ruin everyone's fun.

//First we set up some global variables for the functions to use
var jobNumber=35;  // This is the number of the job that will be done (you can view the source for this)
var jobEnergy=40;  // This is the amount of energy required to do the job

// You should not have to modify anything from here down
var curtimeindex=0;  // This is the counter for the current time index, so we don't execute too fast
var repeattime=1500000;  // this is the amount of time (in milliseconds) to repeat the loop
var runcount=0;  // Keep track of how many itterations we have (mostly for debugging at this point)

// tracking for user variables
   var mycash=null;
   var mystamina=null;
   var myenergy=null;
   var myhitamt=null;

// Junk variables for use in the varius procedures.  These are global because I plan to hold a cache and execute without having to load the page
var fighter=null;
var fightlist=null;
var bvb = null;

function doAll() {
   showHitAmount();
   curtimeindex = 10000;
   setTimeout('setUserVars()',curtimeindex);
   incTime(10000);
   setTimeout('doStuff()',curtimeindex);
   setTimeout('doAll()',repeattime);
}

function doStuff() {
   // this deposits cash into your account
   if (mycash > 1000) {
      setTimeout('doDeposit(mycash)',curtimeindex);
      incTime(10000);
      
   }
   //check to see if there is enough energy to complete the job
   if (getUserValue('user_energy')>=jobEnergy){
      setTimeout('doJob(jobNumber)',curtimeindex);
      incTime(10000);
      setTimeout('showFights()',curtimeindex);
      for(i=0;i 35) {
         incTime(10000);
         setTimeout('doWithdraw(getUserValue("user_stamina")*myhitamt)',curtimeindex);
         incTime(10000);
         setTimeout('showHome()',curtimeindex);
         incTime(10000);
         setTimeout('doRevenge()',curtimeindex);
         incTime(20000);
         setTimeout('delNews()',curtimeindex);
         mystamina=mystamina-5;
      } else {
         console.debug('less than 25 stamina. skipping revenge');
         incTime(10000);
         setTimeout('showHits()',curtimeindex);
      }
      // either way we end up on the hitlist page, so we use the rest of our stamina to try to knock out some hits
      for(i=0;i 0) { 
      if (fightType == 'last') { console.debug('fighting last');
         //grab the last person on the hitlist
         fighter=fightlist.length-1 ;
      } else { console.debug('fighting randomt');
         // just grab a random person to attack
         fighter=Math.floor(Math.random()*fightlist.length+1)-1;
      }
      ZY.View.post('fight.php', {action: 'attack', opponent_id:fightlist[fighter].value});
   }
}

function doHit(hitType){
   fightlist=document.getElementsByName("target_id");
   if (fightlist.length > 0) {
      if (hitType == 'last') { console.debug('hitting last');
         //grab the last person on the hitlist
         fighter=fightlist.length-1 ;
      } else { console.debug('hitting random');
         // just grab a random person to attack
         fighter=Math.floor(Math.random()*fightlist.length+1)-1;
      }
      ZY.View.post('hits.php', {action: 'attack', target_id:fightlist[fighter].value});
   }   
}

function doBankDeposit() {
   //Read the value of the deposit box. if it's over the minimum, deposit it.
   bvb=document.getElementsByName("amount");
   if (bvb[1].value>1000){
      ZY.View.post('bank.php', {amount: bvb[1].value, action: 'Deposit'});
   }
}
function doDeposit(howmuch) {
   ZY.View.post('bank.php', {amount: howmuch, action: 'Deposit'});
}

function doRevenge() {
  //Grab a list of users who have attacked us and place a hit out on the last ones
  var divArray = getElementsByStyleClass("news_content");
  var unduped = new Object;
  for (var i = 0; i0) {
      var int1=m[1];
      int1.replace(/ 4) {
      uniques.push(unduped[k]);
    }
  }
  var mylocaltime = 5000;
  hit1=uniques[0];
  hit2=uniques[1];
  hit3=uniques[2];
  hit4=uniques[3];
  hit5=uniques[4];
  for (var i = 0; i < uniques.length; i++) {   
  }   
  setTimeout('orderHit(myhitamt,hit1)',5000);
  setTimeout('orderHit(myhitamt,hit2)',10000);
  setTimeout('orderHit(myhitamt,hit3)',15000);
  setTimeout('orderHit(myhitamt,hit4)',20000);
  setTimeout('orderHit(myhitamt,hit5)',25000);
  
}

function doRevenge1() {
  //Legacy doRevenge (this will be the new one with the abillity to set number and autodetect stamina)
  var divArray = getElementsByStyleClass("news_content");
  var unduped = new Object;
  for (var i = 0; i0) {
      var int1=m[1];
      int1.replace(/ 4) {
      uniques.push(unduped[k]);
    }
  }
  var mytarget=uniques[1];
  console.log(mytarget);
  ZY.View.get('hits.php', {action:'create', amount:'9000000', target_id:mytarget, submit:'Set Bounty'});
}

//  Misc Support Functions
function getElementsByStyleClass (className) {
  // added for getelementbyid functionality to work with styles instead
  var all = document.all ? document.all :
    document.getElementsByTagName('*');
  var elements = new Array();
  for (var e = 0; e < all.length; e++)
    if (all[e].className == className)
      elements[elements.length] = all[e];
  return elements;
}

function RemoveNonNumeric(strString){
      var strValidCharacters = "1234567890";
      var strReturn = "";
      var strBuffer = "";
      var intIndex = 0;
      for( intIndex = 0; intIndex < strString.length; intIndex++ ) {
            strBuffer = strString.substr( intIndex, 1 );
            if( strValidCharacters.indexOf( strBuffer ) > -1 ) {
                  strReturn += strBuffer;
            }
      }
      return strReturn;
}

// call the whole shebang in one step
doAll();