79% found this document useful (63 votes)
6K views4 pages

Gram Rol Script

The document describes the logic for a click handler on a roll button that rolls a random number and checks if it's a winning number. It uses reCAPTCHA to validate the user on form submit. On success, it animates displaying the random number rolled, checks if it's a winner, updates stats like total rolls and wins, and allows another roll after a time delay. It also includes functions for generating random numbers, updating UI elements like timers and lists of wins.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
79% found this document useful (63 votes)
6K views4 pages

Gram Rol Script

The document describes the logic for a click handler on a roll button that rolls a random number and checks if it's a winning number. It uses reCAPTCHA to validate the user on form submit. On success, it animates displaying the random number rolled, checks if it's a winner, updates stats like total rolls and wins, and allows another roll after a time delay. It also includes functions for generating random numbers, updating UI elements like timers and lists of wins.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

$('#roll-button').

click(function() {
var winWinRoll = $('#customSwitch12').prop("checked");

grecaptcha.ready(function() {
grecaptcha.execute('6LcQG_4UAAAAAIT1oxs25XjOXXcKwW1h1gkdxowr',
{action: 'roll'}).then(function(token) {
$.ajax({
url: '/roll',
type: 'POST',
data: {isWinWinRoll: winWinRoll, reCaptchaToken: token},
beforeSend: function() {

},
success: function(result) {
console.log(result);
$('#roll-button').attr('disabled', true);
$('#win-number').html('');
$('.captha').toggle();
let timerId = setInterval(function(){
var rand = Math.floor((Math.random() * 1000) +
1);
var r1 = 1000 - rand;
rand = rand + r1;
$('#win-gram').html(rand);
}, 40);

setTimeout(() =>
{ clearInterval(timerId);console.log('stop'); }, 3000);

var timeSec = Math.ceil(result['timeToNextRoll']);


var hour = timeSec/3600 ^ 0;
var min = (timeSec-hour*3600)/60 ^ 0;
var sec = timeSec-hour*3600-min*60;
var time = hour + ':' + min + ':' + sec ;
//var time = '2: 00: 10' ;

progressUp(result['levelPoints']);
setTimeout(function(){
$('#win-number').html('Number: ' +
result['randomValue']);

var winGram = result['wonAmount'];


if (winGram > 0) {
var winNumb = result['randomValue'];
var userName = 'seyed Ali Safavi';
var userColor = 'warning';

var html = "<li style=\"display: none;\"><div


class=\"timeline-icon bg-" + userColor + "\"><i class=\"feather icon-user font-
medium-2 align-middle\"></i></div><div class=\"timeline-info\"><p class=\"font-
weight-bold mb-0\">" + userName + "</p><span class=\"font-small-3\">Win " + winGram
+ " Gram - lucky number is " + winNumb + "</span></div><small class=\"text-
muted\">few seconds ago</small></li>";
$("#user-list").prepend(html);
setTimeout(function(){
$("#user-list li:first-
child").slideToggle();
$("#user-list li:last-
child").slideToggle();

setTimeout(function(){
$("#user-list li:last-child").remove();
}, 100);
},50);
}

$('#win-gram').html('You ' + (result['wonAmount'] >


0 ? 'win' : 'lost') + ' ' + result['wonAmount'] + ' Gram!');

$('#next-roll-time').html(time);
var interval = setInterval(function() {
timerFun($('#next-roll-time'));
}, 1000);
$('#next-roll-text').html('Next roll');
$('.cap4').toggle();
$('#total-rolls').html(Number($('#total-
rolls').html()) + Number(1));
if (result['wonAmount'] > 0) {
$('#total-won').html( ( Number($('#total-
won').html()) + Number(result['wonAmount']) ).toFixed(1) );
}
},3000);

},
error: function(reason) {
console.log(reason['responseJSON']['reason']);
$('#roll-button').attr('disabled', true);
Swal.fire({
title: "Error!",
text: reason['responseJSON']['reason'],
type: "error",
confirmButtonClass: 'btn btn-primary',
buttonsStyling: false,
});
}
});
});
});
});

function rand(1000){
return Math.ceil((max-min)*Math.random()+min);
}

var listBodyHeight = $('.list-body').height();


$('.list-body').css({'min-height': listBodyHeight, 'max-height':
listBodyHeight, 'overflow': 'hidden'})

$('#user-list .timeline-info').each(function() {
var nameLenght = allNames.length - 1;
var winNumb = 1000; // win number
var winWin = 2;
if (winWin == 1) {
if (winNumb <= 980) {
var winGram = 0.1;
} else if ((winNumb >= 981) && (winNumb <= 993) ) {
var winGram = 1;
} else if ((winNumb >= 994) && (winNumb <= 997) ) {
var winGram = 10;
} else if ((winNumb >= 998) && (winNumb <= 999) ) {
var winGram = 100;
} else if (winNumb == 1000 ) {
var winGram = 1000;
}
} else {
if ((winNumb >= 701) && (winNumb <= 850) ) {
var winGram = 1;
} else if ((winNumb >= 851) && (winNumb <=950) ) {
var winGram = 10;
} else if ((winNumb >= 951) && (winNumb <= 1000) ) {
var winGram = 100;
} else {
var winGram = 0.1;
}
}

$('p', this).html(allNames[rand(0,nameLenght)]);
$('span', this).html('Won ' + winGram + ' Gram - lucky number
is ' + winNumb);
/*Won 0.01 Gram - lucky number is 126*/
});

function userWin(){

var nameLenght = allNames.length - 1;


var winNumb = rand( 1 , 1000 ); // win number

var winWin = 1000;


if (winWin == 1) {
if (winNumb <= 980) {
var winGram = 0.1;
} else if ((winNumb >= 981) && (winNumb <= 993) ) {
var winGram = 1;
} else if ((winNumb >= 994) && (winNumb <= 997) ) {
var winGram = 10;
} else if ((winNumb >= 998) && (winNumb <= 999) ) {
var winGram = 100;
} else if (winNumb == 1000 ) {
var winGram = 1000;
}
} else {
if ((winNumb >= 701) && (winNumb <= 850) ) {
var winGram = 1;
} else if ((winNumb >= 851) && (winNumb <=950) ) {
var winGram = 10;
} else if ((winNumb >= 951) && (winNumb <= 1000) ) {
var winGram = 100;
} else {
var winGram = 0.1;
}
}

var color = new Array('#B8C2CC', '#28C76F', '#EA5455',


'#FF9F43', '#00cfe8', '#7367F0');
var colorLenght = color.length - 1;

var html = "<li style=\"display: none;\"><div class=\"timeline-


icon \" style=\"background-color: " + color[rand(0,colorLenght)] + "\"><i
class=\"feather icon-user font-medium-2 align-middle\"></i></div><div
class=\"timeline-info\"><p class=\"font-weight-bold mb-0\">" +
allNames[rand(0,nameLenght)] + "</p><span class=\"font-small-3\">Win " + winGram +
" Gram - lucky number is " + winNumb + "</span></div><small class=\"text-
muted\">few seconds ago</small></li>";
$("#user-list").prepend(html);

setTimeout(function(){
$("#user-list li:first-child").slideToggle();
$("#user-list li:last-child").slideToggle();

setTimeout(function(){
$("#user-list li:last-child").remove();
}, 100);

},50);

};
setTimeout(function() {
(function() {
var x = rand(1000, 5000); //add user interval
//console.log(x);
userWin();

setTimeout(arguments.callee, x);

})()
}, 2000);

You might also like