You can define there variables outside the preSearch() function:
And add these as arguments in the function instead.
Now you could use the same function like this
Since you're defining the variables before calling the function, are you able to change them.
If you want to change the whole URL and not only these vars, then could you do this
Add only the url arg to the function, and use it like this
You would have to remove this line from the function though