Created
March 21, 2024 02:13
-
-
Save sammcj/6a9bfd710449243b8c488671fa5bf1b1 to your computer and use it in GitHub Desktop.
clean_redditmail_links.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Clean Reddit Links | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description Remove click.redditmail.com from Reddit links | |
// @author You | |
// @match *://*.reddit.com/* | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
function cleanRedditLink(link) { | |
const url = new URL(link); | |
const path = url.pathname.replace(/^\/CL\d+\//, '/'); | |
const cleanedUrl = new URL(path, window.location.origin); | |
return cleanedUrl.href; | |
} | |
function cleanupLinks() { | |
const links = document.querySelectorAll('a[href*="click.redditmail.com"]'); | |
links.forEach(link => { | |
const cleanedLink = cleanRedditLink(link.href); | |
link.href = cleanedLink; | |
}); | |
} | |
cleanupLinks(); | |
const observer = new MutationObserver(cleanupLinks); | |
observer.observe(document.documentElement, { | |
childList: true, | |
subtree: true | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment