GMX/Mail.com Outgoing URL Decoder

Decodes and rewrites external URLs. Stops URL tracking/analytics

  1. // ==UserScript==
  2. // @name GMX/Mail.com Outgoing URL Decoder
  3. // @namespace https://github.com/2zzly/GMX-Mail-deref-decoder
  4. // @version 1
  5. // @description Decodes and rewrites external URLs. Stops URL tracking/analytics
  6. // @author 1Deref
  7. // @match *://*/*
  8. // @grant none
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. function decodeAndRewriteUrl(url) {
  16. const regexMail = /https:\/\/deref-mail\.com\/mail\/client\/([a-zA-Z0-9-_]{11})\/dereferrer\/\?redirectUrl=(.+)/;
  17. const regexGMX = /https:\/\/deref-gmx\.net\/mail\/client\/([a-zA-Z0-9-_]{11})\/dereferrer\/\?redirectUrl=(.+)/;
  18.  
  19. const matchMail = url.match(regexMail);
  20. const matchGMX = url.match(regexGMX);
  21.  
  22. if (matchMail && matchMail[2]) {
  23. const strippedUrl = matchMail[2];
  24. const decodedUrl = decodeURIComponent(strippedUrl);
  25. return decodedUrl;
  26. }
  27.  
  28. if (matchGMX && matchGMX[2]) {
  29. const strippedUrl = matchGMX[2];
  30. const decodedUrl = decodeURIComponent(strippedUrl);
  31. return decodedUrl;
  32. }
  33.  
  34. return null;
  35. }
  36.  
  37. function injectScript(frame) {
  38. const script = document.createElement('script');
  39. script.textContent = `
  40. (function() {
  41. const links = document.querySelectorAll('a');
  42. for (const link of links) {
  43. const decodedUrl = decodeAndRewriteUrl(link.href);
  44. if (decodedUrl) {
  45. link.href = decodedUrl;
  46. }
  47. }
  48. })();
  49. `;
  50. frame.contentDocument.head.appendChild(script);
  51. }
  52.  
  53. function handleFrames() {
  54. const frames = document.querySelectorAll('iframe');
  55. for (const frame of frames) {
  56. injectScript(frame);
  57. }
  58. }
  59.  
  60. // Handle the top-level document
  61. const links = document.querySelectorAll('a');
  62. for (const link of links) {
  63. const decodedUrl = decodeAndRewriteUrl(link.href);
  64. if (decodedUrl) {
  65. link.href = decodedUrl;
  66. }
  67. }
  68.  
  69. // Handle frames
  70. handleFrames();
  71. })();