Reddit Mail Redirect Cleaner

Automatically clean and redirect from tracking URLs in Reddit mail links.

当前为 2024-04-28 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Reddit Mail Redirect Cleaner
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description Automatically clean and redirect from tracking URLs in Reddit mail links.
  6. // @author sharmanhall
  7. // @match *://*/*
  8. // @grant none
  9. // @icon https://www.google.com/s2/favicons?sz=64&domain=reddit.com
  10. // @run-at document-end
  11. // @license MIT
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. // Listen for click events on the entire document
  18. document.addEventListener('click', function(e) {
  19. // Check if the clicked element is a link that includes "click.redditmail.com"
  20. var target = e.target.closest('a[href*="click.redditmail.com"]');
  21. if (target) {
  22. // Prevent the default link behavior
  23. e.preventDefault();
  24. // Decode the URL and extract the direct Reddit link
  25. const url = new URL(decodeURIComponent(target.href));
  26. const redditURLMatch = url.href.match(/https:\/\/www\.reddit\.com\/message\/messages\/[a-zA-Z0-9]+/);
  27. if (redditURLMatch) {
  28. // Redirect to the extracted Reddit URL
  29. window.location.href = redditURLMatch[0];
  30. } else {
  31. // Alert the user if no clean URL is found
  32. alert("Could not find a clean URL to redirect to.");
  33. }
  34. }
  35. }, true);
  36. })();