summaryrefslogtreecommitdiff
path: root/.config/qutebrowser/greasemonkey/reddit.js
blob: 8ed3ebb5efdaece4394b508745a3a7839432658e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// ==UserScript==
// @name Old Reddit Redirect
// @version      0.1.1
// @description  redirects you to old.reddit.com
// @author       github.com/richkmls
// @match *://*.reddit.com/*
// @exclude /^https?://[a-z]{2}\.reddit\.com/*
// @exclude *out.reddit.com/*
// @exclude *://*.reddit.com/gallery/*
// @exclude *://*.reddit.com/media*
// @run-at document-start
// @grant        none
// ==/UserScript==

// Enforce strict mode for better code quality
'use strict';

// Declare constant for current URL
const currentUrl = window.location.href;

// Declare constant for old reddit URL
const oldRedditUrl = 'https://old.reddit.com/';

// Check if the current URL does not include old.reddit.com
if (!currentUrl.includes("old.reddit.com")) {

  // Use regex literal and constant for new URL
  const newUrl = currentUrl.replace(/^https?:\/\/(www\.)?reddit.com\//, oldRedditUrl);

  // Redirect to new URL without history entry
  window.location.replace(newUrl);
}