Auto Remove ChatGPT UTM Parameter

Removes ?utm_source=chatgpt.com from URLs and reloads the page automatically

  1. // ==UserScript==
  2. // @name Auto Remove ChatGPT UTM Parameter
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0.1
  5. // @description Removes ?utm_source=chatgpt.com from URLs and reloads the page automatically
  6. // @description:en Removes ?utm_source=chatgpt.com from URLs and reloads the page automatically
  7. // @description:de Entfernt ?utm_source=chatgpt.com aus URLs und lädt die Seite automatisch neu
  8. // @author https://github.com/anga83
  9. // @match *://*/*
  10. // @grant none
  11. // @run-at document-start
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16. const currentUrl = window.location.href;
  17. const hasUtmSource = currentUrl.includes('?utm_source=chatgpt.com') || currentUrl.includes('&utm_source=chatgpt.com');
  18. if (hasUtmSource) {
  19. const url = new URL(currentUrl);
  20. url.searchParams.delete('utm_source');
  21. let cleanUrl = url.toString();
  22. if (cleanUrl.endsWith('?')) {
  23. cleanUrl = cleanUrl.slice(0, -1);
  24. }
  25. if (cleanUrl !== currentUrl) {
  26. window.location.replace(cleanUrl);
  27. }
  28. }
  29. })();