Google Search command

so I’ve added added a google command, but it bugs me that every time I attempt to search for something that requires a space to separate between words, the link gets created with only the first word that was added. SO, unless you know to copy the beginning of the https all through the end of what you type, you won’t get the correct answer. I’ve tried quite a few replacements but don’t work but essentially, I want to replace a space for %20 and I keep getting “Unexpected end of input”. Here is some examples of what I’ve tried:

$(eval $(query).replace - Google Search(’ ',/%/2/0))

$(eval $(query).replace - Google Search(’ ',"%20"))

$(eval $(query).replace - Google Search(’ ',"%20"))

$(eval $(querystring).replace - Google Search(’ ',"%20"))

$(eval $(querystring).replace - Google Search(’ ',+))

$(eval $(query).replace - Google Search(’ ',%20))

… and single quotes replaced with double quotes, etc, etc, etc. What am I missing?

Have you considered using $(querystring) ?

I tried, as you can see above, and didn’t work either.

I feel like what I’m missing is not difficult but I’ve also tried so many options that I feel the syntax is incorrect. I just don’t understand where to fix it.

Hey @chykityta!

If you look at a Google’s search URL, you’ll notice that spaces are +.
I made a !google command a while ago, here’s the code:

$(eval q=`$(query)`.replace(` `,`+`);`https://www.google.com/search?q=`+q;)

Wait, I did try replacing with a + sign as well. Can you please explain why yours works and mine doesn’t?

YOURS

MINE

Querystring converts spaces into %20 first, so they wont get replaced by +

and what about the format? What is so different between how you coded it vs. how I coded it?

There’s not much difference between your code and mine, I just use the right tools:

I used $(query) so the spaces don’t get encoded, so I replace them with +.
If I used $(querystring), the spaces are encoded to %20 so I need to replace the encoded characters with +.

After than I simply added a step where I create a variable q, which I could have bypassed, it’s just an habit.

So I could have written the code like this:

$(eval `https://www.google.com/search?q=$(query)`.replace(` `,`+`))
$(eval `https://www.google.com/search?q=$(querystring)`.replace(`%20`,`+`))

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.