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==
|
// ==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;
|
const mediaPattern = /\/media($|\?)/;
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Check if it's a media link
|
// Run on initial load
|
||||||
const mediaPattern = /\/media($|\?)/;
|
redirectIfNecessary(window.location.href);
|
||||||
if (mediaPattern.test(currentUrl)) return; // Abort the redirect
|
|
||||||
|
|
||||||
// Replace www.reddit.com with new.reddit.com
|
// Observe changes in the document to handle dynamic navigation
|
||||||
const newUrl = currentUrl.replace('www.reddit.com', 'new.reddit.com');
|
const observer = new MutationObserver(() => {
|
||||||
|
redirectIfNecessary(window.location.href);
|
||||||
|
});
|
||||||
|
|
||||||
// Redirect to the new URL
|
observer.observe(document.body, { childList: true, subtree: true });
|
||||||
window.location.replace(newUrl);
|
|
||||||
|
// 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