1.9 - hopefully this is the last one
This commit is contained in:
parent
5ad23deee2
commit
f7b29d3b82
1 changed files with 25 additions and 10 deletions
|
@ -1,7 +1,7 @@
|
|||
// ==UserScript==
|
||||
// @name Use old new Reddit
|
||||
// @namespace https://codeberg.org/okseby/newnewredditsucks
|
||||
// @version 1.8
|
||||
// @version 1.9
|
||||
// @description forward the ugly new reddit to the older new reddit
|
||||
// @author okseby
|
||||
// @match https://www.reddit.com/*
|
||||
|
@ -15,16 +15,31 @@
|
|||
(function () {
|
||||
'use strict';
|
||||
|
||||
// Get the current URL
|
||||
const currentUrl = window.location.href;
|
||||
|
||||
// Check if it's a media link
|
||||
function redirectIfNecessary(url) {
|
||||
const mediaPattern = /\/media($|\?)/;
|
||||
if (mediaPattern.test(currentUrl)) return; // Abort the redirect
|
||||
|
||||
// Replace www.reddit.com with new.reddit.com
|
||||
const newUrl = currentUrl.replace('www.reddit.com', 'new.reddit.com');
|
||||
|
||||
// Redirect to the new URL
|
||||
if (mediaPattern.test(url)) {
|
||||
return; // Abort the redirect
|
||||
}
|
||||
const newUrl = url.replace('www.reddit.com', 'new.reddit.com');
|
||||
if (newUrl !== url) {
|
||||
window.location.replace(newUrl);
|
||||
}
|
||||
}
|
||||
|
||||
// Run on initial load
|
||||
redirectIfNecessary(window.location.href);
|
||||
|
||||
// Observe changes in the document to handle dynamic navigation
|
||||
const observer = new MutationObserver(() => {
|
||||
redirectIfNecessary(window.location.href);
|
||||
});
|
||||
|
||||
observer.observe(document.body, { childList: true, subtree: true });
|
||||
|
||||
// Handle click events on links
|
||||
document.addEventListener('click', (event) => {
|
||||
if (event.target.tagName === 'A' && event.target.href) {
|
||||
redirectIfNecessary(event.target.href);
|
||||
}
|
||||
});
|
||||
})();
|
Loading…
Add table
Add a link
Reference in a new issue