Page 1 of 1

Using SET !VAR1 EVAL with javascript iMacros

Posted: Thu Nov 30, 2017 2:04 am
by jinjinda
I have a .js iMacros file for go to url, it looks like this:

Code: Select all
for ( var k = 0; k<3; k++){
var congdong;
congdong =  "CODE:";
congdong +=  "VERSION BUILD=8970419 RECORDER=FX" + "\n";
congdong +=  "SET !ERRORIGNORE YES" + "\n";
congdong +=  "SET !VAR1 EVAL(\"var letters = ['link1','link2','link3','link4','link5','link6','link7','link8']; var  results = []; for (var i = 0; i < 3; i++) {var pos = parseInt(Math.random()  * (letters.length - 1));results.push(letters[pos]);letters.splice(pos, 1);} results[i];\")" + "\n";
congdong +=  "TAB T=1" + "\n";
congdong +=  "URL GOTO={{!VAR1}}" + "\n";
iimPlay(congdong)
}


My goal is for it to run 3 times each time going to 1 different url. But when I let it run it does not go to any urls and does not report errors. Any ideas on how I could get this working?

Thanks so much!

Re: Using SET !VAR1 EVAL with javascript iMacros

Posted: Thu Nov 30, 2017 12:13 pm
by chivracq
jinjinda wrote:I have a .js iMacros file for go to url, it looks like this:

Code: Select all
for ( var k = 0; k<3; k++){
var congdong;
congdong =  "CODE:";
congdong +=  "VERSION BUILD=8970419 RECORDER=FX" + "\n";
congdong +=  "SET !ERRORIGNORE YES" + "\n";
congdong +=  "SET !VAR1 EVAL(\"var letters = ['link1','link2','link3','link4','link5','link6','link7','link8']; var  results = []; for (var i = 0; i < 3; i++) {var pos = parseInt(Math.random()  * (letters.length - 1));results.push(letters[pos]);letters.splice(pos, 1);} results[i];\")" + "\n";
congdong +=  "TAB T=1" + "\n";
congdong +=  "URL GOTO={{!VAR1}}" + "\n";
iimPlay(congdong)
}


My goal is for it to run 3 times each time going to 1 different url. But when I let it run it does not go to any urls and does not report errors. Any ideas on how I could get this working?

Thanks so much!

FCIM...! :mrgreen: (Read my Sig...)
=> iMacros for FF v8.9.7...?, FF55/56...?, OS...?

Ouf-ouf-ouf...!, what a complicated "Solution" you have in your 'EVAL()' Statement...! If you created yourself, you should be able to find "a" (much easier!) Solution by yourself, I would think..., like simply using your Random Nb for the Index 'n' on your 'letters[n]' Array... :idea:

Re: Using SET !VAR1 EVAL with javascript iMacros

Posted: Thu Nov 30, 2017 6:23 pm
by jinjinda
chivracq wrote:
jinjinda wrote:I have a .js iMacros file for go to url, it looks like this:

Code: Select all
for ( var k = 0; k<3; k++){
var congdong;
congdong =  "CODE:";
congdong +=  "VERSION BUILD=8970419 RECORDER=FX" + "\n";
congdong +=  "SET !ERRORIGNORE YES" + "\n";
congdong +=  "SET !VAR1 EVAL(\"var letters = ['link1','link2','link3','link4','link5','link6','link7','link8']; var  results = []; for (var i = 0; i < 3; i++) {var pos = parseInt(Math.random()  * (letters.length - 1));results.push(letters[pos]);letters.splice(pos, 1);} results[i];\")" + "\n";
congdong +=  "TAB T=1" + "\n";
congdong +=  "URL GOTO={{!VAR1}}" + "\n";
iimPlay(congdong)
}


My goal is for it to run 3 times each time going to 1 different url. But when I let it run it does not go to any urls and does not report errors. Any ideas on how I could get this working?

Thanks so much!

FCIM...! :mrgreen: (Read my Sig...)
=> iMacros for FF v8.9.7...?, FF55/56...?, OS...?

Ouf-ouf-ouf...!, what a complicated "Solution" you have in your 'EVAL()' Statement...! If you created yourself, you should be able to find "a" (much easier!) Solution by yourself, I would think..., like simply using your Random Nb for the Index 'n' on your 'letters[n]' Array... :idea:

yes sorry.
FF 30.0 iMacros 8.9.7 OS win 7 64bit

Re: Using SET !VAR1 EVAL with javascript iMacros

Posted: Thu Nov 30, 2017 10:06 pm
by chivracq
jinjinda wrote:yes sorry.
Code: Select all
FF 30.0  iMacros 8.9.7  OS win 7 64bit

OK for your FCI...
Hum, a bit strange btw, FF30...!?, hum OK, yep possible, v8.8.8 until FF29 and v8.9.x from FF30 indeed, so yep I guess v8.9.7 should work on FF30...
But any Reason why you staid at FF30...? :?
v8.9.7 still works perfectly until at least FF v55.0.3 (FF Version I use myself with v8.9.7 for FF)...

But otherwise, any Reaction on the "Content" of your Thread and my Suggestion/Solution about your 'letters[n]'...!?

Ah but OK, ah-ah...!, I see you opened a parallel Thread on SOF, OK, no Pb..., my Sol is actually the same like the one from @Shugar, ah-ah...!, the one from @Naren Murali might work but hum, it looks to me as complicated as your original post...

Hum, I see some " thanks you so much. I solved my problem – Jinjin Da 26 mins ago " from you, you would need to accept one of the 2 Sols and/or share your own Sol on SOF to finish that Thread correctly on SOF, and to do the same here on our Forum by sharing "your" Sol and posting your Final Script... :idea:

Re: Using SET !VAR1 EVAL with javascript iMacros

Posted: Thu Nov 30, 2017 11:35 pm
by jinjinda
Yes, this my code running
Code: Select all
var linkcd= [
  'link1',
  'link2',
  'link3',
  'link4',
  'link5',
  'link6',
  'link7'
];
var resultscd = [];
for (var k = 0; k < 6; k++) {
  var pos = parseInt(Math.random() * (linkcd.length - 1));
  resultscd.push(linkcd[pos]);
  linkcd.splice(pos, 1);
}

for (var k = 0; k < 3; k++) {
var congdong;
congdong =  "CODE:";
congdong +=  "VERSION BUILD=8970419 RECORDER=FX" + "\n";
congdong +=  "SET !ERRORIGNORE YES" + "\n";
congdong +=  "SET !VAR1 \"" + resultscd[k] + "\"\n";
congdong +=  "TAB T=1" + "\n";
congdong +=  "URL GOTO={{!VAR1}}" + "\n";
iimPlay(congdong)

Re: Using SET !VAR1 EVAL with javascript iMacros

Posted: Fri Dec 01, 2017 12:45 pm
by chivracq
jinjinda wrote:Yes, this my code running
Code: Select all
var linkcd= [
  'link1',
  'link2',
  'link3',
  'link4',
  'link5',
  'link6',
  'link7'
];
var resultscd = [];
for (var k = 0; k < 6; k++) {
  var pos = parseInt(Math.random() * (linkcd.length - 1));
  resultscd.push(linkcd[pos]);
  linkcd.splice(pos, 1);
}

for (var k = 0; k < 3; k++) {
var congdong;
congdong =  "CODE:";
congdong +=  "VERSION BUILD=8970419 RECORDER=FX" + "\n";
congdong +=  "SET !ERRORIGNORE YES" + "\n";
congdong +=  "SET !VAR1 \"" + resultscd[k] + "\"\n";
congdong +=  "TAB T=1" + "\n";
congdong +=  "URL GOTO={{!VAR1}}" + "\n";
iimPlay(congdong)

OK, good...!, Thanks for sharing, on our Forum and on SOF... :D

I still find it a bit cumbersome, @Shugar's and my Solution was much simpler I would think, the 'push()' and 'splice()' are probably not needed, even if it's a nice "Exercise", ah-ah...!, as those 2 Commands are not often used, but I guess if your Script works, then you're already happy... :wink:

There was no real "Need" from your original Script to use a '.js' Script, but you went for a "full" '.js' Solution, meaning your Script will only work in FF, while handling your Requirement directly from the 'EVAL()' like @Shugar and myself suggested would have allowed your Script to work in all 4 Browsers supported by iMacros... But fair enough...! 8)