Hot Summer Deals are Here!
Celebrate with up to 99% off on 17,900 resources
00
Days
06
Hours
13
Mins
08
Secs

Wanting a custom Chrome / Firefox extension

PebbleHost
High performance, consistent uptime and fast support. Minecraft hosting that just works.

Evolve

Crypto Exchanger
Supreme
Feedback score
19
Posts
499
Reactions
139
Resources
0
Hey,
I am wanting a custom firefox / chrome extension that when you type subreddit in the URL bar it auto takes you to the sub.
For example if I type r/memes in the URL bar it'll take me to https://reddit.com/r/memes

Thanks,

Verstappen
Sure, it's possible to create a custom Chrome extension that redirects you to a subreddit when you type it in the URL bar. Here's one way you could do it:

  1. Create a new directory for your extension, and within it create a file called "manifest.json" with the following contents:

    JSON:
    {
      "manifest_version": 2,
      "name": "Subreddit redirector",
      "version": "1.0",
      "background": {
        "scripts": ["background.js"]
      },
      "permissions": [
        "activeTab"
      ],
      "chrome_url_overrides": {
        "newtab": "newtab.html"
      }
    }


    2. In the same directory, create a file called "background.js" with the following contents:


    JavaScript:
    chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
      if (changeInfo.url) {
        var regex = /^https?:\/\/(www.)?reddit.com\/r\/([^\/]+)/;
        var match = changeInfo.url.match(regex);
        if (match) {
          var subreddit = match[2];
          chrome.tabs.update(tabId, {url: "https://reddit.com/r/" + subreddit});
        }
      }
    });

    3. Finally, create a file called "newtab.html" with the following contents:


    HTML:
    <!DOCTYPE html>
    <html>
      <head>
        <title>New Tab</title>
      </head>
      <body>
        <h1>Welcome to your new tab!</h1>
        <p>Type a subreddit name in the URL bar to go to that subreddit (e.g. "r/memes")</p>
      </body>
    </html>

    To use your extension, go to chrome://extensions in your Chrome browser, enable "Developer mode" in the top right, and then click "Load unpacked" and select the directory you created for your extension. Now, when you type a subreddit name in the URL bar, it should automatically redirect you to that subreddit.
 
Top