var page_title = document.title;

var glob_row = -1;
var ball_numb = 1;

var glob_row1 = -1;
var glob_row2 = -1;

// thimbles-game__ball thimbles-game__ball--is-position-0

if (page_title.indexOf('Наперстки') !== -1 || page_title.indexOf('Thimbles') !== -1 ) {
    window.onload = function(){
		$(".thimbles-game.thimbles__game").attr('id','id_xThimbles_game');
		$(".thimbles-info__message").attr('id','id_xThimbles_game_title');
		$(".thimbles-info__summ").attr('id','id_dop_str_title');
		$(".thimbles-logo__caption").attr('id','id_xThimbles_game_logo');
		
		$("#id_xThimbles_game_title").html('<div style="color:white;font-size:18pt;">СКРИПТ РАБОТАЕТ! КОМАНДА ТСБ</div><input type="hidden" id="dfgqwerthgf__FSDFDHFSFGFF" value="1">');
		
		var text_old = $("#id_xThimbles_game_logo").text();
		$("#id_xThimbles_game_logo").text(text_old+' 2.0');
		
		var thim_0_html = $(".thimbles-game__thimble:eq(0)").html();
		var thim_1_html = $(".thimbles-game__thimble:eq(1)").html();
		var thim_2_html = $(".thimbles-game__thimble:eq(2)").html();
		
		$(".thimbles-game__thimble:eq(0)").html(thim_0_html+"<div style=\"margin-top:-75pt;margin-left:-5pt;font-size:40pt;color:yellowgreen;\">0</div>");
		$(".thimbles-game__thimble:eq(1)").html(thim_1_html+"<div style=\"margin-top:-75pt;margin-left:-5pt;font-size:40pt;color:yellowgreen;\">1</div>");
		$(".thimbles-game__thimble:eq(2)").html(thim_2_html+"<div style=\"margin-top:-75pt;margin-left:-5pt;font-size:40pt;color:yellowgreen;\">2</div>");
		
		$("#id_xThimbles_game_logo").text(text_old+' 2.0');
		
		$("#id_dop_str_title").after("<div style=\"font-size:15pt;color:yellowgreen;text-align:center\" id=\"id_dop_str_title_123\"></div>");
		
		$(".thimbles-count__inner:eq(0)").attr('id',"t-bets-btn-eq-0");
		$(".thimbles-count__inner:eq(1)").attr('id',"t-bets-btn-eq-1");
		
		document.onclick = ({target}) => {
            let parent = target;
		    clas_name_parent = parent.parentNode.className;
			//
			
			ball_numb = $("#dfgqwerthgf__FSDFDHFSFGFF").attr('value');
			
			if (parent.id == 't-bets-btn-eq-0' || parent.parentNode.id == 't-bets-btn-eq-0' || parent.parentNode.parentNode.id == 't-bets-btn-eq-0')
			{
				$("#dfgqwerthgf__FSDFDHFSFGFF").attr('value',1);
			}
			if (parent.id == 't-bets-btn-eq-1' || parent.parentNode.id == 't-bets-btn-eq-1' || parent.parentNode.parentNode.id == 't-bets-btn-eq-1')
			{
				$("#dfgqwerthgf__FSDFDHFSFGFF").attr('value',2);
			}

            if (parent.className == "thimbles-bottom__val" )
            {
				ball_numb = $("#dfgqwerthgf__FSDFDHFSFGFF").attr('value');
				if(ball_numb == 1)
				{
					setTimeout(function () 
					{
						$(".thimbles-game__thimble:eq(0)").css("visibility","hidden");
						$(".thimbles-game__thimble:eq(1)").css("visibility","hidden");
						$(".thimbles-game__thimble:eq(2)").css("visibility","hidden");
						
						var class_get = $('#id_xThimbles_game').children().first().attr("class");
					
						$("#id_xThimbles_game").prepend('<div id="xThimbles_ball" class="'+class_get+'"></div>');
						
						setTimeout(function () 
						{
							makeid();
						}, getRandomInRange(1500,3500)); 
						
					}, 1800);
				}
				else
				{
					setTimeout(function () 
					{
						$(".thimbles-game__thimble:eq(0)").css("visibility","hidden");
						$(".thimbles-game__thimble:eq(1)").css("visibility","hidden");
						$(".thimbles-game__thimble:eq(2)").css("visibility","hidden");
						
						var class_get = $('#id_xThimbles_game').children().first().attr("class");
					
						$("#id_xThimbles_game").prepend('<div id="xThimbles_ball1" class="'+class_get+'"></div>');
						
						$("#id_xThimbles_game").prepend('<div id="xThimbles_ball2" class="'+class_get+'"></div>');
	
						setTimeout(function () 
						{
							makeid1();
						}, getRandomInRange(1500,3500)); 
						
					}, 1800);
				}
            }
			
			if (clas_name_parent == "thimbles-game thimbles__game" )
            {
				$("#xThimbles_ball").remove();
				
				$("#xThimbles_ball1").remove();
				$("#xThimbles_ball2").remove();
            }
        }
    };
}

function getRandomInRange(min, max) {
	return Math.floor(Math.random() * (max - min + 1)) + min;
}

function makeid() 
{
	if ($("#id_xThimbles_game").attr("class") == "thimbles-game thimbles__game")
	{
		$(".thimbles-game__thimble:eq(0)").css("visibility","hidden");
		$(".thimbles-game__thimble:eq(1)").css("visibility","hidden");
		$(".thimbles-game__thimble:eq(2)").css("visibility","hidden");
						
		var rand_index = getRandomInRange(0,2);
		$("#xThimbles_ball").attr('class','thimbles-game__ball thimbles-game__ball--is-position-'+rand_index);
		
		glob_row = rand_index;
		
		setTimeout(function () 
		{
			makeid();
		}, getRandomInRange(100,1500));
	}
	else
	{
		
		$(".thimbles-game__thimble:eq(0)").css("opacity","0.4");
		$(".thimbles-game__thimble:eq(1)").css("opacity","0.4");
		$(".thimbles-game__thimble:eq(2)").css("opacity","0.4");
		
		$("#id_dop_str_title_123").text("ВЫБЕРИТЕ НАПЁРСТОК "+glob_row);
	}
}

function makeid1() 
{
	if ($("#id_xThimbles_game").attr("class") == "thimbles-game thimbles__game")
	{
		$(".thimbles-game__thimble:eq(0)").css("visibility","hidden");
		$(".thimbles-game__thimble:eq(1)").css("visibility","hidden");
		$(".thimbles-game__thimble:eq(2)").css("visibility","hidden");
		
		var rand_index1 = getRandomInRange(0,2);
		$("#xThimbles_ball1").attr('class','thimbles-game__ball thimbles-game__ball--is-position-'+rand_index1);
		
		var rand_index2 = getRandomInRange(0,2);
		
		while(rand_index2 == rand_index1)
		{
			rand_index2 = getRandomInRange(0,2);
		}
		
		$("#xThimbles_ball2").attr('class','thimbles-game__ball thimbles-game__ball--is-position-'+rand_index2);
		
		glob_row1 = rand_index1;
		glob_row2 = rand_index2;
		
		setTimeout(function ()
		{
			makeid1();
		}, getRandomInRange(100,1500));
	}
	else
	{
		$(".thimbles-game__thimble:eq(0)").css("opacity","0.4");
		$(".thimbles-game__thimble:eq(1)").css("opacity","0.4");
		$(".thimbles-game__thimble:eq(2)").css("opacity","0.4");
		
		$("#id_dop_str_title_123").text("ВЫБЕРИТЕ НАПЁРСТОК "+glob_row1+" или "+glob_row2);
	}
} 
by