Reddit to Redlib

Converts Reddit links to Redlib (previously Libreddit) links, and replaces old url in browser history. Also works in Firefox Android.

  1. // ==UserScript==
  2. // @name Reddit to Redlib
  3. // @namespace happyviking
  4. // @version 1.1
  5. // @description Converts Reddit links to Redlib (previously Libreddit) links, and replaces old url in browser history. Also works in Firefox Android.
  6. // @author HappyViking
  7. // @match *://*.reddit.com/*
  8. // @exclude *://*.reddit.com/media*
  9. // @icon https://www.google.com/s2/favicons?domain=www.reddit.com
  10. // @grant none
  11. // @run-at document-start
  12. // @license MIT
  13. // ==/UserScript==
  14.  
  15.  
  16. // Heavy credit to:
  17. // https://greasyfork.org/en/scripts/432711-libreddit-converter/code
  18. // https://greasyfork.org/en/scripts/465089-libreddit-redirector/code
  19.  
  20.  
  21. function isProperTargetPage(url) {
  22. return !!url.match(/^(|http(s?):\/\/)(.*\.)?reddit.com(\/.*|$)/gim);
  23. }
  24.  
  25. function getNewUrl(url) {
  26. return 'https://farside.link/redlib' + url.split('reddit.com').pop();
  27. }
  28.  
  29. if (isProperTargetPage(window.location.href)) {
  30. const newUrl = getNewUrl(window.location.href)
  31. location.replace(newUrl);
  32. }