0

How do I use if statements to check the content of the page, then perform an action based on the if statement? Here are the possible outcomes when it comes to clicking:

Picture 1

https://i.stack.imgur.com/bpqy5.png

Picture 2

https://i.stack.imgur.com/1T1un.png

Picture 3

https://i.stack.imgur.com/XQoPA.jpg

So here's my mainline logic:

I will keep on clicking the box on the page [picture 1]

if it encounters [picture 2] click the box (i have the code for that)

else if it encounters [picture 3] refresh the page

else keep on clicking the box

If the images are not clear then feel free to comment and I'll try my best to upload more clear images.


So right now I tried to build the code but it doesn't seem to work.

Map.js

var test;

test ="CODE:";
test +="SET !ERRORIGNORE YES "+"\n";
test +="URL GOTO=http://tppcrpg.net/map.php?Map=11 "+"\n";

for (var i = 1; i < 10 ; i++)
{

iimSet("n",i)
iimPlay(test)
iimPlay("map1.iim")

}

map1.iim

TAG POS=1 TYPE=INPUT:IMAGE FORM=ACTION:/map.php?Map=11 ATTR=NAME:Find

It's giving me this error:

[Exception... "Component returned failure code: 0x80520001 (NS_ERROR_FILE_UNRECOGNIZED_PATH) [nsILocalFile.initWithPath]" nsresult: "0x80520001 (NS_ERROR_FILE_UNRECOGNIZED_PATH)" location: "JS frame :: resource://imacros/utils.js :: :: line 192" data: no], line: 188 (Error code: 991)


Using Expert Complete HTML Code I found out that if I encounter [Picture 3] has the following code:

TAG POS=1 TYPE=H2 ATTR=*
TAG POS=2 TYPE=P ATTR=CLASS:center
puretppc
  • 3,232
  • 8
  • 38
  • 65

3 Answers3

1

You have an example of imacros javacript scripting here.

Loop in Imacros using Javascript

You can declare 3 codes each containing iMacros code to a div on that page. And with if clause you can see which one is present on the page.

Edit:

In HTML you have element called DIV . Like this

<div class="some_div">
Some text
</div>

To click on that div the iMacros code is:

TAG POS=1 TYPE=DIV ATTR=CLASS:some_div
Community
  • 1
  • 1
edinvnode
  • 3,497
  • 7
  • 30
  • 53
  • May I ask what a "div" means? I'm not that experienced with this. – puretppc Nov 08 '13 at 20:59
  • So I tried finding the div classes for all the outcomes and it keeps saying ``. However, on the div class for picture 3, it says `
    ` and then it says the same div class that was mentioned before
    – puretppc Nov 11 '13 at 01:52
  • 1
    Try to record with these options and try to get 3 different imacros codes. http://prntscr.com/23dpme – edinvnode Nov 11 '13 at 08:29
  • Ok so I just tried it and added the code for picture 3. The problem is that there is a random chance that picture 2 or picture 3 will show up so that's why I needed if statements. How would I write the code as if picture 3 is being checked if it's true or not? – puretppc Nov 12 '13 at 00:54
  • Press RECORD, click on the picture 3. Then take the iMacros code and put CONTENT=EVENT:MOUSEOVER at the end of it. If error appears then that means there is no picture. But if there is error then it means that the picture is there. – edinvnode Nov 12 '13 at 05:40
0

Maybe you can create a callback function that's always called when changes (like showing/hiding pictures) happen.

It's pretty hard to help with just the images. Can post some code or give more information? I have/had problems understanding your problem ;)

  • What does callback even do? I'm not that experienced with this. I don't actually have the code written for the if statements because I never used them before. I thought that it might help to like perform an action based on what the page has. – puretppc Nov 06 '13 at 17:06
0

I've found when using iMacros that if I'm using creating a script with any sort of branching (ifs or loops), it's better to code it in JS and only use the iMacros language when doing something the JS can't easily do. You can use iimSet to pass variables to an iMacros script and iimGetLastExtract to get them back to the JS. The "content" variable in JavaScript is equal to the page's "window" object and "content.document" is equal to the page's "document" object.

Without knowing the code in question it's difficult to provide a concrete example. I hope this points you in the right direction and lets you harvest those Pokemon like a boss.

jb_314
  • 1,373
  • 2
  • 17
  • 28