1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Need javascript random wait time variable

Discussion in 'Other Scripting Languages' started by Plus44, Sep 19, 2015.

  1. Plus44

    Plus44 Power Member

    Joined:
    Dec 14, 2014
    Messages:
    663
    Likes Received:
    252
    Gender:
    Male
    Location:
    US
    I'm running this javascript with iMacros to follow others followers on Twitter

    Problem is it is way to fast

    Can someone tell me how to add a random wait time of about 3-6 seconds between each follow?


    Code:
    //Set Followers Count
    followCount = 500; 
    
    
    //Leave Numbers Alone
    i = 5; 
    u = i - 1; 
    f = 0; 
    skipped = 0; 
    
    
    //Script loops and follows full 500 people disregarding skipped aka already following
    while (f < followCount){
        var scroll = 'CODE:' + 'URL GOTO=javascript:window.scrollBy(10000)';
        iimPlay(scroll); 
        e = window.document.getElementsByClassName('follow-text')[u]; 
        var css = window.document.defaultView.getComputedStyle(e, null); 
        display = css.getPropertyValue('display'); 
    
    
        if(display === "block"){
        iimSet("i",i);
            var macro = 'CODE:' + 'TAG POS={{i}} TYPE=BUTTON ATTR=TXT:Follow<SP>Following<SP>Unfollow<SP>Blocked<SP>Unblock<SP>Pen*';
            i++; f++; u++; 
            iimPlay(macro);
        }else {i++; u++; skipped++;}   
    }//end of Message Count
    iimExit();
    
    Thanks
     
  2. sockpuppet

    sockpuppet Junior Member

    Joined:
    Nov 7, 2011
    Messages:
    155
    Likes Received:
    145
    try this, never tested it
    Code:
    //Set Followers Count
    followCount = 500; 
    
    
    //Leave Numbers Alone
    i = 5; 
    u = i - 1; 
    f = 0; 
    skipped = 0; 
    
    
    function wait(){
      setTimeout( function(){
        if ( f>=followCount ) {   
          iimExit();
          return;
        }
         macro_go();
      }, (Math.random()*3+3)*1000 );
    }
    
    //Script loops and follows full 500 people disregarding skipped aka already following
    function macro_go() {
        var scroll = 'CODE:' + 'URL GOTO=javascript:window.scrollBy(10000)';
        iimPlay(scroll); 
        e = window.document.getElementsByClassName('follow-text')[u]; 
        var css = window.document.defaultView.getComputedStyle(e, null); 
        display = css.getPropertyValue('display'); 
    
    
        if(display === "block"){
        iimSet("i",i);
            var macro = 'CODE:' + 'TAG POS={{i}} TYPE=BUTTON ATTR=TXT:Follow<SP>Following<SP>Unfollow<SP>Blocked<SP>Unblock<SP>Pen*';
            i++; f++; u++; 
            iimPlay(macro);
        }else {i++; u++; skipped++;}   
    
      wait();
    }//end of Message Count
    
    macro_go();
    
     
    • Thanks Thanks x 1
  3. Plus44

    Plus44 Power Member

    Joined:
    Dec 14, 2014
    Messages:
    663
    Likes Received:
    252
    Gender:
    Male
    Location:
    US
    Nope

    ReferenceError: setTimeout is not defined, line 13 (Error code: -991)
     
  4. sockpuppet

    sockpuppet Junior Member

    Joined:
    Nov 7, 2011
    Messages:
    155
    Likes Received:
    145
    change "setTimeout" to "window.setTimeout"
     
    • Thanks Thanks x 1
  5. Plus44

    Plus44 Power Member

    Joined:
    Dec 14, 2014
    Messages:
    663
    Likes Received:
    252
    Gender:
    Male
    Location:
    US
    IT WORKS! Thanks so much