Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

399
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda