# Omit the user from shared links

**URL:** <https://racket.discourse.group/t/omit-the-user-from-shared-links/1221>\
**Category:** Site Feedback\
**Tags:** link, share, user\
**Created:** [August 10, 2022, 10:22pm UTC](https://racket.discourse.group/t/omit-the-user-from-shared-links/1221 "2022-08-10T22:22:16Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![simonls](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/simonls/32/170_2.png) [@simonls](https://racket.discourse.group/u/simonls)\
**Post date:** [August 10, 2022, 11:14pm UTC](https://racket.discourse.group/t/omit-the-user-from-shared-links/1221/2 "2022-08-10T23:14:17Z")

</div>

I don't have a strong opinion on this topic.  
Here are two posts on the meta site that I found on the topic:

> **[Why do all shared links include the username (u=username)](https://meta.discourse.org/t/why-do-all-shared-links-include-the-username-u-username/60126)**
>
> What exactly is the reason that every link to a discourse post has a u=username at the end? Since the links are functional without, I suppose the idea is some sort of tracking. But for what purpose and where/how does they become tangible in some...

> **[Usernames in shared links break anonymity](https://meta.discourse.org/t/usernames-in-shared-links-break-anonymity/42554)**
>
> Most forums operate with a level of user anonymity - usernames are used instead of real names. The social sharing functions of Discourse however show the username in an unecrypted format, such as: ...

This post from the second topic seems to suggest that they would be open to a feature being added as a PR (In other posts they say that no paying customer has wanted it):

> **[Usernames in shared links break anonymity](https://meta.discourse.org/t/usernames-in-shared-links-break-anonymity/42554/9)**
>
> I am fine with that as a PR, but you would automatically lose all the sharing badges (first share, nice share, good share, great share) if you disabled usernames there.

Having it as a global site setting seems too much, because different users would probably prefer it differently. Personally I think there should be a user setting to disable it, maybe that could be added via PR.

Alternatively it might be possible to create a browser local user script with some extension like [https://www.tampermonkey.net/](https://www.tampermonkey.net/) ~~but I guess that is more of a last resort solution, if no PR would be accepted~~.

Also I am not sure what settings there are, I haven't explored that in depth.

* * *

~~Considering that it is quite easy to write that script maybe it is a good solution and~~ the good thing about it is that you can even customize it to your liking and different users can make it do what they want, I haven't tested it extensively, ~~but it seems to work~~ (almost):

It works the first time, after that it always shows the rewritten text from the first opening even for other posts, but I am currently too tired to figure out why / what kind of state keeps hanging around, or if it somehow blocks some code from setting the new value...  
I guess I hate working with the DOM, too much state and stuff and no way to sensibly compose programs, or easily find out how one thing breaks some other code.  
Maybe someone else finds the solution, I don't want to waste any more time on this...

```javascript
// ==UserScript==
// @name share link username remover
// @namespace http://tampermonkey.net/
// @version 0.1
// @description removes the username from sharelink on discourse websites
// @author You
// @match *.discourse.group/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=discourse.group
// @grant none
// ==/UserScript==

(function() {
    'use strict';

    let container = document.querySelector("#discourse-modal");
    new MutationObserver(function() {
        if(container.classList.contains("hidden")) {
            container.removeAttribute("removed-username"); // reset the class
        } else if(!container.getAttribute("removed-username")) {
            // only remove the username once per opening of the modal
            let node = document.querySelector(".link-share-container .invite-link");
            let url = new URL(node.value);
            url.search = "";
            let new_value = url.toString();
            node.value = new_value
            // reselect all the text
            node.setSelectionRange(0, new_value.length);
            container.setAttribute("removed-username","true");
        }
    }).observe(container, {"attributes":true, "attributeFilter":["class"]});
    // uses attributeFilter to avoid infinite mutation observation loops
    // where after observation we generate the next mutation

})();

```

---

_[View the full topic](https://racket.discourse.group/t/omit-the-user-from-shared-links/1221)._
