Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

398
Views
Sleep , freeze, end?

could you please help me how to fix this? I want to send just one command, but to be as accurate as possible (on milliseconds). This is the part I need to fix:

document.getElementById("arrTime").onclick = function () {
    clearInterval(attInterval);
    let time = document.getElementsByClassName("relative_time")[0].textContent.slice(-8);
    input = prompt("Set Arrival Time", time);
    inputMs = parseInt(prompt("Set the milliseconds", "500"));
    delay = parseInt(delayTime) + parseInt(inputMs);
    let arrivalTime;
    arrInterval = setInterval(function () {
        arrivalTime = document.getElementsByClassName("relative_time")[0].textContent;
        if (arrivalTime.slice(-8) >= input) {
            setTimeout(function () { document.getElementById("troop_confirm_submit").click(); }, delay);
        }
    }, 5);
    document.getElementById("showArrTime").innerHTML = input + ":" + inputMs.toString().padStart(3, "0");
    document.getElementById("showSendTime").innerHTML = "";
};

Now, there is an "if statement" to perform action at arrivalTime.slice(-8) >= input (so for example 19:24:30), but it is sending requests every 5ms. So over that one second time, it sends 200 requests to the server. I don´t want to change those 5ms, as I need to have it as accurate as possible, but I want to break the script, freeze it or sleep it for 1 second once the command is performed. So something like: setTimeout(function () { document.getElementById("troop_confirm_submit").click(); Sleep 1 second }, delay);

Anyone who can help, please?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I'd advise to break up the functions as to manage the interval a little easier

document.getElementById("arrTime").onclick = function() {
  clearInterval(attInterval);
  let time = document.getElementsByClassName("relative_time")[0].textContent.slice(-8);
  input = prompt("Set Arrival Time", time);
  inputMs = parseInt(prompt("Set the milliseconds", "500"));
  delay = parseInt(delayTime) + parseInt(inputMs);
  startInterval(input, delay)
  document.getElementById("showArrTime").innerHTML = input + ":" + inputMs.toString().padStart(3, "0");
  document.getElementById("showSendTime").innerHTML = "";
};

function startInterval(input, delay) {
  arrInterval = setInterval(function() {
    let arrivalTime = document.querySelector(".relative_time").innerText;
    if (+arrivalTime.slice(-8) >= +input) {
      clearInterval(arrInterval); // pause the interval
      setTimeout(() => {
        startInterval(input, delay)
      }, 1000 * 60); // restart the interval in 1 minute       
      setTimeout(() => {
        document.querySelector("#troop_confirm_submit").click();
      }, delay);
    }
  }, 5);
}

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!