-2

I want to run a little script in my Browsers (Chrome) Javascript Console, which clicks some buttons to show me some links

for (var i = 1; i <= 300; i++) {
    expandPack("S" + i);
}

So to not ddos the site, I'd need a delay

The delay should be between every run of the expandPack function

So how to do this?

Thanks for your help

EDIT:

Okay, got it to work with this guys code

https://stackoverflow.com/a/3583754/3499442

didn't see it wen googling for it

Although Thank everyone for his help

Community
  • 1
  • 1
  • 2
    http://stackoverflow.com/questions/3583724/how-do-i-add-a-delay-in-a-javascript-loop – Dylan May 31 '14 at 20:19
  • 5
    Look up [`setTimeout()`](https://developer.mozilla.org/en-US/docs/Web/API/Window.setTimeout). – jfriend00 May 31 '14 at 20:19
  • OP doesn't want to artificially invoke a timeout, OP wants to defer the execution and break it into parts from what I understand. Please elaborate on what expandPack does and what browsers you have to support. A `WebWorker` might be a better solution to dispatch external work to a separate thread. – Benjamin Gruenbaum May 31 '14 at 20:22
  • @BenjaminGruenbaum - `// DELAY HERE` sounds kike a time out to me. – PM 77-1 May 31 '14 at 20:26
  • 1
    @PM77-1 "So to not ddos the site, I'd need a delay" although OP probably didn't mean a _distributed dos :) – Benjamin Gruenbaum May 31 '14 at 20:28
  • You could checkout this answer: http://stackoverflow.com/questions/5226285/settimeout-in-a-for-loop-and-pass-i-as-value – viven May 31 '14 at 20:28
  • So, I want to run the Code in my Browsers Conbsole (Google Chrome) to bring up links on a website. I want a delay between every run of the expandPack function. I'll edit the post to clarify this, sorry guys :/ – user3499442 May 31 '14 at 20:29

1 Answers1

0

I would recommend using a timeout in a recursive function like this:

var delay = 100; //In Milliseconds
function loopExpand(count)
{
    expandPack("S" + count);
    if(count < 300)
        setTimeout(function(){loopExpand(count+1)}, delay);
}
vultix
  • 358
  • 4
  • 6