Skip to content

Instantly share code, notes, and snippets.

@tyhallcsu
Created April 28, 2024 12:57
Show Gist options
  • Save tyhallcsu/6234e3a236f4fb875c4af99577c813e6 to your computer and use it in GitHub Desktop.
Save tyhallcsu/6234e3a236f4fb875c4af99577c813e6 to your computer and use it in GitHub Desktop.
Automatically clean and redirect from tracking URLs in Reddit mail links.
// ==UserScript==
// @name Reddit Mail Redirect Cleaner
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Automatically clean and redirect from tracking URLs in Reddit mail links.
// @author sharmanhall
// @match *://*/*
// @grant none
// @icon https://www.google.com/s2/favicons?sz=64&domain=reddit.com
// @run-at document-end
// @license MIT
// @downloadURL https://update.greasyfork.org/scripts/493675/Reddit%20Mail%20Redirect%20Cleaner.user.js
// @updateURL https://update.greasyfork.org/scripts/493675/Reddit%20Mail%20Redirect%20Cleaner.meta.js
// ==/UserScript==
//
// GreasyFork URL: https://greasyfork.org/en/scripts/493675-reddit-mail-redirect-cleaner
(function() {
'use strict';
// Listen for click events on the entire document
document.addEventListener('click', function(e) {
// Check if the clicked element is a link that includes "click.redditmail.com"
var target = e.target.closest('a[href*="click.redditmail.com"]');
if (target) {
// Prevent the default link behavior
e.preventDefault();
// Decode the URL and extract the direct Reddit link
const url = new URL(decodeURIComponent(target.href));
const redditURLMatch = url.href.match(/https:\/\/www\.reddit\.com\/message\/messages\/[a-zA-Z0-9]+/);
if (redditURLMatch) {
// Redirect to the extracted Reddit URL
window.location.href = redditURLMatch[0];
} else {
// Alert the user if no clean URL is found
alert("Could not find a clean URL to redirect to.");
}
}
}, true);
})();
@tyhallcsu
Copy link
Author

GreasyFork Write-up:

Title: Reddit Mail Redirect Cleaner

Description:
This userscript enhances your browsing experience by automatically cleaning and redirecting from tracking URLs found in Reddit mail links. When clicking on a Reddit mail link that routes through click.redditmail.com, this script intercepts the link, removes tracking parameters, and directly navigates to the intended Reddit message. This not only speeds up your access but also protects your privacy by avoiding unnecessary tracking.

Features:

  • Auto-Redirect: Bypasses the tracking redirect to immediately open the intended Reddit message.
  • Enhanced Privacy: Reduces exposure to tracking URLs.
  • Ease of Use: Works seamlessly in the background; no manual intervention required.

Installation:

  1. Ensure you have Tampermonkey installed in your browser.
  2. Add the script to Tampermonkey.
  3. Enjoy browsing Reddit mails without redirects!

This script is particularly useful for Reddit users who frequently check private messages and want to avoid the clutter of tracking URLs. It's designed to work silently in the background, providing a cleaner and faster browsing experience.

License: MIT

GreasyFork: https://greasyfork.org/en/scripts/493675-reddit-mail-redirect-cleaner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment