IMACROS execute a command once current link changes?

Discussions and Tech Support related to the iMacros Firefox Add-on, including the built-in Javascript scripting interface for playing .js files.
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
Sidr21
Posts: 1
Joined: Sun Apr 22, 2018 12:08 am

IMACROS execute a command once current link changes?

Post by Sidr21 » Sun Apr 22, 2018 12:16 am

As stated in the title, im trying to have imacros detect when the current url has changed and execute a command when this happens, else keep refreshing the page until the link does change. I am running the imacros add on in firefox. My current code looks like this:

var macro;

macro ="CODE:";
macro += "SET !ERRORIGNORE YES" + "\n";
macro += "SET !TIMEOUT_STEP 1" + "\n"
macro += "TAG POS=1 TYPE=A ATTR=TXT:*Some Text*" + "\n";
macro += "ADD !EXTRACT {{!URLCURRENT}}" + "\n";
macro += "REFRESH" + "\n";

for (var i=0;i<=50;i++) {

iimPlay(macro);
var link=iimGetLastExtract();
iimSet("LINK",link)

if ("LINK"= ("Some URL"))
{
break;

}
}
In the first part, the code will press on a certain text if it is present on the page, this works fine. My problem comes in during the if statement. I cant figure out how to compare the extracted link and a certain other link. I want the loop to break if the extracted link and the certain link are the same. I am very new to both Java and Imacros so any help would be greatly appreciated!
chivracq
Posts: 8525
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: IMACROS execute a command once current link changes?

Post by chivracq » Sun Apr 22, 2018 8:32 pm

Sidr21 wrote:As stated in the title, im trying to have imacros detect when the current url has changed and execute a command when this happens, else keep refreshing the page until the link does change. I am running the imacros add on in firefox. My current code looks like this:

Code: Select all

var macro;

macro ="CODE:";
macro += "SET !ERRORIGNORE YES" + "\n";
macro += "SET !TIMEOUT_STEP 1" + "\n"
macro += "TAG POS=1 TYPE=A ATTR=TXT:*Some Text*" + "\n";
macro += "ADD !EXTRACT {{!URLCURRENT}}" + "\n";
macro += "REFRESH" + "\n";

for (var i=0;i<=50;i++) {

iimPlay(macro);
var link=iimGetLastExtract();
iimSet("LINK",link)

if ("LINK"= ("Some URL"))
{
break;

}
}
In the first part, the code will press on a certain text if it is present on the page, this works fine. My problem comes in during the if statement. I cant figure out how to compare the extracted link and a certain other link. I want the loop to break if the extracted link and the certain link are the same. I am very new to both Java and Imacros so any help would be greatly appreciated!
(F)CIM...! :mrgreen: (Read my Sig...)

'iimSet()' is for passing a Var from your main '.js' Script to (inside) your '.iim', you don't need it as you are still in the '.js' for your 'IF' Comparison...

And, hum..., you didn't really need a '.js' Script if you simply want to abort your Script once the Cond. has been met, it could easily be done in pure '.iim' with 'MacroError()'... :idea:

>

+Parallel Thread on SOF:
- How to make IMACROS execute a command when the current link changes?
(No Replies yet...)
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
User avatar
thecoder2012
Posts: 331
Joined: Sat Aug 15, 2015 5:14 pm
Location: Internet
Contact:

Re: IMACROS execute a command once current link changes?

Post by thecoder2012 » Thu May 03, 2018 2:55 am

Example without your errors:

Code: Select all

var macro;
macro ="CODE:";
macro += "SET !ERRORIGNORE YES" + "\n";
macro += "SET !TIMEOUT_STEP 1" + "\n"
macro += "TAG POS=1 TYPE=A ATTR=TXT:*Some Text*" + "\n";
macro += "ADD !EXTRACT {{!URLCURRENT}}" + "\n";
macro += "REFRESH" + "\n";

for (var i=0;i<=50;i++) {
	iimPlay(macro);
	var link=iimGetLastExtract();

	if(link == "Some URL"){
		break;
	}
}
Sidr21 wrote:I am very new to both Java and Imacros so any help would be greatly appreciated!
Java? It's Javascript!
Join 9kw.eu Captcha Service now and let your iMacros continue downloads and scripts while you sleep. - Custom iMacros? Contact me! :idea:
Post Reply