pauloswear wrote: ↑Thu May 21, 2020 4:22 am
Ok, i was trying to learn some JS and imacros.. I was thinking in split the last part of url and put this in a matrix..
i did this function, and this worked, but i still dont know how to implement this on imacros
Code: Select all
function getUrl() {
var link = window.location.href.slice(0, -1)
link = link.split('/')
var user = link.pop() || link.pop();
var urlfinal = 'www.url.com' + "/" + user
console.log(urlfinal);
return urlfinal;
}
I am still trying to get a progress...
edit:
still thinking in something like this
Code: Select all
SET !VAR3 EVAL("'www.url.com' + '/'+window.location.href.slice().split('/').pop()")
Alright, you are indeed making some Progress...
The Function taken from SOF is a bit Overkill but your 'EVAL()' is getting very close...!
A few Remarks:
1- The 'window.location.href' is pure JS, and that would/will work in pure JS or from iMacros in a '.js' Script (not supported anymore in v10.0.2 for FF, '.js' Scripts are only supported until v9.0.3 for FF) or with the 'URL GOTO=javascript' Syntax, but passing Vars back from 'URL GOTO=javascript' to the '.iim' Script is a bit cumbersome and not very straightforward.
And I'm not sure you can access the DOM from 'EVAL()' and that 'window.location.href' will work in 'EVAL()'. You will probably get some Error that "var "window" is undefined/not referenced"...
But "Luckily" for you, this is what the Built-in Var '!URLCURRENT' that I had already mentioned, does for you, ah-ah...! You don't need to reinvent the Wheel, ah-ah...!
2- Then OK, to isolate the "user" Data/String from the first URL, you go for 'split()' as the "main" Mechanism, good-good..., like I had mentioned...
... And you combine it with 'pop()' + 'slice()'...
Hum, OK, why not..., I had not thought of this Way, I find it a little bit cumbersome in this Case, (as 'split()' alone would already get the Result), but it's not a "bad Idea"..., especially using 'pop()' that will return the last Item of the Array returned by the 'split()'.
And you indeed then need the "slice(0,-1)" like in the Function, to first remove the last "/" after the "user" in the URL.
=> The "slice()" without Argument(s) that you use in your 'EVAL()' does nothing, you do need the 2 Args like in your Function to remove the final "/", otherwise, the "pop()" will return an Empty String as the URL ends on a "/" which is the Char you split the URL/String on...
Alright, keep up the "good Work", you are getting very close...!
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE'/'Trial').
- FCI not mentioned: I don't even read the Qt...! (or only to catch Spam!)
- Script & URL help a lot for more "educated" Help...