How to automatically click on " OK " to confirm?

There is a script that monitors the timer. Once the timer shows 00:00:00, he clicks the button, then POPs up the confirm window and there you need to simulate pressing OK, then the timer starts counting down. And so all around.

My code
$( document ).ready(function() {

var event = jQuery.Event('keypress');
event.which = 13; 
event.keyCode = 13; 

 var time = $('.timer').text();
 if (time == '00:00:00') { 

}, 2000);


Then made the button with all the zeros on the timer, and how to simulate clicking on " OK " to confirm?

Were trying to simulate pressing Enter, but somehow no avail.
March 23rd 20 at 19:32
2 answers
March 23rd 20 at 19:34
No, confirm/prompt/alert block script execution until the user does not do something himself.

If you need managed confirma use any library with custom pop-UPS it is possible to close and anything to do with them.
March 23rd 20 at 19:36
Apparently, the window fails to appear in the HOUSE. You have to give him time.

setInterval(function () {
 var time = $('.timer').text();
 if (time == '00:00:00') {

 // wait until konfirm
 setTimeout(function() {
 // or, if there is form
 }, 1000);
}, 2000);
Do not understand some of this part:

Button in the window to confirm, there are two buttons "OK" and "cancel" , write
$('OK').trigger('click'); ?? - Lysanne.Auer commented on March 23rd 20 at 19:39
You understand what confirm ?) - Mark_Labadie commented on March 23rd 20 at 19:42
@abbigail, don't listen to him. Using JS is not implemented. - Mark_Labadie commented on March 23rd 20 at 19:45
@Salvatore_Runte40, Yes, in that do not understand how this code can help... So, as I understand it, with any script will not work until the user click on OK ? - Lysanne.Auer commented on March 23rd 20 at 19:48
@abbigail, the first comment is not for You.
And Yes, JS script can not control pop-up messages browser, as described above.
If only some desktop clicker set that pressed on OK.
Maybe it will be easier to implement Your task via http requests? - Mark_Labadie commented on March 23rd 20 at 19:51
@Salvatore_Runte40, Tell me how, don't know )
The problem is that there is no access to the site, this extension, installing it, there is action here - Lysanne.Auer commented on March 23rd 20 at 19:54
My code would have worked if the confirmation dialog was part of YOUR code: a pop-up or modelka some.
As already said @chastity.White , browser notifications require user interaction. So the main answer to the question "how to simulate press on OK to confirm?" all. - Jules.Volkm commented on March 23rd 20 at 19:57
@abbigail, after pressing, surely, is a http request.
If so - you can catch it in the sniffer, and using curl to send such requests. - Mark_Labadie commented on March 23rd 20 at 20:00

Find more questions by tags jQuery