0

There are some imacro with Javascript questions on here, but nothing that gave me what I need... I tried this question: Imacros: Random wait time? and this question: How to loop only a series of steps in iMacros (this was helpful, but now what I have is a bit buggy). I can't figure out why this isn't working...

What I want to do is follow people on Tumblr using imacros. I added the Math.random() function because I want it to choose a random amount of time within 0 to 11 seconds in which it follows a new person.

I only want the imacro to run this part of the code once because it only needs to be run once:

window.location = "URL GOTO = https://www.tumblr.com/search/pony/recent" + "\n";
var rand = "Math.random()*7 + 5";  
var macro = "CODE:SET !REPLAYSPEED FAST" + "\n";
var macro = "CODE:SET !ERRORIGNORE YES" + "\n";
macro += "TAG POS={{i}} TYPE=I ATTR=CLASS:icon_view_list&&TXT:" + "\n";

Then I want it to loop this part of the code (the actual following steps):

macro += "TAG POS={{i}} TYPE=DIV ATTR=TITLE:Like&&CLASS:post_control<SP>like&&TXT: " + "\n";    
macro += "WAIT SECONDS={{rand}}";

It loops it using this:

for(var i=0;i<100;i++)    
{
iimDisplay(i);    
iimSet("i", i);    
iimSet("rand", rand);    
iimPlay(macro);
}

This works well except these lines of code: macro += "TAG POS={{i}} TYPE=I ATTR=CLASS:icon_view_list&&TXT:" + "\n"; and var rand = "Math.random()*7 + 5;" do not seem to be working properly. The first part of code is to make it so it selects the "list view" instead of the "grid view" on tumblr because I cannot get the grid view to work (if anyone has any insight as to why it doesn't work that'd be great, but not a big deal). The second part of the code isn't working properly because it will always set rand to 11 seconds... so it looks like the Math.random() function isn't working properly and I cannot figure it out.

Here's my entire code:

window.location = "URL GOTO = https://www.tumblr.com/search/pony/recent" + "\n";
var rand = "Math.random()*7 + 5";  
var macro = "CODE:SET !REPLAYSPEED FAST" + "\n";
var macro = "CODE:SET !ERRORIGNORE YES" + "\n";
macro += "TAG POS={{i}} TYPE=I ATTR=CLASS:icon_view_list&&TXT:" + "\n";
macro += "TAG POS={{i}} TYPE=DIV ATTR=TITLE:Like&&CLASS:post_control<SP>like&&TXT: " + "\n";    
macro += "WAIT SECONDS={{rand}}";
for(var i=0;i<100;i++)    
{
iimDisplay(i);    
iimSet("i", i);    
iimSet("rand", rand);    
iimPlay(macro);
}
Community
  • 1
  • 1

1 Answers1

0

var rand = "Math.random()*7 + 5"; returns a string, surely

Try:

    window.location = "URL GOTO = https://www.tumblr.com/search/pony/recent" + "\n";

    var macro = "CODE:SET !REPLAYSPEED FAST" + "\n";
    macro += "CODE:SET !ERRORIGNORE YES" + "\n";
    macro += "TAG POS={{i}} TYPE=I ATTR=CLASS:icon_view_list&&TXT:" + "\n";
    macro += "TAG POS={{i}} TYPE=DIV ATTR=TITLE:Like&&CLASS:post_control<SP>like&&TXT: " + "\n";
    macro += "WAIT SECONDS={{rand}}";
    for (var i = 0; i < 100; i++) {
        var rand = Math.random() * 7 + 5; //<--rand should be inside the loop
        iimSet("i", i);
        iimSet("rand", rand);
        iimPlay(macro);
        iimDisplay(i);
    }

EDITED to move the rand inside the loop. Sorry, my bad.

flish
  • 596
  • 1
  • 6
  • 17
  • I realized one problem, but have not been able to fix it. The reason that the code does not create a new random number each time it loops is because it only sets the random number once due to `var` being in front of the command. How can I make it so it runs with the other code that has `macro` in front? If I remove the `rand`, then I don't have a place holder for `iimSet("rand", rand)`. Do you see? I could put `iimPlay(rand)` above `iimPlay(macro)`, however is there a better way? –  Jul 02 '14 at 04:48
  • UPDATE: Tried the above, but now it doesn't recognize `rand` because it is not defined... –  Jul 02 '14 at 05:01