Advertisement
Guest User

Untitled

a guest
Aug 20th, 2013
2,128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name        JustDice Martingale Bot
  3. // @namespace   none
  4. // @author      Gray
  5. // @version     1.1
  6. // @include     https://just-dice.com/*
  7. // @grant       none
  8. // ==/UserScript==
  9.  
  10. /* How would you go about using this?
  11.  *
  12.  * Install Greasemonkey plugin for Firefox
  13.  * Install Firebug plugin for Firefox (It's better than the builtin console.)
  14.  *
  15.  * Make a new script with Greasemonkey
  16.  * Type whatever you want into the form
  17.  * Then paste this whole file into the editor
  18.  *
  19.  * Adjust to your needs.
  20.  * Run.
  21.  *
  22.  * Other things you can do:
  23.  *
  24.  * That's it!
  25.  *
  26.  * Made a profit and feel like tipping people without seeing their genitals?
  27.  *
  28.  * Go ahead: 1Gray1ZsWo3kKBaCYdigiyPkD1pUnBqPxo
  29.  *
  30.  * Now go have fun with this... thing!
  31. **/
  32.  
  33. // Heres the script
  34.  
  35. $('<script>').attr({
  36.     src: 'http://d3js.org/d3.v3.min.js',
  37.     charset: 'UTF-8'
  38. }).appendTo(document.body);
  39.  
  40. $(function() {
  41.     var markup = '<div class="bot-controls"><fieldset><div class="row"><p class="llabel">bet start</p><input id="gb_bet" value="0.001"><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></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><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></div><div class="clear"></div><div class="bot-graph">Visual feedback goes here. Soon?</div><div class="bot-foot">Made a nice profit? Tips are welcome! 1Gray1ZsWo3kKBaCYdigiyPkD1pUnBqPxo';
  42.         $panelWrapper = $('<div>').attr('id','graysbot').css({display: 'none'}).insertAfter('#faq'),
  43.         $panel = $('<div>').addClass('panel').append(markup).appendTo($panelWrapper),
  44.         $bal = $("#pct_balance"),
  45.         $in_bet = $('#gb_bet'),
  46.         $in_chance = $('#gb_chance'),
  47.         $in_multiplier = $('#gb_multiplier'),
  48.         $in_interval = $('#gb_interval'),
  49.         $in_betstop = $('#gb_betstop'),
  50.         $in_stopprofit = $('#gb_stopprofit'),
  51.         $a_start = $('#gba_start'),
  52.         $a_resume = $('#gba_resume'),
  53.         $a_roll = $('#gba_roll'),
  54.         $a_stop = $('#gba_stop'),
  55.         $a_stoponwin = $('#gba_stoponwin'),
  56.         $a_rollhi = $('#gba_rollhi'),
  57.         $a_rolllo = $('#gba_rolllo'),
  58.         $a_rollrand = $('#gba_rollrand'),
  59.         $a_rollswitch = $('#gba_rollswitch'),
  60.         $a_chaos = $('#gba_chaos'),
  61.         $s_status = $('#gbs_status'),
  62.         $s_statusmessage = $('#gbs_statusmessage'),
  63.         $s_bet = $('#gbs_bet'),
  64.         $s_betwin = $('#gbs_betwin'),
  65.         $s_betlost = $('#gbs_betlost'),
  66.         $s_streak = $('#gbs_streak'),
  67.         $s_rollmode = $('#gbs_rollmode'),
  68.         $s_rollmodecurrent = $('#gbs_rollmodecurrent'),
  69.         $s_wagered = $('#gbs_wagered'),
  70.         $s_myprofit = $('#gbs_myprofit'),
  71.         $s_stopprofit = $('#gbs_stopprofit');
  72.  
  73.     // Include d3.js
  74.  
  75.     /* System stuff */
  76.     this.initialized = false;
  77.     this.auto = false;
  78.     this.manual = false;
  79.     this.stoponwin = false;
  80.     this.stoponprofit = false;
  81.     this.bet = 0;
  82.     this.streak = 0;
  83.     this.statusmessage = "";
  84.     this.lastbetOutcome = null;
  85.  
  86.     /* Stats */
  87.     this.stats = {
  88.         won: 0,
  89.         lost: 0,
  90.         maxStreak: 0,
  91.         currentProfit: 0,
  92.         wagered: 0
  93.     }
  94.  
  95.     /* Parameters */
  96.     this.initialBet = parseFloat(localStorage.getItem('gb_initialBet')) || 0.0001;
  97.     this.maxBet = parseFloat(localStorage.getItem('gb_maxBet')) || 0.01;
  98.  
  99.     this.initialBalance = 0;
  100.     this.currentBalance = 0;
  101.     this.profitStop = parseFloat(localStorage.getItem('gb_profitStop')) || 0;
  102.    
  103.     this.multiplyFactor = parseFloat(localStorage.getItem('gb_multiplyFactor')) || 2; // Current bet is multiplied by [multiplyFactor] every [interval] rolls
  104.     this.interval = parseFloat(localStorage.getItem('gb_interval')) || 1;
  105.     this.chance = parseFloat(localStorage.getItem('gb_chance')) || 49.5;
  106.  
  107.     this.hi_lo = "lo";
  108.     this.rollRandom = true;
  109.     this.rollSwitch = false;
  110.  
  111.     this.byteLock = false;
  112.     this.byteCount = 0;
  113.     this.byteOffset = 0;
  114.     this.delay = 0; // Wanna go slower or faster? Set this. Milliseconds.
  115.  
  116.     this.init = function() {
  117.         if(this.initialized) {
  118.             return;
  119.         }
  120.  
  121.         this.initialized = true;
  122.         // Bind events
  123.         /*socket.on("wins", this.isWin);
  124.         socket.on("losses", this.isLoss);
  125.         socket.on("jderror", this.isError); //*/
  126.  
  127.         socket.on("result", this.setBalance);
  128.         socket.on("init", this.setBalance);
  129.  
  130.         $in_bet.val(tidy(this.initialBet));
  131.         $in_chance.val(this.chance);
  132.         $in_multiplier.val(this.multiplyFactor);
  133.         $in_interval.val(this.interval);
  134.         $in_betstop.val(tidy(this.maxBet));
  135.         $in_stopprofit.val(tidy(this.profitStop));
  136.  
  137.         this.getNewRand();
  138.  
  139.         this.updateStats();
  140.     }
  141.  
  142.     this.setBalance = function(data) {
  143.         if(data.uid == uid && data.balance) {
  144.             var bal = parseFloat(data.balance);
  145.             this.currentBalance = bal;
  146.             if(this.initialBalance===0) {
  147.                 this.initialBalance = bal;
  148.             }
  149.             if(data['win'] === true) {
  150.                 this.isWin(data);
  151.             } else if(data['win'] === false) {
  152.                 this.isLoss(data);
  153.             }
  154.         }
  155.     }
  156.     this.setBalance = this.setBalance.bind(this);
  157.  
  158.     this.start = function() {
  159.         this.auto = true;
  160.         this.manual = false;
  161.         this.statusmessage = "";
  162.         this.bet = this.initialBet;
  163.         this.stats.currentProfit = 0;
  164.         this.roll();
  165.     };
  166.     this.stop = function(stoponwin) {
  167.         if(stoponwin) {
  168.                 this.stoponwin = true;
  169.         } else {
  170.                 this.auto = false;
  171.         }
  172.         this.updateStats();
  173.     };
  174.     this.resume = function() {
  175.         this.auto = true;
  176.         this.roll();
  177.     };
  178.  
  179.     this.getNewRand = function() {
  180.         this.byteLock = true;
  181.         $.get("http://www.random.org/integers/?num=256&min=0&max=1024&col=2&base=2&format=plain&rnd=new", function(bytes) {
  182.             bytes = bytes.replace(/[^01]/g,'');
  183.             MG.bytes = bytes;
  184.             MG.byteCount = bytes.length;
  185.             MG.byteOffset = 0;
  186.             MG.byteLock = false;
  187.             MG.setHiLo();
  188.         });
  189.     }
  190.  
  191.     this.setHiLo = function() {
  192.         if(this.rollRandom) {
  193.             this.hi_lo = (this.bytes[this.byteOffset++] === '1') ? 'hi' : 'lo';
  194.             if(this.byteOffset === this.byteCount) {
  195.                 this.getNewRand();
  196.             }
  197.         } else if(this.rollSwitch) {
  198.  
  199.         }
  200.     }
  201.  
  202.     this.roll = function() {
  203.         window.setTimeout(this.placeBet, this.delay);
  204.     };
  205.  
  206.     this.placeBet = function() {
  207.         if(this.auto || this.manual) {
  208.             socket.emit("bet", csrf, {
  209.                 chance: "" + this.chance,
  210.                 bet: this.bet.toFixed(8),
  211.                 which: this.hi_lo
  212.             });
  213.             if(this.rollRandom && this.byteLock) {
  214.                 window.setTimeout(this.placeBet, this.delay);
  215.                 return;
  216.             } else {
  217.                 this.setHiLo();
  218.             }
  219.  
  220.         }
  221.     };
  222.     this.placeBet = this.placeBet.bind(this);
  223.  
  224.     this.isWin = function(data) {
  225.         this.streak = 0;
  226.         this.stats.won++;
  227.         this.stats.wagered += this.bet;
  228.         this.lastbetOutcome = true;
  229.  
  230.         this.bet = this.initialBet;
  231.         if(this.stoponprofit && (this.currentBalance-this.initialBalance) > this.profitStop) {
  232.             this.auto = false;
  233.             this.stoponprofit = false;
  234.             this.statusmessage = "profit limit";
  235.         } else if(this.stoponwin) {
  236.             this.auto = false;
  237.             this.stoponwin = false;
  238.             this.statusmessage = "stop on win";
  239.         } else if(this.auto) {
  240.             this.roll();
  241.         }
  242.         this.updateStats();
  243.     };
  244.     this.isWin = this.isWin.bind(this);
  245.  
  246.     this.isLoss = function(data) {
  247.         this.streak++;
  248.         this.stats.lost++;
  249.         this.stats.wagered += this.bet;
  250.         this.lastbetOutcome = false;
  251.  
  252.         if(this.streak % this.interval === 0) {
  253.             this.bet *= this.multiplyFactor;
  254.         }
  255.         this.stats.maxStreak = Math.max(this.streak, this.stats.maxStreak);
  256.  
  257.         if(this.bet > this.maxBet) {
  258.             this.statusmessage = "bet limit"
  259.             this.stoponwin = false;
  260.             this.auto = false;
  261.         } else if(this.auto) {
  262.             if(this.rollSwitch) {
  263.                 this.hi_lo = (this.hi_lo === 'hi') ? 'lo' : 'hi';
  264.             }
  265.  
  266.             this.roll();
  267.         }
  268.         this.updateStats();
  269.     };
  270.     this.isLoss = this.isLoss.bind(this);
  271.  
  272.     this.isError = function(data) {
  273.         this.auto = false;
  274.         console.log('Error. Halting.');
  275.         console.log(data);
  276.     };
  277.     this.isError = this.isError.bind(this);
  278.  
  279.     this.updateStats = function() {
  280.         var status = this.auto ? "Running" : (this.manual ? "Manual" : "Halted"),
  281.             rollmode, currentroll;
  282.  
  283.         if(this.stoponwin && this.stoponprofit) {
  284.             status += '; SW|SP';
  285.         } else if(this.stoponwin) {
  286.             status += '; SW';
  287.         } else if(this.stoponprofit) {
  288.             status += '; SP';
  289.         }
  290.  
  291.         if(this.rollRandom) {
  292.             rollmode = 'random';
  293.             $s_rollmodecurrent.text(this.hi_lo).css('display', '');
  294.         } else if(this.rollSwitch) {
  295.             rollmode = 'switch';
  296.             $s_rollmodecurrent.text(this.hi_lo).css('display', '');
  297.         } else {
  298.             rollmode = this.hi_lo;
  299.             $s_rollmodecurrent.text(currentroll).css('display', 'none');
  300.         }
  301.  
  302.         $s_status.text(status);
  303.         $s_bet.text(this.stats.won + this.stats.lost);
  304.         $s_betwin.text(this.stats.won);
  305.         $s_betlost.text(this.stats.lost);
  306.         $s_streak.text(this.stats.maxStreak);
  307.         $s_rollmode.text(rollmode);
  308.         $s_wagered.text(commaify(this.stats.wagered.toFixed(8)));
  309.         $s_myprofit.text(commaify((this.currentBalance-this.initialBalance).toFixed(8)));
  310.         $s_stopprofit.text(this.profitStop ? commaify(this.profitStop.toFixed(8)) : 'none');
  311.  
  312.         if(this.statusmessage) {
  313.             $s_statusmessage.text(this.statusmessage).css('display', '');
  314.         } else {
  315.             $s_statusmessage.text('').css('display', 'none');
  316.         }
  317.     }
  318.  
  319.  
  320.     // Some styling // There are other ways for this. Bear with me. ;)
  321.     $('<style>').append('\
  322.     #graysbot .bot-stats,\
  323.     #graysbot .button_group {\
  324.         margin-top: 16px;\
  325.     }\
  326.     #graysbot .bot-stats .slabel {\
  327.         width: 160px;\
  328.     }\
  329.     #graysbot #gba_chaos {\
  330.         background-color: #FFCCCC;\
  331.         border: 5px solid #CC9999;\
  332.     }\
  333.     #graysbot #gba_chaos:hover {\
  334.         background-color: #DDAAAA;\
  335.     }\
  336.     ').appendTo(document.head);
  337.  
  338.     $a_start.on({
  339.         click: function() {
  340.             MG.initialBet = parseFloat( $in_bet.val() );
  341.             //MG.initialBalance = parseFloat( $bal.val() )
  342.             MG.maxBet = parseFloat( $in_betstop.val() );
  343.             MG.profitStop = parseFloat( $in_stopprofit.val() );
  344.             MG.chance = parseFloat( $in_chance.val() );
  345.             MG.interval = parseFloat( $in_interval.val() );
  346.             MG.multiplyFactor = parseFloat( $in_multiplier.val() );
  347.             MG.stoponprofit = !isNaN(MG.profitStop) && MG.profitStop > 0
  348.  
  349.             localStorage.setItem('gb_initialBet', MG.initialBet);
  350.             localStorage.setItem('gb_maxBet', MG.maxBet);
  351.             localStorage.setItem('gb_profitStop', MG.profitStop);
  352.             localStorage.setItem('gb_multiplyFactor', MG.multiplyFactor);
  353.             localStorage.setItem('gb_interval', MG.interval);
  354.             localStorage.setItem('gb_chance', MG.chance);
  355.  
  356.             MG.chaos = false;
  357.             MG.stoponwin = false;
  358.  
  359.             MG.updateStats();
  360.  
  361.             MG.start();
  362.         }
  363.     });
  364.     $a_resume.on({
  365.         click: function() {
  366.             MG.resume();
  367.         }
  368.     });
  369.     $a_roll.on({
  370.         click: function() {
  371.             MG.stop();
  372.             MG.manual = true;
  373.             MG.roll();
  374.         }
  375.     });
  376.     $a_stop.on({
  377.         click: function() {
  378.             MG.stop();
  379.         }
  380.     });
  381.     $a_stoponwin.on({
  382.         click: function() {
  383.             MG.stop(true)
  384.         }
  385.     });
  386.     $a_rollhi.on({
  387.         click: function() {
  388.             MG.rollSwitch = false;
  389.             MG.rollRandom = false;
  390.             MG.hi_lo = 'hi';
  391.             MG.updateStats();
  392.         }
  393.     });
  394.     $a_rolllo.on({
  395.         click: function() {
  396.             MG.rollSwitch = false;
  397.             MG.rollRandom = false;
  398.             MG.hi_lo = 'lo';
  399.             MG.updateStats();
  400.         }
  401.     });
  402.     $a_rollrand.on({
  403.         click: function() {
  404.             MG.rollSwitch = false;
  405.             MG.rollRandom = true;
  406.             MG.updateStats();
  407.         }
  408.     });
  409.     $a_rollswitch.on({
  410.         click: function() {
  411.             MG.rollSwitch = true;
  412.             MG.rollRandom = false;
  413.             MG.updateStats();
  414.         }
  415.     });
  416.     $a_chaos.on({
  417.         click: function() {
  418.             msg("Chaosmode has yet to be implemented!");
  419.         }
  420.     })
  421.  
  422.     this.init();
  423.     window.MG = this;
  424.    
  425.     // Lastly add the tab
  426.     $('<li>').append($('<a>').text('Bot').attr('href','#graysbot')).appendTo('.tabs');
  427. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement