X
Tap here to go to the mobile version of the site.

Support Forum

Using if-then statements in smart keywords

Posted

Hello, I'm not really sure if this is possible, but it'd be nice. I use smart keywords to go to different subreddits, so for example searching for "r askreddit" goes to reddit.com/r/AskReddit. The issue I have is that if I want to go to the front page, I can't just search for "r", as that goes to http://reddit.com/r/ which then redirects to reddit.com/subreddits.

So what I'd want is to have an if-then statement - if there is no other argument following the "r", it should go to reddit.com. This works with Google Maps and YouTube without needing to do anything /Google handles empty search differently than reddit I suppose/.

Is this possible?

Hello, I'm not really sure if this is possible, but it'd be nice. I use smart keywords to go to different subreddits, so for example searching for "r askreddit" goes to reddit.com/r/AskReddit. The issue I have is that if I want to go to the front page, I can't just search for "r", as that goes to http://reddit.com/r/ which then redirects to reddit.com/subreddits. So what I'd want is to have an if-then statement - if there is no other argument following the "r", it should go to reddit.com. This works with Google Maps and YouTube without needing to do anything /Google handles empty search differently than reddit I suppose/. Is this possible?

Chosen solution

You would need a JavaScript bookmarklet that checks the '%s' placeholder to achieve this.

javascript:void(location.href=('%s'=='')?'https://reddit.com/':'https://reddit.com/r/%s');
Read this answer in context 1
Quote

Additional System Details

Application

  • User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:69.0) Gecko/20100101 Firefox/69.0

More Information

cor-el
  • Top 10 Contributor
  • Moderator
17567 solutions 158896 answers

Chosen Solution

You would need a JavaScript bookmarklet that checks the '%s' placeholder to achieve this.

javascript:void(location.href=('%s'=='')?'https://reddit.com/':'https://reddit.com/r/%s');
You would need a JavaScript bookmarklet that checks the '%s' placeholder to achieve this. <pre><nowiki>javascript:void(location.href=('%s'=='')?'https://reddit.com/':'https://reddit.com/r/%s');</nowiki></pre>

Modified by cor-el

Was this helpful to you? 1
Quote

Question owner

Thank you, I didn't know I can just place JavaScript into the url bar.

Thank you, I didn't know I can just place JavaScript into the url bar.
Was this helpful to you?
Quote
Ask a question

You must log in to your account to reply to posts. Please start a new question, if you do not have an account yet.