How to press the button at the exact time specified?

  • 0
    Guys, hello everyone! I don’t understand programming, but, collecting information piece by piece, I wrote a code that automatically fills in and sends the form on the site with an interval of 1 second. The code looks like this:

    setInterval (() = & gt; {
    const field1 = document.querySelector ('[name = "...."]');
    const field2 = document.querySelector ('[name = "...."]');
    const field3 = document.querySelector ('[name = "...."]');
    const btn = document.querySelector ("input.button.solid");

    field1.value = "....";
    field2.value = ".....";
    field3.value = ".....";
    btn.click ();
    }, 1000);

    So, now the task is to remake this code so that the form is filled in and sent only ONE time at the specified time. In this case, the sending time should be accurate, up to milliseconds (Moscow time). How can this be done? It seems like you can put SetTimeout. And yet, are Moscow time and server time different? Please give me a hint. I will be very grateful.
    Thank you all for your help in this matter.
    JavaScript Kaleb Duran, Dec 12, 2019

  • 1 Answers
  • 0
    First, no one can guarantee you accuracy.

    The setTimeout and setInterval methods themselves do not mean that "should be triggered in exactly this amount of time".

    They mean "let it work no earlier than such and such a time." How it works depends on many factors.



    To implement your task with the efforts of just a script, you can run a script 1 minute before the time you need, which will try to call setInterval with a timeout of 86400000 ms exactly at the moment when

    new Date (). getHours () === yourHours & amp; & amp; ... then repeat the same thing instead of hours with minutes, seconds, milliseconds.

    Here yourHours is a variable in which you specify at what time the event should occur. And with minutes, seconds the same.

    And then your setInterval will call the callback with a frequency of 24 hours - you can choose the frequency yourself. For example, I gave it to work once a day.

    Or you can run the script in advance every day.

    In general, this is better done on the server using cron.
    Everly Nicholson

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!