-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathredirect-to-old-reddit.user.js
36 lines (32 loc) · 1.48 KB
/
redirect-to-old-reddit.user.js
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
33
34
35
36
// ==UserScript==
// @name Goto Old Reddit
// @namespace https://github.com/abstraction/userscripts
// @description Old Reddit but a bit more pleasing.
// @author abstraction
// @version 2024-07-02
// @match https://www.reddit.com/*
// @exclude https://*.reddit.com/poll/*
// @exclude https://*.reddit.com/gallery/*
// @exclude https://www.reddit.com/media*
// @exclude https://chat.reddit.com/*
// @exclude https://www.reddit.com/appeal*
// @updateURL https://raw.githubusercontent.com/abstraction/userscripts/master/src/redirect-to-old-reddit.user.js
// @downloadURL https://raw.githubusercontent.com/abstraction/userscripts/master/src/redirect-to-old-reddit.user.js
// @icon https://www.google.com/s2/favicons?sz=64&domain=reddit.com
// @run-at document-start
// ==/UserScript==
const navigateToOldReddit = () => {
if (top.location.hostname !== 'old.reddit.com') {
top.location.hostname = 'old.reddit.com';
}
};
navigateToOldReddit(); // Run immediately to redirect to old Reddit
// Ensures redirection during tab close, refresh, or navigation away
window.addEventListener('beforeunload', navigateToOldReddit);
// If coming from new Reddit, modify the history state
if (document.referrer === 'https://www.reddit.com/') {
history.pushState({}, ''); // Adds a state to the history stack
window.addEventListener('popstate', () => {
history.go(-2); // Navigate back two steps in the history, skipping new Reddit
});
}