Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

400
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda