Skip to content

Instantly share code, notes, and snippets.

@ricardosiri68
Last active September 3, 2018 17:40
Show Gist options
  • Save ricardosiri68/7b2632c02b028f0909a0 to your computer and use it in GitHub Desktop.
Save ricardosiri68/7b2632c02b028f0909a0 to your computer and use it in GitHub Desktop.
/*jslint nomen: true, debug: true, evil: true, vars: false, browser: true,
devel: true */
/*global $ */
(function(){
var Iniciar = function(config) {
this.config = config;
window.setTimeout(
this.calcular.bind(this),
(this.multiplicador * this.config.espera) + Math.round(Math.random() * 10000)
);
};
Iniciar.prototype = {
boton: 'hi',
multiplicador: 1,
cantidad: 0,
balanceInicial: 0,
gane: 0,
perdi: 0,
salida: 0,
hi_button: document.getElementById("double_your_btc_bet_hi_button"),
lo_button: document.getElementById("double_your_btc_bet_lo_button"),
win_button: $('#double_your_btc_bet_win'),
/*
* alterna el boton hi|lo
* @valor: (String) puede ser hi o lo
*
* @return: (String) puede ser hi o lo
*/
cambiar_boton: function(valor) {
return valor === 'hi' ? 'lo' : 'hi';
},
/*
* revisa si ganó o perdio
*
* @return (undefined)
*/
calcular: function(){
if (this.botones_habilitados()) {
if (this.win_button.html() !== '') {
this.after_win();
} else if ($('#double_your_btc_bet_lose').html() !== '') {
this.after_lose();
}
var dobuble_stake = parseFloat($('#double_your_btc_stake').val()) > this.config.apuestaMaxima;
var balance_favorable = parseFloat($('#balance').html()) > salida;
if (dobule_stake || balance_favorable) {
this.show_balance();
return;
}
this.make_bet();
} else {
console.log("Calculo en espera");
}
},
/*
* comprueba el estado de los botones double_your_btc_bet_{hi|lo}_button
*
* @return: (Boolean)
*/
botones_habilitados: function(){
return (this.hi_button.getAttribute("disabled") !== "disabled") &&
(this.lo_button.getAttribute("disabled") !== "disabled");
},
/*
* operaciones que se efectuan luego de que ganó
*/
after_win: function(){
console.log("Gane! " + (this.win_button.html()).substring(22, 36));
$('#double_your_btc_min').click();
this.multiplicador = 1;
this.gane++;
this.cantidad = 0;
this.boton = 'hi';
},
/*
* redobla la apuesta luego de perder
*
* @return: (undefined)
*/
after_lose: function(){
console.log("Perdi, aumento la apuesta");
$('#double_your_btc_2x').click();
this.perdi++;
this.multiplicador++;
if(this.cantidad == this.config.payout) {
this.boton = this.cambiar_boton(this.boton);
this.cantidad = 0;
console.log("cambio boton de apuesta");
}
},
/*
* muestra el balance en consola
*
* @return: (undefined)
*/
show_balance: function(){
var promedio = String(
Math.round((parseFloat($('#balance').html()) - this.balanceInicial) * 100000000)
);
console.log("@xxxbxxx para Taringa!");
console.log("Nos vemos en Narnia");
console.log("Estadisticas:");
console.log("Balance inicial: " + this.balanceInicial);
console.log("Ganancia/Perdida: " + promedio + " Satoshis");
console.log("Balance final: " + String($('#balance').html()));
console.log("Apuestas ganadas: " + String(this.gane));
console.log("Apuestas perdidas: " + String(this.perdi));
console.log("Total de apuestas: " + String(this.gane + perdi));
},
/*
* pulsa el boton para hacer una apuesta
*
* @return: (undefined)
*/
make_bet: function(){
$('#double_your_btc_bet_' + this.boton + '_button').click();
console.log("Hice una apuesta apretando " + this.boton);
this.cantidad++;
}
};
var config = {
apuestaMaxima: 0.00001024,
gananciaEsperada: 0.0,
espera: 500,
payout: 3,
};
var iniciar = new Iniciar(config);
iniciar.balanceInicial = parseFloat($('#balance').html());
config.gananciaEsperada = config.apuestaMaxima / 2;
iniciar.salida = config.gananciaEsperada + parseFloat($('#balance').html());
$('#double_your_btc_payout_multiplier').val(String(config.payout) + ".00");
$('#double_your_btc_min').click();
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment