1.9 - hopefully this is the last one

This commit is contained in:
Sebastian Cabrera 2024-07-09 06:38:43 -04:00
parent 5ad23deee2
commit f7b29d3b82
No known key found for this signature in database
GPG key ID: 9C70960A46161D08

View file

@ -1,7 +1,7 @@
// ==UserScript== // ==UserScript==
// @name Use old new Reddit // @name Use old new Reddit
// @namespace https://codeberg.org/okseby/newnewredditsucks // @namespace https://codeberg.org/okseby/newnewredditsucks
// @version 1.8 // @version 1.9
// @description forward the ugly new reddit to the older new reddit // @description forward the ugly new reddit to the older new reddit
// @author okseby // @author okseby
// @match https://www.reddit.com/* // @match https://www.reddit.com/*
@ -15,16 +15,31 @@
(function () { (function () {
'use strict'; 'use strict';
// Get the current URL function redirectIfNecessary(url) {
const currentUrl = window.location.href;
// Check if it's a media link
const mediaPattern = /\/media($|\?)/; const mediaPattern = /\/media($|\?)/;
if (mediaPattern.test(currentUrl)) return; // Abort the redirect if (mediaPattern.test(url)) {
return; // Abort the redirect
// Replace www.reddit.com with new.reddit.com }
const newUrl = currentUrl.replace('www.reddit.com', 'new.reddit.com'); const newUrl = url.replace('www.reddit.com', 'new.reddit.com');
if (newUrl !== url) {
// Redirect to the new URL
window.location.replace(newUrl); 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);
}
});
})(); })();