burhan-syed / troddit

A web client for Reddit with authenticated logins and a variety of browsing options
https://www.troddit.com
GNU Affero General Public License v3.0
554 stars 82 forks source link

(Feature Request) Convert reddit url to troddit url automatically #120

Closed dnet890 closed 1 year ago

dnet890 commented 1 year ago

Hi if we google search reddit url, it will be really wonderful if this url automatically changed to troddit URL like wikiwand with their browser extension and it is also beneficial to promote this project further. What do you think?

LewsTherinTelescope commented 1 year ago

Here's a quick userscript that does that:

// ==UserScript==
// @name        Redirect Reddit Links to Troddit
// @namespace   Reddit Scripts
// @description Attempts to redirect all clicks on Reddit URLs to Troddit.
//              Known bug: Fails if navigation is done with JS instead of pure HTML (ie New Reddit feed).
// @match       <all_urls>
// @version     1.0
// @grant       none
// ==/UserScript==

document.body.addEventListener('click', e => {
  // in case target is a tag inside a link, ie DDG results are `span`s inside `a`s
  const tag = e.target.closest('a');
  const reddit = /https?:\/\/(\w+\.)?reddit\.com\//;
  const troddit = 'https://troddit.com/';
  if (tag?.href?.match(reddit)) {
    tag.href = tag.href.replace(reddit, troddit);
  }
});

Not sure if there's a better way or not, but this is simple at least.

r7l commented 1 year ago

You could use Libreddirect extension for it. Also supports other sites like Twitter, Youtube and more.

burhan-syed commented 1 year ago

Adding https://www.troddit.com as a reddit instance in the Libreddirect extension works so no need for a custom extension.