Advertisement
Guest User

drinkmorecoffee's Martingale Bot for just-dice.com

a guest
Oct 16th, 2013
644
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name    drinkmorecoffee's Martingale Bot
  3. // @namespace   none
  4. // @author      Original script by Gray, modifications by drinkmorecoffee
  5. // @version     2.0.0
  6. // @include     https://just-dice.com/*
  7. // @grant       none
  8. // ==/UserScript==
  9.  
  10. /* Version 2 change notes [drinkmorecoffee]
  11.  *
  12.  * To use:
  13.  *
  14.  *  * See Gray's installation notes below.  One additional step, find the variable "userID"
  15.  *    and update it to reflect your account's uid value.  
  16.  *
  17.  * Current known issues:
  18.  *
  19.  *  * If betting is stopped using "stop" or "stop on win", the page must be reloaded
  20.  *    in order to resume operation.  "Start" has no effect and "Resume" will lock up the script.
  21.  *
  22.  *  * When reloading, the script will pull the starting bet from the server's init message.
  23.  *    This means that the initial bet may miss either a double down or reset to your initial bet.
  24.  *    The effect is usually trivial, but still worth mentioning as it could be noticeable if the site
  25.  *    resets after a large loss streak (when bet values are large).
  26.  *
  27.  * BACKGROUND:
  28.  *
  29.  * In its original state (Gray, v1.1), this script would crash almost immediately on just-dice.com,
  30.  * with the server asking if the user was betting from multiple locations.  While the Martingale
  31.  * math looked solid, the script just didn't work reliably on that page.  This may be due to
  32.  * server side changes, because this script was well known when I was first searching for a tool like this.
  33.  * If it were simply unreliable, it wouldn't have been so popular.  
  34.  *
  35.  * To fix it, the script was modified to rely less heavily on header messages to determine
  36.  * things like wins and losses, opting instead to directly monitor real-time visual status of relevant page elements.
  37.  *
  38.  * This approach more closely mimics the behavior of a human player who, for example, would spot a win by noticing
  39.  * that the win counter changed (and more accurately, increased).  Further, bet amounts are read directly
  40.  * from (and written directly to) page elements, ensuring that the script always performs math on the correct values.  
  41.  * Tracking these elements solely within the script can be problematic given this site's
  42.  * nontrivial lag times; it's very possible that the script values may not match the current state of the site.
  43.  *
  44.  * Please note that I did not create this script.  
  45.  * All credit for the idea and initial implementation go to Gray, and his donation address is maintained below.
  46.  * If you like the script at all, please remember to toss a few Satoshis his way.
  47.  *
  48.  * If you appreciate my work on the functional alterations and feel inclined to tip, buy me a beer!
  49.  * 1GSbiUPeASc6X78TPzohGfVquvtG2Soqow
  50.  *
  51.  * CYA:
  52.  *
  53.  * As always, use of this script is done at your own risk.  By using it you agree that no one but yourself will be held liable
  54.  * for any losses incurred through the use of this tool or any others like it.  
  55.  * This was created as a learning project and is intended to be used solely for entertainment.
  56.  * Never risk more than you can afford to lose, you know the drill.  
  57.  *
  58. **/
  59.  
  60.  
  61. /* How would you go about using this?
  62.  *
  63.  * Install Greasemonkey plugin for Firefox
  64.  * Install Firebug plugin for Firefox (It's better than the builtin console.)
  65.  *
  66.  * Make a new script with Greasemonkey
  67.  * Type whatever you want into the form
  68.  * Then paste this whole file into the editor
  69.  *
  70.  * Adjust to your needs.
  71.  * Run.
  72.  *
  73.  * Other things you can do:
  74.  *
  75.  * That's it!
  76.  *
  77.  * Made a profit and feel like tipping people without seeing their genitals?
  78.  *
  79.  * Go ahead: 1Gray1ZsWo3kKBaCYdigiyPkD1pUnBqPxo
  80.  *
  81.  * Now go have fun with this... thing!
  82. **/
  83.  
  84.  
  85. $('<script>').attr({
  86.     src: 'http://d3js.org/d3.v3.min.js',
  87.     charset: 'UTF-8'
  88. }).appendTo(document.body);
  89.  
  90. $(function() {
  91.     var markup = '<div class="bot-controls"><fieldset><div class="row"><p class="llabel">bet start</p><input id="gb_bet" value="0.00001"><p class="rlabel">BTC</p></div><div class="row"><p class="llabel">chance</p><input id="gb_chance" value="50"><p class="rlabel">%</p></div></fieldset><fieldset><div class="row"><p class="llabel">bet multiplier</p><input id="gb_multiplier" value="2"><p class="rlabel" title="The bet gets multiplied by [mutiply factor] every [interval] steps.">x</p></div><div class="row"><p class="llabel">interval</p><input id="gb_interval" value="1"><p class="rlabel" title="The bet gets multiplied by [mutiply factor] every [interval] steps.">&nbsp;</p></div></fieldset><fieldset><div class="row"><p class="llabel">bet stop</p><input id="gb_betstop" value="0.01"><p class="rlabel">BTC</p></div><div class="row"><p class="llabel">profit stop</p><input id="gb_stopprofit" value="0.1"><p class="rlabel">BTC</p></div></fieldset><div class="clear"></div><div class="button_group"><button class="button_label action_toggle">start</button><div class="actions button_inner_group"><button id="gba_start">start</button><button id="gba_resume">resume</button><button id="gba_roll">roll</button><button id="gba_autorecover">autorecover</button></div></div><div class="button_group"><button class="button_label action_toggle">halt</button><div class="actions button_inner_group"><button id="gba_stop">stop</button><button id="gba_stoponwin">stop on win</button></div></div><div class="button_group"><button class="button_label action_toggle">roll</button><div class="actions button_inner_group"><button id="gba_rollhi">hi</button><button id="gba_rolllo">lo</button><button id="gba_rollrand" title="Grabs random bytes from random.org">random</button><button id="gba_rollswitch">switch on loss</button></div></div><div class="button_group"><button class="button_label action_toggle">chaos</button><div class="actions button_inner_group"><button id="gba_chaos">go</button></div><div class="clear"></div></div><div class="bot-stats"><div class="statspanel"><h2>Bot Stats</h2><div class="slabel">Status:</div><span id="gbs_status">Halted</span><span id="gbs_statusmessage"></span><div class="clear"></div><div class="slabel">Bets placed:</div><span id="gbs_bet">0</span><div class="clear"></div><div class="slabel">Bets won:</div><span id="gbs_betwin">0</span><div class="clear"></div><div class="slabel">Bets lost:</div><span id="gbs_betlost">0</span><div class="clear"></div><div class="slabel">Longest streak:</div><span id="gbs_streak">0</span><div class="clear"></div></div><div class="statspanel"><h2>More Stats</h2><div class="slabel">Rollmode:</div><span id="gbs_rollmode">random</span><span id="gbs_rollmodecurrent">lo</span><div class="clear"></div><div class="slabel">Wagered:</div><span id="gbs_wagered">0</span><div class="clear"></div><div class="slabel">Profit:</div><span id="gbs_myprofit">0</span><div class="clear"></div><div class="slabel">Stop at profit:</div><span id="gbs_stopprofit">none</span><div class="clear"></div><div class="slabel">Autorecover after server restart:</div><span id="gbs_autorecover">no</span></div></div><div class="clear"></div><div class="bot-foot">Made a nice profit? Tips are welcome!</div><div class="bot-foot">1Gray1ZsWo3kKBaCYdigiyPkD1pUnBqPxo (Gray, original script)</div><div class="bot-foot">1GSbiUPeASc6X78TPzohGfVquvtG2Soqow (drinkmorecoffee, v2)</div>';
  92.         $panelWrapper = $('<div>').attr('id','dmcbot').css({display: 'none'}).insertAfter('#faq'),
  93.         $panel = $('<div>').addClass('panel').append(markup).appendTo($panelWrapper),
  94.         $bal = $("#pct_balance"),
  95.         $in_bet = $('#gb_bet'),
  96.         $in_chance = $('#gb_chance'),
  97.         $in_multiplier = $('#gb_multiplier'),
  98.         $in_interval = $('#gb_interval'),
  99.         $in_betstop = $('#gb_betstop'),
  100.         $in_stopprofit = $('#gb_stopprofit'),
  101.         $a_start = $('#gba_start'),
  102.         $a_resume = $('#gba_resume'),
  103.         $a_roll = $('#gba_roll'),
  104.         $a_stop = $('#gba_stop'),
  105.         $a_stoponwin = $('#gba_stoponwin'),
  106.         $a_rollhi = $('#gba_rollhi'),
  107.         $a_rolllo = $('#gba_rolllo'),
  108.         $a_rollrand = $('#gba_rollrand'),
  109.         $a_rollswitch = $('#gba_rollswitch'),
  110.         $a_chaos = $('#gba_chaos'),
  111.         $a_autorecover = $('#gba_autorecover'),        /* added in v2, [drinkmorecoffee] */
  112.         $s_status = $('#gbs_status'),
  113.         $s_statusmessage = $('#gbs_statusmessage'),
  114.         $s_bet = $('#gbs_bet'),
  115.         $s_betwin = $('#gbs_betwin'),
  116.         $s_betlost = $('#gbs_betlost'),
  117.         $s_streak = $('#gbs_streak'),
  118.         $s_rollmode = $('#gbs_rollmode'),
  119.         $s_rollmodecurrent = $('#gbs_rollmodecurrent'),
  120.         $s_wagered = $('#gbs_wagered'),
  121.         $s_myprofit = $('#gbs_myprofit'),
  122.         $s_autorecover = $('#gbs_autorecover'),
  123.         $s_stopprofit = $('#gbs_stopprofit');
  124.  
  125.     /* System stuff */
  126.     this.initialized = false;
  127.     this.auto = false;
  128.     this.manual = false;
  129.     this.stoponwin = false;
  130.     this.stoponprofit = false;
  131.     this.bet = 0;
  132.     this.streak = 0;
  133.     this.statusmessage = "";
  134.     this.lastbetOutcome = null;
  135.  
  136.     /* Stats */
  137.     this.stats = {
  138.         won: 0,
  139.         lost: 0,
  140.         maxStreak: 0,
  141.         currentProfit: 0,
  142.         wagered: 0     
  143.     }
  144.  
  145.     /* win/los stats for current round */
  146.     var total_wins = "0";
  147.     var total_losses = "0";
  148.    
  149.     var streakLimit = 12;   /* Change bet strategy after this many losses.  See this.isLoss(). */
  150.    
  151.     /* win/loss stats for previous round.  Used to determine outcome of last round. */
  152.     /* This is a sort of built in delay, since the next round won't start
  153.        until the page reports the outcome of the previous round. */
  154.     var last_total_wins = "0";
  155.     var last_total_losses = "0";
  156.    
  157.     /* win/loss transition flag, indicating the outcome of last round */
  158.     var waiting_for_result = false;
  159.    
  160.     /* should prevent multiple messages stacking up and confusing the server */
  161.     var socket_busy = false;
  162.    
  163.     /* semaphore to block the bet button press event, should only happen once per bet. */
  164.     var bet_in_progress = false;
  165.    
  166.     /* time stamp of last bet.  Used to track page performance and recover from server resets, etc. */
  167.     var timestamp = 0;
  168.     /* Maximum time to wait before reloading the page and starting over.  Units: milliseconds */
  169.     var serverLagTimeout = 60 * 1000;  
  170.     /* another autorecover attempt */
  171.     var autorecover_status = false;
  172.     var delay_ms = 0;
  173.    
  174.     /* more experimental timeout stuff */
  175.     var time_last_good_response_received = 0;
  176.     var time_since_last_good_response = 0;
  177.     var right_now = 0;
  178.     var response_lag = 0;
  179.    
  180.     /* Parameters */
  181.     /* [drinkmorecoffee] the "initial bet" value below is actually specified by this script in the code above (see definition for var markup).
  182.        I believe it's still more consistent to read it like the other values, but you may want to change it
  183.        to suit your coding style. */      
  184.     this.initialBet = document.getElementById('gb_bet').value;
  185.     this.maxBet = parseFloat(localStorage.getItem('gb_maxBet')) || 0.01;
  186.  
  187.     this.initialBalance = 0;
  188.     this.currentBalance = 0;
  189.     this.profitStop = parseFloat(localStorage.getItem('gb_profitStop')) || 0;
  190.    
  191.     this.multiplyFactor = parseFloat(localStorage.getItem('gb_multiplyFactor')) || 2; // Current bet is multiplied by [multiplyFactor] every [interval] rolls
  192.     this.interval = parseFloat(localStorage.getItem('gb_interval')) || 1;
  193.     this.chance = parseFloat(localStorage.getItem('gb_chance')) || 49.5;
  194.  
  195.     this.hi_lo = "hi";
  196.     this.rollRandom = true;
  197.     this.rollSwitch = false;
  198.  
  199.     this.byteLock = false;
  200.     this.byteCount = 0;
  201.     this.byteOffset = 0;
  202.    
  203.     /* [drinkmorecoffee] The below variable seems to have no effect whatsoever. */
  204.     this.delay = 4000; // Wanna go slower or faster? Set this. Milliseconds.
  205.  
  206.     var last_bet = 0;
  207.     var current_bet = "0";
  208.    
  209.     /* your account's UID - required for proper script operation! */
  210.     var userID = "";    
  211.    
  212.     /* [drinkmorecoffee] Bet control buttons */
  213.     var double_button = document.getElementById('b_double');
  214.     var half_button = document.getElementById('b_half');
  215.     var bet_hi_button = document.getElementById('a_hi');
  216.  
  217.     this.init = function() {
  218.         if(this.initialized) {
  219.             return;
  220.         }
  221.  
  222.         this.initialized = true;
  223.         // Bind events
  224.         /*socket.on("wins", this.isWin);
  225.         socket.on("losses", this.isLoss);
  226.         socket.on("jderror", this.isError); //*/
  227.  
  228.         socket.on("result", this.setBalance);
  229.         socket.on("init", this.setBalance);
  230.  
  231.         $in_bet.val(tidy(this.initialBet));
  232.         $in_chance.val(this.chance);
  233.         $in_multiplier.val(this.multiplyFactor);
  234.         $in_interval.val(this.interval);
  235.         $in_betstop.val(tidy(this.maxBet));
  236.         $in_stopprofit.val(tidy(this.profitStop));
  237.        
  238.         this.getNewRand();
  239.  
  240.         this.updateStats();
  241.                        
  242.     }
  243.  
  244.     /* The following routine will execute once the page has completely loaded.
  245.        This is necessary because the this.start() routine pulls from page element data,
  246.        and if those elements haven't yet loaded, it will return null and crash the script.
  247.        Note, the setTimeout functionality seems to work nicely here;
  248.        I have no idea why it fails elsewhere in this script. */
  249.     $(window).bind("load", function() {
  250.    
  251.         /* [drinkmorecoffee] Check the autorecover flag to see if we should begin automatically.  
  252.         If set, this will allow the system to start after auto-reloading following a server reset. */
  253.         autorecover_status = localStorage.getItem('autorecover');
  254.            
  255.         if(autorecover_status == 'true')
  256.         {
  257.             window.setTimeout(function() {console.log("Automatically started after page load.");MG.start();}, 4000);
  258.            
  259.         }
  260.        
  261.     });
  262.  
  263.     /* If enabled, this feature will automatically begin betting on page load.
  264.        The site lag monitor feature down in this.setBalance will reload the page if the server resets.
  265.        If this feature is enabled, the result is that your betting continues (i.e., through the night)
  266.        without interruption or user input.  */
  267.     this.autoRecover = function() {
  268.        
  269.         autorecover_status = localStorage.getItem('autorecover');
  270.        
  271.         if (autorecover_status == 'true')
  272.         {
  273.             localStorage.setItem('autorecover', 'false');
  274.             document.getElementById('msg').innerHTML = "Script will NOT automatically reload the page and begin betting in the event of server reset.";
  275.         }
  276.         else
  277.         {
  278.             localStorage.setItem('autorecover', 'true');
  279.             document.getElementById('msg').innerHTML = "Script will reload the page and automatically begin betting in the event of server reset.";
  280.         }
  281.         this.updateStats();
  282.    
  283.     };
  284.  
  285.     this.setBalance = function(data) {
  286.        
  287.         /* [drinkmorecoffee] This section will monitor the time lag between the last network response
  288.            to one of our bets and the most recent network response to anyone else's bet.  In short,
  289.            it's monitoring website lag.  If the server resets, our bet will be lost and it won't report
  290.            a win/loss, so the script will wait infinitely.  This routine waits for the site's bet log to
  291.            start rolling again, monitoring the time since our last bet result was received.  
  292.            When the lag is great enough, the script determines that the site has reset
  293.            and reloads the page.  If the "autorecover" feature is enabled, betting will continue without
  294.            user input.  */
  295.    
  296.         if (this.auto === true)    /* only perform this timestamp checking if we're actually betting */
  297.         {
  298.             if(data['uid'] === userID) /* this message is intended for us */
  299.             {
  300.                 time_last_good_response_received = new Date().getTime();         /* time stamp of current message */
  301.  
  302.             }
  303.             else /* this message is NOT intended for us */
  304.             {
  305.                  right_now = new Date().getTime();                               /* get current time */
  306.                  response_lag = right_now - time_last_good_response_received;    /* this is the server lag time */
  307.             }
  308.            
  309.             /* Time out event.  Page took too long to load.  Reload it.
  310.                Note, the extra check for 100x timeout is to help with the initial launch.  
  311.                On page load, the first check is (current time - zero), which is huge.  Disregard this value. */
  312.             if ((response_lag > serverLagTimeout) && (response_lag < (100 * serverLagTimeout)))  
  313.             {
  314.                 if (localStorage.getItem('autorecover') === 'true')              /* Only proceed if autorecover is enabled */
  315.                 {
  316.            
  317.                   /* Reload the page. */
  318.                    window.location.reload(true);
  319.                  
  320.                 }
  321.             }
  322.         }
  323.        
  324.         /* process the site's win/loss report */
  325.         if(data.uid == uid && data.balance) {
  326.             var bal = parseFloat(data.balance);
  327.             this.currentBalance = bal;
  328.             if(this.initialBalance===0) {
  329.                 this.initialBalance = bal;
  330.             }
  331.             if(data['win'] === true) {
  332.                 this.isWin(data);
  333.             } else if(data['win'] === false) {
  334.                 this.isLoss(data);
  335.             }
  336.         }
  337.     }
  338.     this.setBalance = this.setBalance.bind(this);
  339.  
  340.     this.start = function() {
  341.         this.auto = true;
  342.         this.manual = false;
  343.         this.statusmessage = "";
  344.         this.bet = this.initialBet;
  345.         this.stats.currentProfit = 0;
  346.        
  347.         total_wins = document.getElementById('wins').firstChild.data;
  348.         total_losses = document.getElementById('losses').firstChild.data;
  349.        
  350.         waiting_for_result = false;
  351.        
  352.         this.roll();
  353.     };
  354.    
  355.     this.stop = function(stoponwin) {
  356.         if(stoponwin) {
  357.                 this.stoponwin = true;
  358.         } else {
  359.                 this.auto = false;
  360.         }
  361.        
  362.         /* [drinkmorecoffee] Allow betting to resume using "start" or "resume" buttons.
  363.            Note, this doesn't work.  No idea why.  If you stop or stop-on-win,
  364.            you have to reload the page to begin again.*/
  365.         bet_in_progress = false;
  366.        
  367.         this.updateStats();
  368.     };
  369.     this.resume = function() {
  370.    
  371.        /* [drinkmorecoffee] Note, this feature is still a little buggy.  Not sure what's going on.  */
  372.         this.auto = true;
  373.         this.roll();
  374.     };
  375.  
  376.     this.getNewRand = function() {
  377.         this.byteLock = true;
  378.         $.get("http://www.random.org/integers/?num=256&min=0&max=1024&col=2&base=2&format=plain&rnd=new", function(bytes) {
  379.             bytes = bytes.replace(/[^01]/g,'');
  380.             MG.bytes = bytes;
  381.             MG.byteCount = bytes.length;
  382.             MG.byteOffset = 0;
  383.             MG.byteLock = false;
  384.             MG.setHiLo();
  385.         });
  386.     }
  387.  
  388.  
  389.     this.setHiLo = function() {
  390.         if(this.rollRandom) {
  391.             this.hi_lo = (this.bytes[this.byteOffset++] === '1') ? 'hi' : 'lo';
  392.             if(this.byteOffset === this.byteCount) {
  393.                 this.getNewRand();
  394.             }
  395.         } else if(this.rollSwitch) {
  396.  
  397.         }
  398.     }
  399.  
  400.  
  401.     this.roll = function() {      
  402.                
  403.         /* [drinkmorecoffee] This function was causing problems in Gray's original code,
  404.            as it would place bets far too quickly.  Even the hard-coded delays
  405.            used in the window.setTimeout function below didn't help because
  406.            the site itself introduces inconsistent and nontrivial delays between bets.
  407.            This method will check the visual display elements, waiting for the site itself
  408.            to report a win or loss, just like you would do if playing manually.  */
  409.         while(waiting_for_result)
  410.         {
  411.  
  412.            /* capture previous win/loss count */
  413.            last_total_wins = total_wins;
  414.            last_total_losses = total_losses;
  415.            
  416.            /* get updated win/loss count */
  417.            total_wins = document.getElementById('wins').firstChild.data;
  418.            total_losses = document.getElementById('losses').firstChild.data;
  419.            
  420.            /* Look for a change, clear the wait flag */
  421.            /* This whole loop is just a basic delay to ensure the site is ready for
  422.               the next bet.  */
  423.            if ((total_wins > last_total_wins) || (total_losses > last_total_losses))
  424.            {
  425.                waiting_for_result = false;
  426.                bet_in_progress = false;
  427.                
  428.                /* When did this occur? */
  429.                timestamp = new Date().getTime();
  430.                
  431.            }
  432.            else
  433.            {
  434.                /* page has not yet reported a win/loss.  See how long it's taken so far. */
  435.                var currentTime = new Date().getTime;
  436.                var serverLag = currentTime - timestamp;
  437.                
  438.                alert("Site took " + serverLag + " milliseconds to report that result.");
  439.                
  440.                /* Specify the maximum time to wait for a win/loss report.  
  441.                   This should be a long delay, maybe 30-60 seconds.  It's intended to catch server resets. */
  442.                if (serverLag > serverLagTimeout)
  443.                {
  444.                    /* reload the page */
  445.                    window.location.reload(true);
  446.                }
  447.            
  448.            }
  449.            
  450.        
  451.         }
  452.          
  453.         /* [drinkmorecoffee] Note, the setTimeout function doesn't seem to honor the specified delays.  
  454.            As such we had to implement the while loop below, using Date().getTime() to determine delay timouts.
  455.            It's ugly, but stable.  */
  456.            
  457.         /* Note also that this delay method may not be required, given that we're already waiting for the
  458.            visual page elements to report a win/loss.  It's included here for completeness, but you might
  459.            want to experiment with removing it. */
  460.        
  461.         /* We're about to place a bet - this flag will force the above wait loop to execute next time. */
  462.         waiting_for_result = true;
  463.  
  464.         //short delay
  465.         //wait_ms(250);        
  466.        
  467.         //window.setTimeout(this.placeBet, this.delay);    
  468.         this.placeBet();
  469.        
  470.     };
  471.  
  472.  
  473.  
  474.     this.placeBet = function() {
  475.    
  476.            if(this.auto || this.manual)
  477.            {
  478.            
  479.                if (bet_in_progress == false)
  480.                {
  481.                    bet_hi_button.click();
  482.                    bet_in_progress = true;
  483.                }
  484.                 /* [drinkmorecoffee] Commented in favor of the above code, which interacts with website elements directly.
  485.                 socket.emit("bet", csrf, {
  486.                 chance: "" + this.chance,
  487.                 bet: this.bet.toFixed(8),
  488.                 which: this.hi_lo
  489.                 });
  490.                 */
  491.            
  492.            }
  493.        
  494.            
  495.             if(this.rollRandom && this.byteLock) {
  496.                 window.setTimeout(this.placeBet, this.delay);
  497.                 return;
  498.             } else {gtre
  499.                 this.setHiLo();
  500.             }
  501.            
  502.        
  503.     };
  504.     this.placeBet = this.placeBet.bind(this);
  505.  
  506.     this.isWin = function(data) {
  507.         this.streak = 0;
  508.         this.stats.won++;
  509.         this.stats.wagered += this.bet;
  510.         this.lastbetOutcome = true;
  511.        
  512.         /* reset the bet to original amount */
  513.         document.getElementById('pct_bet').value = this.initialBet;
  514.        
  515.         if(this.stoponprofit && (this.currentBalance-this.initialBalance) > this.profitStop) {
  516.             this.auto = false;
  517.             this.stoponprofit = false;
  518.             this.statusmessage = "profit limit";
  519.         } else if(this.stoponwin) {
  520.             this.auto = false;
  521.             this.stoponwin = false;
  522.             this.statusmessage = "stop on win";
  523.         } else if(this.auto) {
  524.             this.roll();
  525.         }
  526.         this.updateStats();
  527.     };
  528.     this.isWin = this.isWin.bind(this);
  529.  
  530.     this.isLoss = function(data) {
  531.         this.streak++;
  532.         this.stats.lost++;
  533.         this.stats.wagered += this.bet;
  534.         this.lastbetOutcome = false;
  535.        
  536.         /* [drinkmorecoffee]
  537.            Martingale is all about taking appropriate action in the event of a loss.  If done right,
  538.            you can come away with a small but consistent profit even though you'll lose just over half the time.
  539.            
  540.            Problem is, a long streak can wipe you out.  You have to have a plan to deal with this eventuality.
  541.            This section checks the current loss streak, and takes appropriate action if loss streak reaches "streakLimit". */
  542.         if(this.streak >= streakLimit)
  543.         {
  544.             /* [drinkmorecoffee] */
  545.            
  546.             /* Strategy 1 - if the streak exceeds a certain length, just keep betting that amount.
  547.                This will still use Martingale until a certain number of losses, then will stop doubling.
  548.                Note, this strategy requires no code in this section.*/
  549.        
  550.             /* Strategy 2 - reset your bet to this.initialBet after too many losses.  
  551.                Standard Martingale up to this point, then just eat it and start over.  */
  552.             //document.getElementById('pct_bet').value = this.initialBet;
  553.            
  554.             /* Uncomment the next line if you want to reset the streak counter when it reaches the streakLimit you set earlier.
  555.                I've found that leaving it out is more meaningful because it will show how long the streak of losses actually was.  */
  556.             //this.streak = 0;
  557.         }
  558.         else
  559.         {
  560.             /* [drinkmorecoffee] Double down */
  561.             document.getElementById('pct_bet').value = parseFloat(data['bet']) * 2;
  562.          
  563.         }
  564.        
  565.         /* [drinkmorecoffee] Update max loss streak counter */
  566.         this.stats.maxStreak = Math.max(this.streak, this.stats.maxStreak);
  567.        
  568.         if(this.bet > this.maxBet) {
  569.             this.statusmessage = "bet limit";
  570.             this.stoponwin = false;
  571.             this.auto = false;
  572.         } else if(this.auto) {
  573.             if(this.rollSwitch) {
  574.                 this.hi_lo = (this.hi_lo === 'hi') ? 'lo' : 'hi';
  575.             }
  576.  
  577.             this.roll();
  578.         }
  579.         this.updateStats();
  580.     };
  581.     this.isLoss = this.isLoss.bind(this);
  582.  
  583.     this.isError = function(data) {
  584.         this.auto = false;
  585.         console.log('Error. Halting.');
  586.         console.log(data);
  587.     };
  588.     this.isError = this.isError.bind(this);
  589.  
  590.     this.updateStats = function() {
  591.         var status = this.auto ? "Running" : (this.manual ? "Manual" : "Halted"),
  592.             rollmode, currentroll;
  593.  
  594.         if(this.stoponwin && this.stoponprofit) {
  595.             status += '; SW|SP';
  596.         } else if(this.stoponwin) {
  597.             status += '; SW';
  598.         } else if(this.stoponprofit) {
  599.             status += '; SP';
  600.         }
  601.  
  602.         if(this.rollRandom) {
  603.             rollmode = 'random';
  604.             $s_rollmodecurrent.text(this.hi_lo).css('display', '');
  605.         } else if(this.rollSwitch) {
  606.             rollmode = 'switch';
  607.             $s_rollmodecurrent.text(this.hi_lo).css('display', '');
  608.         } else {
  609.             rollmode = this.hi_lo;
  610.             $s_rollmodecurrent.text(currentroll).css('display', 'none');
  611.         }
  612.  
  613.         $s_status.text(status);
  614.         $s_bet.text(this.stats.won + this.stats.lost);
  615.         $s_betwin.text(this.stats.won);
  616.         $s_betlost.text(this.stats.lost);
  617.         $s_streak.text(this.stats.maxStreak);
  618.         $s_rollmode.text(rollmode);
  619.        
  620.         /* [drinkmorecoffee] Firefox reported an error with the next line, said ".toFixed()" is not a function.
  621.            Just had to parse the text as a float first, then it worked.  */
  622.         $s_wagered.text(commaify(parseFloat(this.stats.wagered).toFixed(8)));
  623.         //$s_wagered.text(commaify(this.stats.wagered.toFixed(8)));
  624.        
  625.         $s_myprofit.text(commaify((this.currentBalance-this.initialBalance).toFixed(8)));
  626.         $s_stopprofit.text(this.profitStop ? commaify(this.profitStop.toFixed(8)) : 'none');
  627.         $s_autorecover.text(localStorage.getItem('autorecover'));
  628.  
  629.         if(this.statusmessage) {
  630.             $s_statusmessage.text(this.statusmessage).css('display', '');
  631.         } else {
  632.             $s_statusmessage.text('').css('display', 'none');
  633.         }
  634.     }
  635.  
  636.  
  637.     // Some styling // There are other ways for this. Bear with me. ;)
  638.     $('<style>').append('\
  639.     #graysbot .bot-stats,\
  640.     #graysbot .button_group {\
  641.         margin-top: 16px;\
  642.     }\
  643.     #graysbot .bot-stats .slabel {\
  644.         width: 200px;\
  645.     }\
  646.     #graysbot #gba_chaos {\
  647.         background-color: #FFCCCC;\
  648.         border: 5px solid #CC9999;\
  649.     }\
  650.     #graysbot #gba_chaos:hover {\
  651.         background-color: #DDAAAA;\
  652.     }\
  653.     ').appendTo(document.head);
  654.  
  655.     $a_start.on({
  656.         click: function() {
  657.             /*
  658.             MG.initialBet = parseFloat( $in_bet.val() );
  659.             //MG.initialBalance = parseFloat( $bal.val() )
  660.             MG.maxBet = parseFloat( $in_betstop.val() );
  661.             MG.profitStop = parseFloat( $in_stopprofit.val() );
  662.             MG.chance = parseFloat( $in_chance.val() );
  663.             MG.interval = parseFloat( $in_interval.val() );
  664.             MG.multiplyFactor = parseFloat( $in_multiplier.val() );
  665.             MG.stoponprofit = !isNaN(MG.profitStop) && MG.profitStop > 0
  666.  
  667.             localStorage.setItem('gb_initialBet', MG.initialBet);
  668.             localStorage.setItem('gb_maxBet', MG.maxBet);
  669.             localStorage.setItem('gb_profitStop', MG.profitStop);
  670.             localStorage.setItem('gb_multiplyFactor', MG.multiplyFactor);
  671.             localStorage.setItem('gb_interval', MG.interval);
  672.             localStorage.setItem('gb_chance', MG.chance);
  673.  
  674.             MG.chaos = false;
  675.             MG.stoponwin = false;
  676.  
  677.             MG.updateStats();
  678.             */
  679.  
  680.             MG.start();
  681.         }
  682.     });
  683.     $a_resume.on({
  684.         click: function() {
  685.             MG.resume();
  686.         }
  687.     });
  688.     $a_roll.on({
  689.         click: function() {
  690.             MG.stop();
  691.             MG.manual = true;
  692.             MG.roll();
  693.         }
  694.     });
  695.     $a_stop.on({
  696.         click: function() {
  697.             MG.stop();
  698.         }
  699.     });
  700.     $a_stoponwin.on({
  701.         click: function() {
  702.             MG.stop(true)
  703.         }
  704.     });
  705.     $a_rollhi.on({
  706.         click: function() {
  707.             MG.rollSwitch = false;
  708.             MG.rollRandom = false;
  709.             MG.hi_lo = 'hi';
  710.             MG.updateStats();
  711.         }
  712.     });
  713.     $a_rolllo.on({
  714.         click: function() {
  715.             MG.rollSwitch = false;
  716.             MG.rollRandom = false;
  717.             MG.hi_lo = 'lo';
  718.             MG.updateStats();
  719.         }
  720.     });
  721.     $a_rollrand.on({
  722.         click: function() {
  723.             MG.rollSwitch = false;
  724.             MG.rollRandom = true;
  725.             MG.updateStats();
  726.         }
  727.     });
  728.     $a_rollswitch.on({
  729.         click: function() {
  730.             MG.rollSwitch = true;
  731.             MG.rollRandom = false;
  732.             MG.updateStats();
  733.         }
  734.     });
  735.     $a_chaos.on({
  736.         click: function() {
  737.             msg("Chaosmode has yet to be implemented!");
  738.         }
  739.     });
  740.     $a_autorecover.on({
  741.         click: function() {
  742.            MG.autoRecover();  
  743.         }
  744.     })
  745.  
  746.     this.init();
  747.     window.MG = this;
  748.    
  749.     // Lastly add the tab
  750.     $('<li>').append($('<a>').text('Bot').attr('href','#dmcbot')).appendTo('.tabs');
  751. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement