Omit the user from shared links

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

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):

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/ 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...

// ==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

})();
1 Like