logoalt Hacker News

hamdingersyesterday at 8:45 PM2 repliesview on HN

While I don't take the author's hard stance, I do hate gratuitous query params that result in links that are thousands of characters long.

I use this bookmarklet to strip query params before sharing a link:

    javascript:(()=>navigator.clipboard.writeText(location.origin+location.pathname))();

Replies

susamtoday at 7:15 AM

This corrupts a URL like:

  https://example.com/?p=20&utm_source=spam
to:

  https://example.com/
when in fact we want the following:

  https://example.com/?p=20
A possible improvement can be:

  javascript:(()=>{const u=new URL(location.href);[...u.searchParams.keys()].forEach(k=>{if(k.startsWith('utm_')){u.searchParams.delete(k)}});navigator.clipboard.writeText(u.href)})();
kittikittitoday at 3:00 AM

This is great! I love one-liners that are readable like this. This made me wonder if there are any extensions that run a script on every page load for a web browser. I'm currently experimenting with userscript managers and plan on including your code as an additional security measure against tracking.