var counter_check = 1; sleep(3000).then(() => { checkFinishPriorityScanner(); }); function checkFinishPriorityScanner() { counter_check++; jQuery.ajax({ type: "post", url: ajax_var_check_force_scanner.url, data: "action=" + ajax_var_check_force_scanner.action + "&nonce=" + ajax_var_check_force_scanner.nonce, success: function (response) { response = JSON.parse(response); if(response.cron_status == 'success'){ document.getElementById('status-indicator-cron-execute').style.color = '#bef6e2'; } if(response.cron_status == 'error'){ document.getElementById('status-indicator-cron-execute').style.color = '#FFE6E8'; set_error(ajax_var_check_force_scanner.translations.errors.cron); return; }else{ if( counter_check >= 80 ){ document.getElementById('status-indicator-first-scanner').style.color = '#FFE6E8'; set_error(ajax_var_check_force_scanner.translations.errors.attempts); return; } if (response.force_scanner == "NO") { set_success(ajax_var_check_force_scanner.translations.success.scanner); sleep(1500).then(() => { location.reload(); }); } if (response.force_scanner == "YES") { sleep(3000).then(() => { document.getElementById('status-indicator-counter').innerHTML = counter_check; checkFinishPriorityScanner(); }); } } }, error: function (jqXHR, textStatus, errorThrown) { console.log("error"); console.log(errorThrown); console.log(jqXHR.responseText); }, }); } function sleep(time) { return new Promise((resolve) => setTimeout(resolve, time)); } function set_error(message){ // Change image document.getElementById('image-scanner-execute').src = ajax_var_check_force_scanner.image_error; // Change error message document.getElementById('error-message').innerHTML = message; document.getElementById('error-message').style.visibility = 'initial'; } function set_success(message){ // Change dot status document.getElementById('status-indicator-first-scanner').style.color = '#bef6e2'; // Change error message document.getElementById('success-message').innerHTML = message; document.getElementById('success-message').style.visibility = 'initial'; }