Extension Snippet Help? Clean URLs to Remove Tracking

I absolutely love the new Extension Snippets! Such a cool, elegant implementation.

I was trying to modify the Remove Dots Extension Snippet to make it remove the tracking info from URLs (basically everything from and including ?):



Here’s what I came up with (that doesn’t work). I tried to just change the regex. Clearly, I don’t know Javascript:

# popclip
name: Remove Tracking
javascript: popclip.pasteText(popclip.input.text.replace(/([^\?]*)/))
description: Remove tracking code from the selected URL.

I’d be grateful if anyone could show me what’s wrong with the above snippet.

Thanks in advance!

1 Like

Try this instead:

# popclip
name: Remove Tracking
requirements: [url]
javascript: popclip.pasteText(popclip.input.text.replace(/\?.*/, ''))
description: Remove tracking code from the selected URL.

I haven’t tried it in PopClip (I’m on mobile) but the (\?.*) appears to successfully capture anything following a ? in the URL. As it stands, it captures anything following a ? at all, even if it isn’t a URL. But if you only use it on URLs, it should work


Great work @tf2 and welcome to the forum. I’ve edited your code slightly as there was a missing bracket. It also needed a second parameter added to replace(). Should work now!
(JS docs ref: http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)

I als added a line requirements: [url] which constrains the extension to only appear when the selection contains a web URL.

Worth noting that this removes the entire query part of the URL, not just tracking codes. But makign it target tracking specifically would be significantly more complicated!

Thanks very much to both of you! Works like a charm. Say goodbye to tracking and hello to Popclip! :smiley:


Wonderful — thanks! And thanks for making PopClip so easy to customize. Nice touch making it work on URLs only.

I’m gradually making all my bookmarklets into PopClip snippets; that’s way I can use whichever is most useful in the moment. Will post here if they’re useful beyond my own workflows.

1 Like

Hi @tf2
Thank you very much for that idea to shorten URLs from tracking.
My question as an amateur: How can I add that functionality to Popclip?
Will there be an additional Popclip Extension or do I have to create that myself?
(Sorry for being so naive!)

1 Like

From your Mac, and with PopClip running, just highlight the snippet with your mouse, including the first # popclip line.

The Popclip ribbon/interface should appear, and one of the options will be to install “Remove Tracking” (which is the name provided in the snippet).

Pretty sure I have the steps right. I’m on my phone at the moment.

Wow, what a useful and easy way to get a new function!

Thanks @tf2 for the explanation and thank you, @nick from PopClip, for being so clever!

It is pretty brilliant.


Hi guys I’m missing the obvious somewhere, but how do I add this snippet to PopClip?

1 Like

With PopClip running on your Mac, use your mouse/trackpad to select the text of the snippet, including the first and last lines. PopClip should appear, with an addition item showing the name of the snippet. Click on that and it’ll install.

In other words, PopClip itself turns the text of the snippet into a new PopClip extension.

1 Like

Wow that is completely awesome. Works like a charm…

Now I just need to work out how to back all my Clips up!

You’ll find everything in ~/Library/Application Support/PopClip/Extensions (PopClip can reveal that for you, naturally…)

Welcome to the forum @t3kk2

Brilliant, they are indeed. I guess I’d need the ‘show in finder’ or similar option installed. It’d be useful (for the future) if they could be sync’ed in iCloud and therefore safely backed up automatically?

1 Like

Indeed - we’ve had some discussion on this, see Idea: Sync Extensions across Macs using iCloud Drive

Cheers it looks like I’ve got some reading up to do :slight_smile:

One last comment on this clip, is there any way to replace the ‘Replace Tracking’ with an icon?

Yep, you add an icon with a line such as:

icon: square filled RT

is one example — see Icons for the specification and some examples.

Ah ha right, works perfectly!

1 Like

So this is coming late, but I’m just learning about this awesome new extension snippet stuff.

Regarding your URL snippet, which is amazing, how do you trigger Popclips to copy it? Do you have to always copy a link, then paste it somewhere, then highlight it to trigger Popclip?

Is there a way to trigger a Popclip action just by right-clicking on the link?

1 Like

Glad you are enjoying the snippets! I introduced them only a few months ago as a kind of “soft launch” experimental feature, while I make sure they work right and figure out how to explain them. Honestly, they have gone better than I imagined and I’ve been pleasantly surprised how well they have been received. It’s been great to see people sharing snippets and helping figure out ways to do things.

So as for URLs, PopClip right now only works on URLs that are in view in the selected plain text, for example, that you might select in the address bar.
Or as as you say, paste somewhere else.


PopClip does have the ability theoretically, to look at the HTML behind the selection, and I so hope to have it working directly on Web page links in future. At least, in some form.

It makes PopClip a little less snappy and response in browsers when it is getting the HTML, so it doesn’t do it at the moment. Is a tricky one to figure out the right balance of compromises in the UI to do it.

I suspect it may require an extra click to “X-ray” the links. Anyway, I’m rambling :grinning: