Joshua Rogers' Scribbles

Always 'Copy Clean Link' when possible on Firefox, with userChrome.css

In my last two posts, I outlined how to clean up the right-click menu on Firefox to remove useless buttons using about:config and userChrome.css, respectively. One of my major complaints was that when right-clicking a link, I was presented with two buttons: one for ‘Copy Link’, and one for ‘Copy Clean Link’ – with the latter 99.% of the time greyed out due to link already being clean. I found the greyed out link annoying, because it cluttered up my screen and since it wasn’t useful for the vast majority of the time, just another empty space taking up my screen for something I would never use. In my ideal world, the ‘Copy Link’ button would always clean the link, if possible; but this is not an option in Firefox.

Since then, realansgar reached out and offered an idea of how to achieve what I wanted, by using CSS to hide the ‘Copy Clean Link’ button if it was greyed out (disabled), and hide the ‘Copy Link’ button if the ‘Copy Clean Link’ was not greyed out. Following the same instructions in my post about userChrome.css, we first ensure that #context-stripOnShareLink is not set to display: none !important; (as the instructions in that post recommend) and that privacy.query_stripping.strip_on_share.enabled is enabled in about:config, and then add to our userChrome.css the following:

#context-stripOnShareLink[disabled=true] {
  display: none !important;
}
#contentAreaContextMenu:has(#context-stripOnShareLink:not([disabled=true])) #context-copylink {
  display: none !important;
}

Restarting Firefox should make it start working. The CSS basically dictates that at any time, right-clicking a link will only ever show one button: either ‘Copy Link’ or ‘Copy Clean Link’. This link to a blog post from Sentry is a good link to test. Since most of the link is full of tracking, right-clicking should only show ‘Copy Clean Link’.

Generally speaking, I would much rather it just always shows ‘Copy Link’, and the cleaning is opaque (to make the the menu predictable/static). I came up with the following CSS instead:

#context-stripOnShareLink[disabled],
#context-stripOnShareLink[hidden],
#context-copylink[hidden] {
  display: none !important;
}

#contentAreaContextMenu:has(#context-stripOnShareLink:not([disabled]):not([hidden])) #context-copylink {
  display: none !important;
}

#context-copylink .menu-text,
#context-stripOnShareLink .menu-text {
  visibility: collapse !important;
}

#context-copylink::after,
#context-stripOnShareLink::after {
  content: "Copy Link" !important;
  display: -moz-box !important;
}

This ensures that links are always cleaned if possible, and the right-click menu’s button always says ‘Copy Link’.

Maybe Firefox will one day offer a “Copy Clean Link by Default” option, but until then, this is a good solution.