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

155
Vistas
How do I modify this code to create a loop inside a loop?

I found this script from a website. The loop ends when it has followed 40 Instagram accounts at a 2-second interval. How do I modify the script so it waits for 10 minutes before repeating the same loop for 3 times? Basically, it goes:

  1. Follow an account and wait for 2 seconds X40
  2. Wait for 10 minutes
  3. Follow an account and wait for 2 seconds X40
  4. Wait for 10 minutes
  5. Follow an account and wait for two seconds X40
  6. Wait for 10 minutes
  7. ---LOOP ENDS---
 var TagFollow = document.getElementsByTagName("button");
 var SearchFollow = "Follow";
 var foundFollow;

 function clickfollow(){
 for (var i = 0; i < TagFollow.length; i++) {
     if (TagFollow[i].textContent == SearchFollow) {
     foundFollow = TagFollow[i];
     foundFollow.click(); 
     break;
      }
 }
 }
var i = 1;
function myLoop() {
   setTimeout(function() {
       console.log(new Date().toLocaleTimeString());
        clickfollow();
        //document.getElementsByTagName("ul")[3].scrollIntoView(false
         i++;
         if (i < 41) {
            myLoop();
          }
     }, 2000)
}
 myLoop();

Thanks in advance!

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You do not need nested loops. You can "linearize" them in single loop (I do not recall the correct therm now). So basically you want loop of 3 * 40 = 120 and after each 40 you need to use increased delay of 10 * 60 * 1000 = 600000. You help yourself by using modulo function i%40. Because you start with 1, the each 40th iteration is when remainder of i divided with 40 is zero.

So basically change if (i < 41) to if (i < 121) and }, 2000) to }, i%40 === 0 ? 600000 : 2000)

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