Greasy Fork is available in English.

Reddit remove params from share url

Remove params from share url copied

// ==UserScript==
// @name               Reddit remove params from share url
// @namespace          https://greasyfork.org/users/821661
// @match              https://*.reddit.com/*
// @grant              none
// @run-at             document-start
// @version            1.2
// @author             hdyzen
// @description        Remove params from share url copied
// @license            GPL-3.0
// ==/UserScript==
'use strict';

// Params to delete in url copied
const paramsToDelete = ['utm_source', 'utm_medium', 'utm_name', 'utm_term', 'utm_content', 'ref', 'ref_source'];

// Remove params
function removeParams(url) {
    const params = new URL(url);

    paramsToDelete.forEach(param => params.searchParams.delete(param)); // Delete params

    return params.href; // Value modded
}

// Oldreddit
const originalInputSelect = HTMLInputElement.prototype.select;

HTMLInputElement.prototype.select = function () {
    this.value = removeParams(this.value);

    return originalInputSelect.apply(this, arguments);
};

// Newreddit
const originalSelect = HTMLTextAreaElement.prototype.select;

HTMLTextAreaElement.prototype.select = function () {
    this.value = removeParams(this.value);

    return originalSelect.apply(this, arguments);
};

// Shreddit
navigator.clipboard.writeText = function writeText(text) {
    return removeParams(text);
};