IF...else...condition, please help

Discussions and Tech Support specific to the iMacros Firefox add-on.
Forum rules
Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the search box (at the top of each forum page) to see if a similar problem or question has already been addressed.
3. Try searching the iMacros Wiki - it contains the complete iMacros reference as well as plenty of samples and tutorials.
4. We can respond much faster to your posts if you include the following information: CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST
Post Reply
tgrendo
Posts: 32
Joined: Wed Jul 28, 2010 4:54 pm

IF...else...condition, please help

Post by tgrendo » Fri Feb 18, 2011 4:18 pm

Ok guys i have two macros i want to play in separate conditions.

There is a game i play that from time to time it refresh its own page with a picture i have to click so to continue playing.
I have make a macro that i need to be executed and one that is been executed when the picture is been placed on so to continue.

So in few words i want something like this.

1)I am in the page.
2)I execute macro1
3)IF the page with the picture appears to execute macro2(i can recognize it with the URL of the picture that is always the same).
So in other words i want a condition that will look for URL of the picture IN the page and IF it finds it to execute macro2 and then..
4)Go back to execute macro1.2nd time, then again when it ends to look for IF condition above and if not back to macro1 and so on for 100 times.

All those in a loop of like 100 times.(i noticed in a .js file he loop button do not work but i know there is loop code for javascript...)

Is that possible and if yes can anyone write me the code here as i have no idea of javascript.
tgrendo
Posts: 32
Joined: Wed Jul 28, 2010 4:54 pm

Re: IF...else...condition, please help

Post by tgrendo » Sun Feb 20, 2011 6:12 pm

As i am waiting here for a reply, look what i got.


js Code

Code: Select all

var i;
var s;

 
 for(k=0; k<100; k++) {
 

s = iimGetLastExtract();   
i = s.indexOf ("http://myimageurlhere");


  if (i < 0)  {
   iimPlay ("Google");
  } else {
   iimPlay ("Gmail");
  }
 }

But the problem is it gives me all the time negative even when the URL(image) is there.

What i am doing wrong?

Thank you.
tgrendo
Posts: 32
Joined: Wed Jul 28, 2010 4:54 pm

Re: IF...else...condition, please help

Post by tgrendo » Sun Feb 20, 2011 8:15 pm

now i realized that i have to write the search lines and set the i as a javascript.

Is anyone able to do that for me?

All i need is to nclude in javascript a search on the page of a TXT.

Like search of "Hello" if there is and then set that as i as a result. Postitive if it finds it and negative if not so to continue my loop.


-------------------------------------------------------
EDIT:


As i see i need something like this.

js Code

Code: Select all

var i;

 
 for(k=0; k<100; k++) {
 
search the page  i run the script for a text(for example "Hello world"), using javascript(i dont know how...)<--- to this i need help
And then set the result i ll get as i<--- to this i need help
so to continue with the if.....else.... statement here.
Please guys help me here?



  if (i < 0)  {
   iimPlay ("Google");
  } else {
   iimPlay ("Gmail");
  }
 }
yquant
Posts: 19
Joined: Tue Nov 16, 2010 10:00 am

Re: IF...else...condition, please help

Post by yquant » Mon Feb 21, 2011 12:42 pm

Code: Select all

for (var i = 1; i <= 100; i++) {
  iimPlay("macro1");
  if (iimPlay('CODE: SEARCH SOURCE=TXT:"Hello World!" IGNORE_CASE=YES') < 0) {
    iimPlay("macro1");
  }
  else {
    iimPlay("macro2");
  }
}
tgrendo
Posts: 32
Joined: Wed Jul 28, 2010 4:54 pm

Re: IF...else...condition, please help

Post by tgrendo » Mon Feb 21, 2011 1:42 pm

First of all thank you in advance.


Now trying this out i realized that always goes to else condition even when the test in in the page source.

Also i want when i press the script to do:

1)the search for the word in source of the page i run it
2)if it find the word to play macro1
3)if it will not find the word to play macro2.
4)do the search again after it finish executing macro1 or macro2 and so on the steps 2 and 3.
5) all that in a loop of 100.


With your code here it executes the macro1 first.(btw i removed it of my code that line "iimPlay("macro1");")


EDIT: I cant stop the code here to run, and it loops the macro1 over and over again without the search after it done...
Tom, Tech Support
Posts: 3609
Joined: Mon May 31, 2010 4:59 pm

Re: IF...else...condition, please help

Post by Tom, Tech Support » Tue Feb 22, 2011 12:08 pm

Code: Select all

var ret;

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

	// 1) search for the word in source of the page i run it
	ret = iimPlay('CODE:SEARCH SOURCE=TXT:"Hello World!" IGNORE_CASE=YES');

	// 2)if it find the word to play macro1
	if (ret == 1) {	// Text was found
		ret = iimPlay("macro1");
	}
	// 3)if it will not find the word to play macro2	
	else if (ret != -101) {
		ret = iimPlay("macro2");
	}
  
	if (ret == -101) {	// User clicked the Stop button
		break;
	}
}
Regards,

Tom, iMacros Support
tgrendo
Posts: 32
Joined: Wed Jul 28, 2010 4:54 pm

Re: IF...else...condition, please help

Post by tgrendo » Fri Feb 25, 2011 4:33 pm

Code: Select all

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

  if (iimPlay('CODE: SEARCH SOURCE=TXT:"Hello World!" IGNORE_CASE=YES') < 0) {
    iimPlay("macro1");
  }
  else {
    iimPlay("macro2");
  }
}
I used the above code and works fine.

Tim is it possible to make an if condition here that will check the URL it is?

Like this.

1)Check URL i am in
2)IF URL is this one http://www.URL1.com then continue to the above code.
3)IF URL is anything else but http://www.URL1.com then close the current tab and run the script again.

Thank you in advance.




EDIT. Basically it can be done if there is a way to close all tabs BUT the tab 1 in order.
I mean i have 1,2 tabs opened and some times cause of hanging out the page in tab 2 the script sticks in tab 2 when it has to go back in tab.
Is any way to declare close ALL tabs but tab 1? As they are appearing in my firefox.
OFc if i am to the tab 1 to keep that open as it is.

Thank you in advance.
Tom, Tech Support
Posts: 3609
Joined: Mon May 31, 2010 4:59 pm

Re: IF...else...condition, please help

Post by Tom, Tech Support » Tue Mar 01, 2011 1:02 am

1)Check URL i am in
2)IF URL is this one http://www.URL1.com then continue to the above code.
3)IF URL is anything else but http://www.URL1.com then close the current tab and run the script again.
You can extract the current URL in your macro with the following command:

Code: Select all

ADD !EXTRACT {{!URLCURRENT}}
Then you can retrieve this value in your script with the following:

Code: Select all

var url = iimGetLastExtract(1);

if (url == "http://www.URL1.com") {
     ...
}
else {
     ...
}
Is any way to declare close ALL tabs but tab 1?

Code: Select all

TAB T=1
TAB CLOSEALLOTHERS
Reference:

http://wiki.imacros.net/!URLCURRENT
http://wiki.imacros.net/iimGetLastExtract()
http://wiki.imacros.net/TAB
Regards,

Tom, iMacros Support
tgrendo
Posts: 32
Joined: Wed Jul 28, 2010 4:54 pm

Re: IF...else...condition, please help

Post by tgrendo » Thu Mar 03, 2011 4:27 pm

Tom, iOpus wrote:
1)Check URL i am in
2)IF URL is this one http://www.URL1.com then continue to the above code.
3)IF URL is anything else but http://www.URL1.com then close the current tab and run the script again.
You can extract the current URL in your macro with the following command:

Code: Select all

ADD !EXTRACT {{!URLCURRENT}}
Its same in javascript code as well?Cause i need that in js file as code

Then you can retrieve this value in your script with the following:

Code: Select all

var url = iimGetLastExtract(1);

if (url == "http://www.URL1.com") {
     ...
}
else {
     ...
}
thank you
Is any way to declare close ALL tabs but tab 1?

Code: Select all

TAB T=1
TAB CLOSEALLOTHERS
This is closing all tabs but the one i run it.
I want to close all tabs but the first one, in any tab i may run the code.


Reference:

http://wiki.imacros.net/!URLCURRENT
http://wiki.imacros.net/iimGetLastExtract()
http://wiki.imacros.net/TAB
BOLD.

Thank you Tom
Tom, Tech Support
Posts: 3609
Joined: Mon May 31, 2010 4:59 pm

Re: IF...else...condition, please help

Post by Tom, Tech Support » Fri Mar 04, 2011 5:32 pm

I want to close all tabs but the first one, in any tab i may run the code.
I'm not sure this is possible considering the way iMacros for Firefox handles the counting of tabs:

http://wiki.imacros.net/TAB#Note

You may have to come up with your own Javascript code to accomplish this.
Regards,

Tom, iMacros Support
Post Reply