Reddit remove params from share url

Remove params from share url copied

  1. // ==UserScript==
  2. // @name Reddit remove params from share url
  3. // @namespace https://greasyfork.org/users/821661
  4. // @match https://*.reddit.com/*
  5. // @grant none
  6. // @run-at document-start
  7. // @version 1.2
  8. // @author hdyzen
  9. // @description Remove params from share url copied
  10. // @license GPL-3.0
  11. // ==/UserScript==
  12. 'use strict';
  13.  
  14. // Params to delete in url copied
  15. const paramsToDelete = ['utm_source', 'utm_medium', 'utm_name', 'utm_term', 'utm_content', 'ref', 'ref_source'];
  16.  
  17. // Remove params
  18. function removeParams(url) {
  19. const params = new URL(url);
  20.  
  21. paramsToDelete.forEach(param => params.searchParams.delete(param)); // Delete params
  22.  
  23. return params.href; // Value modded
  24. }
  25.  
  26. // Oldreddit
  27. const originalInputSelect = HTMLInputElement.prototype.select;
  28.  
  29. HTMLInputElement.prototype.select = function () {
  30. this.value = removeParams(this.value);
  31.  
  32. return originalInputSelect.apply(this, arguments);
  33. };
  34.  
  35. // Newreddit
  36. const originalSelect = HTMLTextAreaElement.prototype.select;
  37.  
  38. HTMLTextAreaElement.prototype.select = function () {
  39. this.value = removeParams(this.value);
  40.  
  41. return originalSelect.apply(this, arguments);
  42. };
  43.  
  44. // Shreddit
  45. navigator.clipboard.writeText = function writeText(text) {
  46. return removeParams(text);
  47. };