Javascript functions inside EVAL (tricks for search and use)

Discussions and Tech Support related to the iMacros Firefox Add-on, including the built-in Javascript scripting interface for playing .js files.

Moderators: Community Moderators, iMacros Moderators

Forum rules
Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the Google search box (at the top of each forum page) to see if a similar problem or question has already been addressed. This will search the entire contents of the forums as well as the iMacros Wiki.
3. We can respond much faster to your posts if you include the following information:

CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST

Answering your own posts (e.g. attempting to "bump" your topic) drops your topic from the list of unanswered threads, so it may actually receive less views.

Javascript functions inside EVAL (tricks for search and use)

by Guest0034 on Sat Dec 17, 2016 4:41 pm

Fci OS Windows 10, iMacro for firefox v. 8.9.7, Firefox version 49.0.0.0

My question is:
I have read almost all the topics related to this argument, but being not too familiar with javascripts I am asking here how can I use eval for set a variable to 0 if a specific word is not present or 1 if present.
Ive got this at this point:
Code: Select all
SET var1 eval{*}
TAG POS={var1} TYPE=SPAN ATTR=TXT:{**}

But dunno how set the {*} part of the code.
Basically In a page there are 4 ways a page can show you.
The page can show an AAAA, a BBBB, a CCCC or a DDDD (textual example) and the code need to test each of the 4 occurrance for select the one active at the moment and let the script go.
Ideal way is to run eval 4 times and assign 4 var values and then execute them in a row after the assignment for avoid that, executing first command, the page can change and the next check get something wrong in the next page by mistake.
A sort of code like:
Code: Select all
SET var1 eval{*}
SET var2 eval{*}
SET var3 eval{*}
SET var4 eval{*}
TAG POS={var1} TYPE=SPAN ATTR=TXT:{**}
TAG POS={var2} TYPE=SPAN ATTR=TXT:{**}
TAG POS={var3} TYPE=SPAN ATTR=TXT:{**}
TAG POS={var4} TYPE=SPAN ATTR=TXT:{**}

This way only the specific order is activated by it, but not the others.
Anyone can give a hint for this?
[This can work in many ways, so teach someone how to do it can be useful for various purposes]
[Even a link with a list of javascripts commands usable in EVAL can give help]
Thanks in advance.
Guest0034
Last edited by Guest0034 on Wed Dec 21, 2016 4:12 am, edited 2 times in total.
Windows 10, iMacro for firefox v. 8.9.7, first time ready to use iMacro seriously.
Already checked the WIKI and if I ask I'm already done with tries.

Sorry for the bad English, but then google does not help much with translations... :P
Guest0034
 
Posts: 29
Joined: Wed Sep 14, 2016 7:46 am

Re: Javascript in EVAL command help

by chivracq on Sat Dec 17, 2016 9:30 pm

Guest0034 wrote:
Code: Select all
Fci present in signature. Firefox version, ATM is 49.0.0.0


My question is:
I have read almost all the topics related to this argument, but being not too familiar with javascripts I am asking here how can I use eval for set a variable to 0 if a specific word is not present or 1 if present.
Ive got this at this point:
Code: Select all
SET var1 eval{*}
TAG POS={var1} TYPE=SPAN ATTR=TXT:{**}

But dunno how set the {*} part of the code.
Basically In a page there are 4 ways a page can show you.
The page can show an AAAA, a BBBB, a CCCC or a DDDD (textual example) and the code need to test each of the 4 occurrance for select the one active at the moment and let the script go.
Ideal way is to run eval 4 times and assign 4 var values and then execute them in a row after the assignment for avoid that, executing first command, the page can change and the next check get something wrong in the next page by mistake.
A sort of code like:
Code: Select all
SET var1 eval{*}
SET var2 eval{*}
SET var3 eval{*}
SET var4 eval{*}
TAG POS={var1} TYPE=SPAN ATTR=TXT:{**}
TAG POS={var2} TYPE=SPAN ATTR=TXT:{**}
TAG POS={var3} TYPE=SPAN ATTR=TXT:{**}
TAG POS={var4} TYPE=SPAN ATTR=TXT:{**}

This way only the specific order is activated by it, but not the others.
Anyone can give a hint for this?
[This can work in many ways, so teach someone how to do it can be useful for various purposes]
[Even a link with a list of javascripts commands usable in EVAL can give help]
Thanks in advance.
Guest0034

Code: Select all
Fci present in signature. Firefox version, ATM is 49.0.0.0

Yep, but I've already asked you twice to still mention your FCI hard-coded when you open a Thread for the Reasons below, it's completely confusing otherwise..., do it properly sorry, I don't even try to read nor answer...
... and you should still hard-code your FCI in your OP when you open a New Thread as you only have one Dynamic Sig for the whole Forum...)
=> OK, but your Sig still mentions that you are using vX.X.X, that's why I mentioned that mentioning your FCI in your Sig can be confusing...

Bump your Thread once you've mentioned your FCI clearly at the top of your OP for me to have a look at this Thread again... (I won't notice/check it again if you edit your OP silently...)
And, pfff, last time I ask, sorry, do things a bit properly, I quickly loose interest if I have to ask several times for "things"...

And hum, quickly scanning your Post to see if I might have some other Qt's after you'll have mentioned your FCI correctly for me to read, and hum...: :roll:
- Thread Title is a bit useless: "Javascript in EVAL command help"
=> The only useful (= Descriptive) Term is 'EVAL'...
- Everybody on the Forum is looking for "Help". => Useless...
- Yep, 'EVAL' is a "Command". => Useless...
- Everything in 'EVAL()' is "Javascript". => Useless...
So OK, your Thread/Qt is about 'EVAL()' but I don't have a clue about what precisely... :roll:
Try searching the Forum for the Keywords you used in your Thread Title and you should be able to find similar Threads or any other User(s) searching the Forum with a similar Qt like yours should find this Thread..., well, good luck for everybody with "javascript + EVAL + command + help", ah-ah...! :roll:

- Hum, I don't see any URL which always complicates things, I've asked you 3 times now in your previous Thread to mention some URL but you never reacted to that..., and I see some kind of a "fake" Script:
Code: Select all
SET var1 eval{*}
SET var2 eval{*}
...
So, hum..., OK, I hope the rest of the Post gives enough Info, it doesn't look too promising to me at the moment... But OK, I'll read it "correctly" once (= 1 time) once (= after) you'll have mentioned your FCI correctly and edited your Thread Title into stg a bit more Descriptive than just "EVAL" which is at this moment the only Term that gives me an idea what this Thread is about..., I won't go acting like a Detective who needs to ask the right Qt's in order to have an idea of the whole "Situation", sorry, not my "Role", you need to supply all necessary Info (and preferably too much Info than too little) if you want other Users to be able to help you, ah-ah...! Think pragmatically and proactively... (And I'm still your "best Friend", don't get offended...!) :idea:
- (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...
chivracq
 
Posts: 6307
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)

Re: Javascript in EVAL command help

by Guest0034 on Sun Dec 18, 2016 3:18 am

chivracq wrote:
Code: Select all
Fci present in signature. Firefox version, ATM is 49.0.0.0

Yep, but I've already asked you twice to still mention your FCI hard-coded when you open a Thread for the Reasons below, it's completely confusing otherwise..., do it properly sorry, I don't even try to read nor answer...
... and you should still hard-code your FCI in your OP when you open a New Thread as you only have one Dynamic Sig for the whole Forum...)
=> OK, but your Sig still mentions that you are using vX.X.X, that's why I mentioned that mentioning your FCI in your Sig can be confusing...

Bump your Thread once you've mentioned your FCI clearly at the top of your OP for me to have a look at this Thread again... (I won't notice/check it again if you edit your OP silently...)
And, pfff, last time I ask, sorry, do things a bit properly, I quickly loose interest if I have to ask several times for "things"...

Done.
chivracq wrote:And hum, quickly scanning your Post to see if I might have some other Qt's after you'll have mentioned your FCI correctly for me to read, and hum...: :roll:
- Thread Title is a bit useless: "Javascript in EVAL command help"
=> The only useful (= Descriptive) Term is 'EVAL'...
- Everybody on the Forum is looking for "Help". => Useless...
- Yep, 'EVAL' is a "Command". => Useless...
- Everything in 'EVAL()' is "Javascript". => Useless...
So OK, your Thread/Qt is about 'EVAL()' but I don't have a clue about what precisely... :roll:
Try searching the Forum for the Keywords you used in your Thread Title and you should be able to find similar Threads or any other User(s) searching the Forum with a similar Qt like yours should find this Thread..., well, good luck for everybody with "javascript + EVAL + command + help", ah-ah...! :roll:

Tried to do my best, but my problem is that I dont know exactly how do it inside eval command so annot be more explicit than this way. Any suggestion for a better title is appreciated, if the new one is not enough.
I have time for edit title once I have got more info, but actually is just a clue because I dont know the "better way to explain it".
About URL i'm not searching about a specific site, but for an universal way to get this effect, maybe in a google search, in a mail page, in a game page, in a trading page and so on.
If you want, I can search for a game I do, do you know Renaissance Kingdom? Is a game with feature similar to this, and even if I have no interest on having it automated, it can give you an idea.
Site is http://www.lesroyaumes.com/, but maybe you need an account for try look inside it.
I can make one just for let you see inside the page, but is better if you do one for free and take a look. You can even check in the home with existance of the subscription block or you can choose any other site that has textual links for send to specific other function. I can join a script, but when I know how to set an "extract" command for catch the text present in the link needed, I dont know exactly how to use it for "EVAL" it correctly...
chivracq wrote:- Hum, I don't see any URL which always complicates things, I've asked you 3 times now in your previous Thread to mention some URL but you never reacted to that..., and I see some kind of a "fake" Script:
Code: Select all
SET var1 eval{*}
SET var2 eval{*}
...
So, hum..., OK, I hope the rest of the Post gives enough Info, it doesn't look too promising to me at the moment... But OK, I'll read it "correctly" once (= 1 time) once (= after) you'll have mentioned your FCI correctly and edited your Thread Title into stg a bit more Descriptive than just "EVAL" which is at this moment the only Term that gives me an idea what this Thread is about..., I won't go acting like a Detective who needs to ask the right Qt's in order to have an idea of the whole "Situation", sorry, not my "Role", you need to supply all necessary Info (and preferably too much Info than too little) if you want other Users to be able to help you, ah-ah...! Think pragmatically and proactively... (And I'm still your "best Friend", don't get offended...!) :idea:

It's not a "fake" script, but a question on what has to be set inside the braces for have the effect needed (and even if there are text outside EVAL for better improvement of recognizing system).

My "request" is a sort of guide for one of the most difficult task for a newcomer to iMacros, handling with EVAL instruction, the most versatile and flexible, but the most professional in many ways.
I was looking for a "hint" or a "guide" on how use it, because the firefox help page given on the specific thread and the specific thread himself are not so helpful in this.
That the reason I'm asking in a general way.

I've got the chance to ask for make an example with this, because it's one of the most useful for me, but maybe that, if I receive a good guide about ther "inside EVAL codings" I cann go by myself without boring you for this.
And maybe this function is a solution for few other problems I have sent or even the one I have not yet sent here.
Windows 10, iMacro for firefox v. 8.9.7, first time ready to use iMacro seriously.
Already checked the WIKI and if I ask I'm already done with tries.

Sorry for the bad English, but then google does not help much with translations... :P
Guest0034
 
Posts: 29
Joined: Wed Sep 14, 2016 7:46 am

Re: Javascript in EVAL command help

by chivracq on Sun Dec 18, 2016 4:32 am

Guest0034 wrote:
Code: Select all
Fci:
OS Windows 10, iMacro for firefox v. 8.9.7, Firefox version 49.0.0.0

Tried to do my best, but my problem is that I dont know exactly how do it inside eval command so annot be more explicit than this way. Any suggestion for a better title is appreciated, if the new one is not enough.
I have time for edit title once I have got more info, but actually is just a clue because I dont know the "better way to explain it".
About URL i'm not searching about a specific site, but for an universal way to get this effect, maybe in a google search, in a mail page, in a game page, in a trading page and so on.
If you want, I can search for a game I do, do you know Renaissance Kingdom? Is a game with feature similar to this, and even if I have no interest on having it automated, it can give you an idea.
Site is http://www.lesroyaumes.com/, but maybe you need an account for try look inside it.
I can make one just for let you see inside the page, but is better if you do one for free and take a look. You can even check in the home with existance of the subscription block or you can choose any other site that has textual links for send to specific other function. I can join a script, but when I know how to set an "extract" command for catch the text present in the link needed, I dont know exactly how to use it for "EVAL" it correctly...

>

It's not a "fake" script, but a question on what has to be set inside the braces for have the effect needed (and even if there are text outside EVAL for better improvement of recognizing system).

My "request" is a sort of guide for one of the most difficult task for a newcomer to iMacros, handling with EVAL instruction, the most versatile and flexible, but the most professional in many ways.
I was looking for a "hint" or a "guide" on how use it, because the firefox help page given on the specific thread and the specific thread himself are not so helpful in this.
That the reason I'm asking in a general way.

I've got the chance to ask for make an example with this, because it's one of the most useful for me, but maybe that, if I receive a good guide about ther "inside EVAL codings" I cann go by myself without boring you for this.
And maybe this function is a solution for few other problems I have sent or even the one I have not yet sent here.

OK, FCI mentioned, => good, Thread Title a bit improved, => a bit better even if I still didn't really understand only from it what the Thread would be about exactly, so I was a bit surprised to read as a first sentence "I have read almost all the topics related to this argument...", => me thinking: "Woaw...!, wondering what Keywords you used to search the Forum or Google to locate "all the topics related to this argument"...!?", but OK, I read your OP and everything...

Still not completely clear, but I think I understood more or less...
About your Game, I normally/usually don't help Users trying to use/misuse iMacros for (cheating for) Games (+ Votes and Spam) even if I got myself absolutely all my Knowledge about iMacros from automating playing Games, ah-ah...!
And I don't create (anymore) an Account on every Site Users have a Pb or play a Game on, but, hum, you are a bit lucky, ah-ah...!, I used to play that Game myself for 1 or 2 years maybe and I still have some Login somewhere but they had already implemented some Captcha so I'll be a bit "careful"..., and again, I'm not too keen on helping Users for Games...

But OK, about your Principle for 'AAAA' / 'BBBB' etc being "active" or not ("active" btw is not very clear to me, if all Words are present on the Page but only one is "active" or if only one is "present" at the time, but the "Principle" will be similar, I'll explain the Difference a bit further), the Principle is to try to extract the HTML Element displaying it with stg like:
Code: Select all
TAG POS=1 TYPE=DIV ATTR=TXT:*AAAA* EXTRACT=TXT
I don't know about the 'TYPE', you'll need to record yourself to find out if it's a 'DIV' or a 'SPAN' or whatever...

Then if 'EXTRACT' returns "#EANF#", that means your Element and therefore your Word was not found and you indeed use 'EVAL()' to spit the 1/0 that you want, so for 'AAAA', that will give stg like:
Code: Select all
SET !EXTRACT NULL
TAG POS=1 TYPE=DIV ATTR=TXT:*AAAA* EXTRACT=TXT
SET !VAR1 EVAL("var s='{{!EXTRACT}}'; var x; if(s!='#EANF#'){x=1;} else{x=0;}; x;")
TAG POS={{!VAR1}} TYPE=SPAN ATTR=TXT:{**}
And I don't know what's in your"TXT:{**}"

And you repeat the same "Process" for all 4 Words...
And you'll need to use '!ERRORIGNORE' because iMacros doesn't like otherwise "TAG POS=0", ah-ah...!

But there is maybe even more simple if your "TXT:{**}" contains "AAAA" etc which won't do anything if the Element/Word does not exist if you simply use '!ERRORIGNORE' as well, together with a short '!TIMEOUT_STEP'...

More Info in the following Thread where I've already explained the whole Technique and which contains a list of useful Threads containing many Examples of how to use 'EVAL()' for this Purpose:
- Workarounds for Conditional Logic in Macro Code

Oh yeah, and if all 4 Words are always present on the Page but only one is "active" at the time, there will always be stg in the HTML Code to differentiate the Active one from the 3 other ones, it can be the Colour, or Bold or the Background Image and by looking at the Source Code or doing a:
Code: Select all
TAG POS=1 TYPE=DIV ATTR=TXT:*AAAA* EXTRACT=HTM
... on your Element, you should be able to identify some extra Attribute to use for the 'EXTRACT' Statement... (and/or Relative Positioning can help sometimes).

Well, good luck and I hope you understand the Principle/Technique... I was told a bit earlier today that I have "poor explaining Skills" while trying to explain "1+1", ah-ah...!, so I hope it goes a bit better with you, ah-ah...! 8)
- (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...
chivracq
 
Posts: 6307
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)

Re: {Javascript coding inside EVAL} command list

by Guest0034 on Sun Dec 18, 2016 6:14 am

So there aren't chances to "extract" text directly inside the EVAL statement?
I have read your topic, as told before, but there are no instruction on how use EVAL better than copy directly your text.
As for the site, thinking about marketplace (dont know english word used by the game, sorry) you can use iMacro for detect if there is a specific item for sale, use extract too for detect if there is a value you can compare in EVAL and, when found it, you can add a number of items in your purchase list, but then you have to use the "complete" (as before is a "guessed" word, because I'm using it in another language) for confirm your purchase.
My problem was like something similar, so "it's not a button, but a text inside a buttonlike picture".
So how collect the text from the whole window (as before is for make an example. I wont do task like this automated, specifically in a game because I'm not a cheater) and if present let the macro click on it?
In the "main project" window, the one where I am working for it, there is only 2 "button" at time, but "button" is not a correct word, being them "text inside a buttonlike picture".
They are:
"Search" and "Cancel search"
"Select" and "Cancel select"
"Run selection" and "Cancel run"
and last, but not last,
"New instance" and "Close job window"
I'm using first buttons for let the thing run, but if "search" dont work, the "New instance" appear instead, and if the selected items don't have the "Run" function, again the "New instance" appear.
Im not looking for a specific site work, but for a general knowledge that can allow me work alone instead boring people with my boring questions.
That's why I'm looking not for a "specific site" solution, but the knowledge for work alone inside the EVAL function.
I've tried to copy your script and adapt it with one of "my" sites, but it was not working properly, so I was asking the knowledge I can use for program alone that situations.
I've read all the links in your topics, but they have poor answers and some of the "general google search" results I have found more "general javascripts" instructions more than EVAL instructions.
Maybe I'm not so good with this not knowing javascripts too well, but for this I was asking a source compatible with EVAL and iMacro EVAL programming.
Basically I'm going to work on your suggestion and try to work at it for decompose it and learn from it, but hope you can give a better solution for my request.
BTW, I will make a little example program for ask you if it's correct or not.
I will use 4 variable before running the "TAG POS={{!VAR1}} TYPE=SPAN ATTR=TXT:{AAAA/BBBB/CCCC/DDDD}" because the screen can change during the script working then a new instance of extract can alterate all the target result.
Thanks, really thanks.
Guest0034

p.s.: {**} was "where put the 4 digit words" without typing them in each row because dont know the best way to set them correctly after the EVAL statement not knowing how it will seems".
Windows 10, iMacro for firefox v. 8.9.7, first time ready to use iMacro seriously.
Already checked the WIKI and if I ask I'm already done with tries.

Sorry for the bad English, but then google does not help much with translations... :P
Guest0034
 
Posts: 29
Joined: Wed Sep 14, 2016 7:46 am

Re: {Javascript coding inside EVAL} command list

by Guest0034 on Sun Dec 18, 2016 7:11 am

With few work there is the result:

Usig AAAA, BBBB, CCCC and DDDD as "example text to be found" this is a working script, thanks:

Code: Select all
SET !ERRORIGNORE YES
...
SET !EXTRACT NULL
TAG POS=1 TYPE=A ATTR=TXT:*AAAA* EXTRACT=TXT
SET !VAR1 EVAL("var s='{{!EXTRACT}}'; var x; if(s!='#EANF#'){x=1;} else{x=0;}; x;")
SET !EXTRACT NULL
TAG POS=1 TYPE=A ATTR=TXT:*BBBB* EXTRACT=TXT
SET !VAR2 EVAL("var s='{{!EXTRACT}}'; var x; if(s!='#EANF#'){x=1;} else{x=0;}; x;")
SET !EXTRACT NULL
TAG POS=1 TYPE=A ATTR=TXT:*CCCC* EXTRACT=TXT
SET !VAR3 EVAL("var s='{{!EXTRACT}}'; var x; if(s!='#EANF#'){x=1;} else{x=0;}; x;")
SET !EXTRACT NULL
TAG POS=1 TYPE=A ATTR=TXT:*DDDD* EXTRACT=TXT
SET !VAR4 EVAL("var s='{{!EXTRACT}}'; var x; if(s!='#EANF#'){x=1;} else{x=0;}; x;")
TAG POS={{!VAR1}} TYPE=A ATTR=TXT:AAAA
TAG POS={{!VAR2}} TYPE=A ATTR=TXT:BBBB
TAG POS={{!VAR3}} TYPE=A ATTR=TXT:CCCC
TAG POS={{!VAR4}} TYPE=A ATTR=TXT:DDDD
...


That's working, when changing the keywords in general use with the specific ones.
It was working perfectly in 3 different sites. Thanks.
But still hope you can give a better source for "programming inside EVAL".
That will be true gold for not javascripters and iMacro users.
Thanks again.
Windows 10, iMacro for firefox v. 8.9.7, first time ready to use iMacro seriously.
Already checked the WIKI and if I ask I'm already done with tries.

Sorry for the bad English, but then google does not help much with translations... :P
Guest0034
 
Posts: 29
Joined: Wed Sep 14, 2016 7:46 am

Re: {Javascript coding inside EVAL} command list

by chivracq on Sun Dec 18, 2016 1:04 pm

Guest0034 wrote:So there aren't chances to "extract" text directly inside the EVAL statement?
I have read your topic, as told before, but there are no instruction on how use EVAL better than copy directly your text.
As for the site, thinking about marketplace (dont know english word used by the game, sorry) you can use iMacro for detect if there is a specific item for sale, use extract too for detect if there is a value you can compare in EVAL and, when found it, you can add a number of items in your purchase list, but then you have to use the "complete" (as before is a "guessed" word, because I'm using it in another language) for confirm your purchase.
My problem was like something similar, so "it's not a button, but a text inside a buttonlike picture".
So how collect the text from the whole window (as before is for make an example. I wont do task like this automated, specifically in a game because I'm not a cheater) and if present let the macro click on it?
In the "main project" window, the one where I am working for it, there is only 2 "button" at time, but "button" is not a correct word, being them "text inside a buttonlike picture".
They are:
"Search" and "Cancel search"
"Select" and "Cancel select"
"Run selection" and "Cancel run"
and last, but not last,
"New instance" and "Close job window"
I'm using first buttons for let the thing run, but if "search" dont work, the "New instance" appear instead, and if the selected items don't have the "Run" function, again the "New instance" appear.
Im not looking for a specific site work, but for a general knowledge that can allow me work alone instead boring people with my boring questions.
That's why I'm looking not for a "specific site" solution, but the knowledge for work alone inside the EVAL function.
I've tried to copy your script and adapt it with one of "my" sites, but it was not working properly, so I was asking the knowledge I can use for program alone that situations.
I've read all the links in your topics, but they have poor answers and some of the "general google search" results I have found more "general javascripts" instructions more than EVAL instructions.
Maybe I'm not so good with this not knowing javascripts too well, but for this I was asking a source compatible with EVAL and iMacro EVAL programming.
Basically I'm going to work on your suggestion and try to work at it for decompose it and learn from it, but hope you can give a better solution for my request.
BTW, I will make a little example program for ask you if it's correct or not.
I will use 4 variable before running the "TAG POS={{!VAR1}} TYPE=SPAN ATTR=TXT:{AAAA/BBBB/CCCC/DDDD}" because the screen can change during the script working then a new instance of extract can alterate all the target result.
Thanks, really thanks.
Guest0034

p.s.: {**} was "where put the 4 digit words" without typing them in each row because dont know the best way to set them correctly after the EVAL statement not knowing how it will seems".

"So there aren't chances to "extract" text directly inside the EVAL statement?"
=> No, you first need to tag some HTML Element and use the Extract Mechanism to extract its Text or HTML Code or URL for a Link and you use 'EVAL()' for example to spit out a 1/0 if the Element was found or not like in your Case or you use 'EVAL()' to do some Data Manipulation on the String or Number(s) that got extracted when you use iMacros for "Data Extraction".

Guest0034 wrote:With few work there is the result:

Usig AAAA, BBBB, CCCC and DDDD as "example text to be found" this is a working script, thanks:

Code: Select all
SET !ERRORIGNORE YES
...
SET !EXTRACT NULL
TAG POS=1 TYPE=A ATTR=TXT:*AAAA* EXTRACT=TXT
SET !VAR1 EVAL("var s='{{!EXTRACT}}'; var x; if(s!='#EANF#'){x=1;} else{x=0;}; x;")
SET !EXTRACT NULL
TAG POS=1 TYPE=A ATTR=TXT:*BBBB* EXTRACT=TXT
SET !VAR2 EVAL("var s='{{!EXTRACT}}'; var x; if(s!='#EANF#'){x=1;} else{x=0;}; x;")
SET !EXTRACT NULL
TAG POS=1 TYPE=A ATTR=TXT:*CCCC* EXTRACT=TXT
SET !VAR3 EVAL("var s='{{!EXTRACT}}'; var x; if(s!='#EANF#'){x=1;} else{x=0;}; x;")
SET !EXTRACT NULL
TAG POS=1 TYPE=A ATTR=TXT:*DDDD* EXTRACT=TXT
SET !VAR4 EVAL("var s='{{!EXTRACT}}'; var x; if(s!='#EANF#'){x=1;} else{x=0;}; x;")
TAG POS={{!VAR1}} TYPE=A ATTR=TXT:AAAA
TAG POS={{!VAR2}} TYPE=A ATTR=TXT:BBBB
TAG POS={{!VAR3}} TYPE=A ATTR=TXT:CCCC
TAG POS={{!VAR4}} TYPE=A ATTR=TXT:DDDD
...


That's working, when changing the keywords in general use with the specific ones.
It was working perfectly in 3 different sites. Thanks.
But still hope you can give a better source for "programming inside EVAL".
That will be true gold for not javascripters and iMacro users.
Thanks again.

Yep, very good, that's exactly what I mentioned: I gave you one Block for one Word, you repeat for each other Word and you use '!ERRORIGNORE'...

Well, I don't do any '.js' Scripts and I hardly know anything about JavaScript (well, 3 years after I joined the Forum and being able to answer maybe 80% of all Threads that get opened on the Forum, I guess I understand a bit (more) of JS now...) and that's why I came up with this Method of using 'EVAL()' (+ a few other "Tricks" mentioned in the Thread I referred you to) to be able to add some Conditional Logic to my Scripts in pure '.iim' and be able to avoid '.js' Scripts.

The Method was "mine" and I was or am probably or at least for a long time the only one to use it as JavaScript in '.js' Scripts is (still) the "Standard" way to do Conditional Behaviour in iMacros, but if you search my Posts on "EVAL", I guess you'll find more than a hundred Threads where I've produced some "interesting" 'EVAL()' Statements that you can use as Examples.

Within 'EVAL()' I usually use a limited Set of JavaScript Functions: 'split()', 'trim()', 'replace()', 'substr()', 'substring()', 'indexOf()', 'floor()', 'ceil()', 'random()' and that's more or less about it. You can use those as Search Keywords on the Forum (one by one together with "eval", I don't use them all together in one Script, ah-ah...!) and you'll find plenty of Examples... :idea:
- (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...
chivracq
 
Posts: 6307
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)

Re: {Javascript coding inside EVAL} command list

by Guest0034 on Sun Dec 18, 2016 2:02 pm

Could I suggest to collect in a post of the Workarounds for Conditional Logic in Macro Code a list of the varius topics and a little description of the use you suggested to all?
This will reach 2 main objectives:
1st) you can keep track of all your past job and use them as reference with ease and
2nd) anyone can, without boring you with this kind of problems, try to find in an easier way coding searching directly in a list of solution from a single post of all your codes and figure himself how to use them for a better solution.
I go experimenting the command list you gave me here and hope never come back with similar problems.
Thanks again, really thanks again and I hope you can have less job to "newbies" like me. :P
I know about programming, but any language is different for form compiling and command list, so "be a decent programmer" will be a force point and too a weak point.
Any knowledge you have is not necessarily useful... and any knowledge can be a good starting point or a totally wrong way. :P
Windows 10, iMacro for firefox v. 8.9.7, first time ready to use iMacro seriously.
Already checked the WIKI and if I ask I'm already done with tries.

Sorry for the bad English, but then google does not help much with translations... :P
Guest0034
 
Posts: 29
Joined: Wed Sep 14, 2016 7:46 am

Re: {Javascript coding inside EVAL} command list

by chivracq on Sun Dec 18, 2016 4:52 pm

Guest0034 wrote:Could I suggest to collect in a post of the Workarounds for Conditional Logic in Macro Code a list of the varius topics and a little description of the use you suggested to all?
This will reach 2 main objectives:
1st) you can keep track of all your past job and use them as reference with ease and
2nd) anyone can, without boring you with this kind of problems, try to find in an easier way coding searching directly in a list of solution from a single post of all your codes and figure himself how to use them for a better solution.
I go experimenting the command list you gave me here and hope never come back with similar problems.
Thanks again, really thanks again and I hope you can have less job to "newbies" like me. :P
I know about programming, but any language is different for form compiling and command list, so "be a decent programmer" will be a force point and too a weak point.
Any knowledge you have is not necessarily useful... and any knowledge can be a good starting point or a totally wrong way. :P

Hum, you are right about the "Collecting Post", I had started to do so in this Post from the Thread, but hum, last Update is from more than 2 years, oops...!, so a lot of water has run underneath the bridge since, ah-ah...!

I do a little "better job" in this other Thread "of mine" where I maintain as well a list of "interesting" Threads pertaining to the 'EVENT' Mode.

But if you have some Programming Background, iMacros is not difficult to master a bit, the most important "Ingredient" is "Creativity" to make interesting things with it... :idea:
Last edited by chivracq on Sat May 27, 2017 10:23 am, edited 1 time in total.
- (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...
chivracq
 
Posts: 6307
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)

Re: Javascript functions inside EVAL (tricks for search and

by Guest0034 on Wed Dec 21, 2016 4:17 am

Edited the title for give few hints about content of topic.
As wanted by me this one can address people to few sources and commands for EVAL best use.
Thanks again.
Your help has been very precious on this.
And I hope your posts can help someone other when searching for functions and hints about EVAL. ;) :D
[No need to answer until you have a better title to propose. Actually, for me at least, this is a starred topic in my google chrome online account an, just for precaution, to firefox online account too. :D
Better avoid to lose it for a virus or an accidental damage to my PC. :P]
Windows 10, iMacro for firefox v. 8.9.7, first time ready to use iMacro seriously.
Already checked the WIKI and if I ask I'm already done with tries.

Sorry for the bad English, but then google does not help much with translations... :P
Guest0034
 
Posts: 29
Joined: Wed Sep 14, 2016 7:46 am

Re: Javascript functions inside EVAL (tricks for search and

by Guest0034 on Thu Dec 22, 2016 11:53 am

An idea based on the same reasoning.
You can set the script to push a text instead of another if a specific text is present?
I've thought on something about this and want to know if it's a good idea or a trashing one instead.
Code: Select all
SET !ERRORIGNORE YES
...
SET !EXTRACT NULL
TAG POS=1 TYPE=A ATTR=TXT:*Text to search* EXTRACT=TXT
SET !VAR1 EVAL("var s='{{!EXTRACT}}'; var x; if(s!='#EANF#'){x="Click if search is successful";} else{x="Click if search fail";}; x;")
TAG POS=1 TYPE=A ATTR=TXT:{{!VAR1}}
...

And do you think that both EVAL can be applied, obviously to different VAR, to a single function?
Something like:

Code: Select all
SET !EXTRACT NULL
TAG POS=1 TYPE=A ATTR=TXT:*Check if button is present* EXTRACT=TXT
SET !VAR1 EVAL("var s='{{!EXTRACT}}'; var x; if(s!='#EANF#'){x=1;} else{x=0;}; x;")
SET !EXTRACT NULL
TAG POS=1 TYPE=A ATTR=TXT:*Text to search if results are present* EXTRACT=TXT
SET !VAR2 EVAL("var s='{{!EXTRACT}}'; var x; if(s!='#EANF#'){x="Click if search is successful";} else{x="Click if search fail";}; x;")
TAG POS={{!VAR1}} TYPE=A ATTR=TXT:{{!VAR2}}

This let you choose to click a specific button if the button is present, but also if there's a specific text is in the page, like when you do search, but you find only few results, and want to check if the search give you a result you are searching actively and not just a result for similar names. If this can run anyway, for me will be true gold on some sites.
Windows 10, iMacro for firefox v. 8.9.7, first time ready to use iMacro seriously.
Already checked the WIKI and if I ask I'm already done with tries.

Sorry for the bad English, but then google does not help much with translations... :P
Guest0034
 
Posts: 29
Joined: Wed Sep 14, 2016 7:46 am

Re: Javascript functions inside EVAL (tricks for search and

by chivracq on Thu Dec 22, 2016 6:08 pm

Guest0034 wrote:Edited the title for give few hints about content of topic.
As wanted by me this one can address people to few sources and commands for EVAL best use.
Thanks again.
Your help has been very precious on this.
And I hope your posts can help someone other when searching for functions and hints about EVAL. ;) :D
[No need to answer until you have a better title to propose. Actually, for me at least, this is a starred topic in my google chrome online account an, just for precaution, to firefox online account too. :D
Better avoid to lose it for a virus or an accidental damage to my PC. :P]

"starred topic in my google chrome account", hum, you can bookmark Threads at the bottom of every Threads, and/or you can always find back your own Threads from your Profile on the Forum... With 26 Posts in total for the moment in about 5 different Threads, it shouldn't be too difficult for you to locate any of your Threads/Posts later...
I have about 5000 Posts on the Forum in maybe 2000 Threads, then yep, looking for specific Post from myself can sometimes be a bit of a "Challenge" indeed, but you are still far from that stage, ah-ah...! (And I have about 40 Threads bookmarked, either that I refer to them regularly or that they contain some interesting Content for me, even if hum..., many have some fairly useless (=non-descriptive) Thread Title which makes that I usually locate them back quicker from searching the Forum rather than having to completely read again 20 or 30 Threads with some useless Title that I don't know anymore why I bookmarked them and which one is the one I am looking for...

Guest0034 wrote:An idea based on the same reasoning.
You can set the script to push a text instead of another if a specific text is present?
I've thought on something about this and want to know if it's a good idea or a trashing one instead.
Code: Select all
SET !ERRORIGNORE YES
...
SET !EXTRACT NULL
TAG POS=1 TYPE=A ATTR=TXT:*Text to search* EXTRACT=TXT
SET !VAR1 EVAL("var s='{{!EXTRACT}}'; var x; if(s!='#EANF#'){x="Click if search is successful";} else{x="Click if search fail";}; x;")
TAG POS=1 TYPE=A ATTR=TXT:{{!VAR1}}
...

And do you think that both EVAL can be applied, obviously to different VAR, to a single function?
Something like:

Code: Select all
SET !EXTRACT NULL
TAG POS=1 TYPE=A ATTR=TXT:*Check if button is present* EXTRACT=TXT
SET !VAR1 EVAL("var s='{{!EXTRACT}}'; var x; if(s!='#EANF#'){x=1;} else{x=0;}; x;")
SET !EXTRACT NULL
TAG POS=1 TYPE=A ATTR=TXT:*Text to search if results are present* EXTRACT=TXT
SET !VAR2 EVAL("var s='{{!EXTRACT}}'; var x; if(s!='#EANF#'){x="Click if search is successful";} else{x="Click if search fail";}; x;")
TAG POS={{!VAR1}} TYPE=A ATTR=TXT:{{!VAR2}}

This let you choose to click a specific button if the button is present, but also if there's a specific text is in the page, like when you do search, but you find only few results, and want to check if the search give you a result you are searching actively and not just a result for similar names. If this can run anyway, for me will be true gold on some sites.

Yeah, maybe possible, I saw once sbd using or trying to use some Array as a Var, but hum..., not very practical in my Opinion..., or at least in your Case...:
You use '!VAR1' and '!VAR2' for your Vars but "good Practice" is to give "real" Names to your Vars like in your Example 'BTN_Present' for '!VAR1' and 'Search_Result' for '!VAR2' for example... And maybe '!VAR1' and '!VAR2' are OK for your short Macro which is one of your 5 Macros in total maybe, but you cannot really keep using '!VARn' (= x10) in 5000+ Lines long Macros like mine, you quickly get mixed up with '!VARn' as you only have 10 possibilities for 'n'.
And you would need to store the 2 Extracts into 2 Temp Vars, or at least the first one, or you need to handle yourself the "split-back" of '!EXTRACT' in your 'EVAL' which renders your 'EVAL()' Statement much longer (won't fit on one Screen, will require some horizontal Scrolling just to have a look at a Statement) and much more complicated to follow for yourself in a few weeks or months if you ever need to change anything before you understand first what you did last time...
- (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...
chivracq
 
Posts: 6307
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)

Re: Javascript functions inside EVAL (tricks for search and

by Guest0034 on Thu Dec 22, 2016 6:19 pm

Obviously this is a sample.
On my running programs I'm going to put variable names that are linked to the use I'm doing in the site.
As example it is totally indicative of what they are, VARiables.
Using different names can be a bit confusing for peoples that are not using them if they dont know about the flow of program.

About the adding them to favorites, it is a useful thing to do because you can change names easily to your bookmark and make the link clear on why you have added them.
And, if you are logged out, it is faster click on the link than open home page of the forum, logging in and then search in your posts where the one you're looking for is, if the title is a bit confusing.
That's why I use often bookmarking useful topics outside the forum for have them at hand. ;D
Windows 10, iMacro for firefox v. 8.9.7, first time ready to use iMacro seriously.
Already checked the WIKI and if I ask I'm already done with tries.

Sorry for the bad English, but then google does not help much with translations... :P
Guest0034
 
Posts: 29
Joined: Wed Sep 14, 2016 7:46 am

Re: Javascript functions inside EVAL (tricks for search and

by Guest0034 on Sat May 27, 2017 7:39 am

I try reuse this topic, because it is a clarification of how use js commands inside EVAL.
I want find a way to compare 2 parts of a single span tag, but I have to "decompose" the EXTRACTed text in 2 variables.
The way it's built is "Entry A-B of C total entries".
Basically I need to extract B and C, then compare them for check if there is a good reason to click the "NEXT" button. If I'm in the last page, the "NEXT" button send it in the last page again and I want use a command that, when you reach the last page and operate it, you have to click the "FIRST" button.
The configuration is the usual of a GOOGLE standard page with this exception. I already know how operate the single buttons, but I are unable to calculate how operate the text for extract the numbers B and C for use them in simple eval statement, but the problem is how do it properly having variable text length. The script can go on a over 1000 results, so I cannot set a "CharAt" fixed setting, even if, with a long text, it will make a decent job.
The best way to obtain it is to select the characters backward and I've tried to use a length command for set a -1 step on the loop if-then, but it's hard to use a statement that work effectively.
Assuming a TAG command that extract the text "Listed X-Y entries of W total entries" I have wrote a SET command that assign a value inside an EVAL statement.
The basic idea is (wrote inside an eval, but wrote here like a working program for let better reading and comment for understand why doing each command):

Code: Select all
"var x;
var Os; 'Original string copy
var OsT; 'Original string edited for process extraction
var L; 'Length extact
var Ch; 'Step Character for extraction
var St; 'Step character in work now
var Out1; 'extraction of data first value
set Os=!extract; 'make Os an exact copy of !extract
Set OsT=Os-" total entries"; 'Remove extra text from the original one. this text is always the same and at the end of !extract
set L=OsT.length; 'Extract lengt of edited !extract
for(Ch = L; Ch > 0; Ch-1){                           'this is the loop function for extracting last text
ST=OsT.CharAt(Ch);                                   'character extraction
if ST=\" \" then ch=0 else Out1=St+Out1;        'check character, if a space, end of loop, else save character as first of Out1 variable
};
x=Out1;
x;"


End of first extraction process, on the second, same as before except last 2 rows and then add this rows:

'at the end, remove the next fixed text and the extracted Out1 value from the last OsT for start 2nd variable extraction
Code: Select all
Var Out2
set OsT=Ost-" of "-Out1
set L=OsT.length;
for(Ch = L; Ch > 0; Ch-1){
ST=OsT.CharAt(Ch);
if ST=\" \" then ch=0 else Out2=St+Out2}
x=Out2;
x;"


For me it seems ok, but it wont work...

If you think this is not a same "question kind" I will delete the post and the create a new topic, but for me it is almost the same, so how build a correct js function inside EVAL...
Windows 10, iMacro for firefox v. 8.9.7, first time ready to use iMacro seriously.
Already checked the WIKI and if I ask I'm already done with tries.

Sorry for the bad English, but then google does not help much with translations... :P
Guest0034
 
Posts: 29
Joined: Wed Sep 14, 2016 7:46 am

Re: Javascript functions inside EVAL (tricks for search and

by chivracq on Sat May 27, 2017 10:42 am

Guest0034 wrote:I try reuse this topic, because it is a clarification of how use js commands inside EVAL.
I want find a way to compare 2 parts of a single span tag, but I have to "decompose" the EXTRACTed text in 2 variables.
The way it's built is "Entry A-B of C total entries".
Basically I need to extract B and C, then compare them for check if there is a good reason to click the "NEXT" button. If I'm in the last page, the "NEXT" button send it in the last page again and I want use a command that, when you reach the last page and operate it, you have to click the "FIRST" button.
The configuration is the usual of a GOOGLE standard page with this exception. I already know how operate the single buttons, but I are unable to calculate how operate the text for extract the numbers B and C for use them in simple eval statement, but the problem is how do it properly having variable text length. The script can go on a over 1000 results, so I cannot set a "CharAt" fixed setting, even if, with a long text, it will make a decent job.
The best way to obtain it is to select the characters backward and I've tried to use a length command for set a -1 step on the loop if-then, but it's hard to use a statement that work effectively.
Assuming a TAG command that extract the text "Listed X-Y entries of W total entries" I have wrote a SET command that assign a value inside an EVAL statement.
The basic idea is (wrote inside an eval, but wrote here like a working program for let better reading and comment for understand why doing each command):

Code: Select all
"var x;
var Os; 'Original string copy
var OsT; 'Original string edited for process extraction
var L; 'Length extact
var Ch; 'Step Character for extraction
var St; 'Step character in work now
var Out1; 'extraction of data first value
set Os=!extract; 'make Os an exact copy of !extract
Set OsT=Os-" total entries"; 'Remove extra text from the original one. this text is always the same and at the end of !extract
set L=OsT.length; 'Extract lengt of edited !extract
for(Ch = L; Ch > 0; Ch-1){                           'this is the loop function for extracting last text
ST=OsT.CharAt(Ch);                                   'character extraction
if ST=\" \" then ch=0 else Out1=St+Out1;        'check character, if a space, end of loop, else save character as first of Out1 variable
};
x=Out1;
x;"


End of first extraction process, on the second, same as before except last 2 rows and then add this rows:

'at the end, remove the next fixed text and the extracted Out1 value from the last OsT for start 2nd variable extraction
Code: Select all
Var Out2
set OsT=Ost-" of "-Out1
set L=OsT.length;
for(Ch = L; Ch > 0; Ch-1){
ST=OsT.CharAt(Ch);
if ST=\" \" then ch=0 else Out2=St+Out2}
x=Out2;
x;"


For me it seems ok, but it wont work...

If you think this is not a same "question kind" I will delete the post and the create a new topic, but for me it is almost the same, so how build a correct js function inside EVAL...

Hum..., nice to see you again on the Forum, ah-ah...!

But OK, isolating your 'B' + 'C' Content from your "Entry A-B of C total entries" can be done fairly easily like this:
Code: Select all
SET My_Extract "Entry A-B of C total entries"
SET Entry_B EVAL("var s='{{My_Extract}}'; var x,y,z; x=s.split('-'); z=x[1].split(' '); z[0];")
SET Entry_C EVAL("var s='{{My_Extract}}'; var x,y,z; x=s.split('-'); z=x[1].split(' '); z[2];")
PROMPT My_Extract:<SP>_{{My_Extract}}_<BR><BR>Entry_B:<SP>_{{Entry_B}}_<BR>Entry_C:<SP>_{{Entry_C}}_
(Tested on iMacros for FF v8.8.2, Pale Moon v26.3.3 (=FF47), Win10-x64.)
- (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...
chivracq
 
Posts: 6307
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)

Next

Return to iMacros for Firefox

Who is online

Users browsing this forum: babarali124, Bing [Bot], Google [Bot] and 5 guests

-->