I know firefox has the very useful “Copy clean Link” option in the context menu, but I would like a similar feature for copying links from any other software, like spotify for example. So I am looking for some software that hooks into the clipboard pipeline, and cleans any URL that gets added. I tried googling for something like it, but was completely unsuccessful. Does anyone have a clue how I might go about achieving this?
Thanks in advance :)
Edit: I found out about klipper
’s actions, which provide the option to run a command when a string that matches a regex is added to the clipboard buffer. I am not sure how to properly use this though, so any help is appreciated!
That’d be cool. Whenever I’m sharing a YT link, I’m always a bit suspicious of what info the youtu.be URL is hiding, so I paste it into a browser to get a clean URL.
Maybe this is silly, but I’d be cool to do that automatically.
You never define “clean”.
To strip excess URL parameters (i.e. beginning “&”, almost certainly junk) if the clipboard buffer contains a URL and only a URL (Wayland only):
if url=$(printf '%s' "$(wl-paste --no-newline | awk '$1=$1' ORS=' ')" | egrep -o 'https?://[^ ]+') ; then wl-copy "${url%%\&*}" fi
Edit: Oh, OP basically already said the same thing.
I think it really depends on the website and even where you are on the website. For example, if you’re on YT, the
watch?v=<b64_id>
is probably not something you want to throw away. If you’re on a news site likeimaginarynews.com/.../the-article-title/?tracking-garbage=<...>
then you probably do. It’s just a matter of having “sane” defaults that work as most people would expect.Fair enough, I haven’t given that too much thought myself until now. After playing around with Firefox’s URL cleaning, I realized there are some parameters I want to keep. So, by clean I mean removing all unnecessary parameters in the URL.
For example,
https://youtu.be/jNQXAC9IVRw
would becomehttps://youtu.be/jNQXAC9IVRw
, buthttps://www.youtube.com/watch?v=jNQXAC9IVRw
keeps it’s parameter, because it is necessary.I guess replicating the logic for deciding which parameters to keep is not trivial, so the easiest solution is probably just manually pasting links into firefox, and just copying them cleanly from there. Thanks for providing some code, though!
There is no logic as to which parameters is useful and which is used for tracking. But there are databases.
Here is the one for the CleanURLs extension and here is the one for the AdGuard URL Tracking filter list (which I recommend everyone should enable in uBlock Origin).
Oh, nice! That’s definitely valuable info. Personally, I do think it’s too much work to implement that properly, though.
Query parameters are junk? They have tons of legitimate uses, they’re one of the better places to keep state.
I wish that option was the default in Firefox.
It’s never worked for me either. The ClearURLs addon has a function to copy a clean URL and that works great though. It’s open source, so maybe someone could turn its cleaning function into a program that could be used for the clipboard.
Hmm. Thanks, though I’m seeking universal /offline so if I get URLs in other platforms, I won’t have to turn to the browser to purge them of junk. Or maybe this could be converted into a standalone program…