Universal Tracker Remover

Removes common tracking parameters (e.g., utm_source, fbclid, from) from all links and the browser address bar, on all websites.

  1. // ==UserScript==
  2. // @name Universal Tracker Remover
  3. // @namespace https://cleanlinks.net/
  4. // @version 1.0
  5. // @description Removes common tracking parameters (e.g., utm_source, fbclid, from) from all links and the browser address bar, on all websites.
  6. // @author DiCK
  7. // @match *://*/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function () {
  12. 'use strict';
  13.  
  14. // List of tracking parameters to remove
  15. const trackingParams = [
  16. 'utm_source',
  17. 'utm_medium',
  18. 'utm_campaign',
  19. 'utm_term',
  20. 'utm_content',
  21. 'fbclid',
  22. 'gclid',
  23. 'mc_cid',
  24. 'mc_eid',
  25. 'ref',
  26. 'ref_',
  27. 'from'
  28. ];
  29.  
  30. // Remove trackers from a given URL string
  31. function removeTrackersFromUrl(urlString) {
  32. try {
  33. const url = new URL(urlString, window.location.origin);
  34. let modified = false;
  35.  
  36. trackingParams.forEach(param => {
  37. if (url.searchParams.has(param)) {
  38. url.searchParams.delete(param);
  39. modified = true;
  40. }
  41. });
  42.  
  43. return modified ? url.toString() : urlString;
  44. } catch (e) {
  45. // Fail silently if invalid URL
  46. return urlString;
  47. }
  48. }
  49.  
  50. // Clean all anchor tags on the page
  51. function cleanLinks() {
  52. const links = document.querySelectorAll('a[href*="?"], a[href*="&"]');
  53.  
  54. links.forEach(link => {
  55. const cleaned = removeTrackersFromUrl(link.href);
  56. if (cleaned !== link.href) {
  57. link.href = cleaned;
  58. }
  59. });
  60. }
  61.  
  62. // Clean the browser address bar (without reloading the page)
  63. function cleanAddressBar() {
  64. const currentUrl = window.location.href;
  65. const cleaned = removeTrackersFromUrl(currentUrl);
  66.  
  67. if (cleaned !== currentUrl) {
  68. const urlObj = new URL(cleaned);
  69. const newUrl = urlObj.pathname + urlObj.search + urlObj.hash;
  70. window.history.replaceState(null, '', newUrl);
  71. }
  72. }
  73.  
  74. // Run immediately
  75. cleanLinks();
  76. cleanAddressBar();
  77.  
  78. // Watch for dynamic changes (e.g., AJAX navigation)
  79. const observer = new MutationObserver(() => {
  80. cleanLinks();
  81. });
  82.  
  83. observer.observe(document.body, { childList: true, subtree: true });
  84. })();