var createDialog = function() {
var dialog = $('
id: 'safety-dialog',
'class': 'dialog',
style: 'left: 50%; margin-left: -223px; z-index: 1002; position: fixed; top: 50%; margin-top: -138px; display: none;'
});
var dCloseButton = $('
dialog.append(dCloseButton);
var dHeader = $('
var dhIcon = $('
var dhiImg = $('', { src: '/static/images/logo_48.png', alt: 'Bitcoin video casino log' });
dhIcon.append(dhiImg);
var dhTitle = $('
var dhClear = $('
dHeader.append(dhIcon);
dHeader.append(dhTitle);
dHeader.append(dhClear);
dialog.append(dHeader);
var dBody = $('
var dbMessage = $('
', { id: 'safety-dialog-message' });
dBody.append(dbMessage);
dialog.append(dBody);
var dButtonContainer = $('
var dbcCancel = $('', { type: 'button', id: 'safety-dialog-cancel', value: 'Cancel' });
var dbcProceed = $('', { type: 'button', id: 'safety-dialog-proceed', value: 'Proceed', style: 'margin-left: 10px' });
dButtonContainer.append(dbcCancel);
dButtonContainer.append(dbcProceed);
dialog.append(dButtonContainer);
dialog.hide();
$('body').append(dialog);
}
var getScores = function(action) {
var hand = 0;
var cards = null;
for(var i = 0; i < game_system.player_hands.length; i++) {
if(game_system.player_hands[i].find('.hand_dimmer .dimmed').length == 0) cards = game_system.get_hand(game_system.player_hands[i]);
}
playerScore = Blackjack.score_hand(cards)[0];
var dealerCards = game_system.get_hand(game_system.dealer_hand).splice(1,1);
dealerScore = Blackjack.score_hand(dealerCards);
action(playerScore, dealerScore);
}
var overrideHit = function() {
getScores(function(playerScore, dealerScore) {
if(playerScore >= 17) {
showDialog('Your hand score is greater than or equal to 17, are you sure you want to hit?', hitRef);
} else hitRef.call(game_system);
});
}
var overrideStand = function() {
getScores(function(playerScore, dealerScore) {
if(playerScore <= 11) {
showDialog('Your hand score is less than or equal to 11, are you sure you want to stand?', standRef);
} else if(playerScore < 17 && dealerScore >= 7) {
showDialog('Your hand score is less than 17, and dealer shows a hand score greater than or equal to 7, are you sure you want to stand?', standRef);
} else standRef.call(game_system);
});
}
var overrideDouble = function() {
getScores(function(playerScore, dealerScore) {
if(playerScore > 11) {
showDialog('Your hand score is greater than 11, are you sure you want to double?', doubleRef);
} else doubleRef.call(game_system);
});
}
var overrideSplit = function() {
getScores(function(playerScore, dealerScore) {
if(playerScore >= 17) {
showDialog('Your hand score is greater than or equal to 17, are you sure you want to split?', splitRef);
} else splitRef.call(game_system);
});
}
var showDialog = function(msg, handler) {
$('#safety-dialog').show();
$('#safety-dialog-message').text(msg);
$('#safety-dialog-proceed').unbind();
$('#safety-dialog-proceed').click(function() { $('#safety-dialog').hide(); handler.call(game_system); });
}
var init = function() {
createDialog();
hitRef = game_system.__proto__.handle_hit;
standRef = game_system.__proto__.handle_stand;
doubleRef = game_system.__proto__.handle_double;
splitRef = game_system.__proto__.handle_split;
game_system.handle_hit = overrideHit;
game_system.handle_stand = overrideStand;
game_system.handle_double = overrideDouble;
game_system.handle_split = overrideSplit;
$('#safety-dialog .close_button').click(function() { $('#safety-dialog').hide(); });
$('#safety-dialog-cancel').click(function() { $('#safety-dialog').hide(); });
}
init();
That said, it's a really bad idea to run random code from strangers that you don't understand.