32
Clean all URLs in clipboard
(lemmy.world)
From Wikipedia, the free encyclopedia
Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).
Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.
Community icon by Alpár-Etele Méder, licensed under CC BY 3.0
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):
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?si=someTrackingId
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.
There are some examples of projects that use CleanURLs db in its readme but most have not been updated for a long time.
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.Sure, but my script only gets rid of the second and later parameters, i.e. ones with
&
not?
. Personally I don't think I've ever seen a single site where an&
param is critical. These days there few where the?
matters either, but yes YT is a holdout.There are plenty of sites that use more than one parameters. It's true that a lot of sites now use the history API instead of url parameters but you can still find plenty, and you have no garante about the parameters order. Any site with a search page that have a few options will probably use url parameters instead of the history API. It's easier to parse and will end up being shorter most of the time.
Search results, sure. Personally I have rarely if ever wanted to save or share such URLs. But sure.
Query parameters are junk? They have tons of legitimate uses, they’re one of the better places to keep state.
As a WebDev... URL parameters are definitely not the place to keep state... Were not in the 00's anymore. They do have legit uses, but we have JS localStorage nowadays.
They have pretty different use cases. Localstorage is for when you want persistence across page loads, not necessarily specific to any particular page but specific to a browser. An example would be storing user-selected light or dark mode.
Query parameters are specific to a page/URL and you get a lot of things for free when you use them:
Query parameters are good for things like searches, filters, sorting, etc
I disagree. I definitely prefer REST APIs that use the file path for searches, filters, sorting. You get most if not all benefits from query parameters, and if done correctly it is just as clearly readable as query params.
But what if you have multiple optional parameters?
have multiple routes point to the same endpoint, dynamically adding the parameters serverside
That sounds harder than just using query parameters. What are the benefits?
Having more beautiful and structured URLs. I suppose for those cases it's more of a preference, and with the tooling I use (.NET) it's not too difficult to achieve.
I guess my gripe with your original statement was that I was thinking mostly of state like user login etc. I have to concede it's not totally garbage for the cases you mentioned.