Automatically remove fbclid parameter from URLs?

26 views
Skip to first unread message

Esben Maaløe

unread,
Jun 18, 2024, 8:15:02 AM6/18/24
to CopyQ
Hi

Is it possible to have copyq always remove the fbclid query-param from URLs when copying (or inserting) them?

I found a script on CopyQs GitHub-page - but it seems I have to invoke it, for each copy/paste action?

This is the script:

Name=Replace in Selection
Command="
    copyq:
    // Copy without changing Linux mouse selection (on Windows you can use "copy" instead).
    function copy2() {
      try {
        var x = config('copy_clipboard')
        config('copy_clipboard', false)
        try {
          copy.apply(this, arguments)
        } finally {
          config('copy_clipboard', x)
        }
      } catch(e) {
        copy.apply(this, arguments)
      }
    }

    copy2()
    var text = str(clipboard())

    if (text) {
      var r1 = 'Text' // I'd need to set this to an appropriate regex
      var r2 = 'Replace with' // I'd need to set this to an empty string
      var reply = dialog(r1, '', r2, '')

      if (reply) {
        copy2(text.replace(new RegExp(reply[r1], 'g'), reply[r2]))
        paste()
      }
    }"
Icon=\xf040
GlobalShortcut=Meta+Alt+R

Lukáš Holeček

unread,
Jun 19, 2024, 8:11:34 AM6/19/24
to Esben Maaløe, CopyQ
You can modify the command in the Command dialog by enabling Automatic button instead of the "Global Shortcut" (you need to enable Show Advanced checkbox to see the buttons).

Also, select "text/plain" as Format under Advanced tab.

Then edit code in Command tab to something like:

copyq:
const text = str(input());
const regex = new RegExp('\bfbclid=[^&]*', 'g');
const newText = text.replace(regex, '');
if (text != newText) {
  popup('Removed fbclid query parameter');
  copy(newText);
}



--
You received this message because you are subscribed to the Google Groups "CopyQ" group.
To unsubscribe from this group and stop receiving emails from it, send an email to copyq+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/copyq/e424a813-852e-4d3c-953d-aa6dd844184cn%40googlegroups.com.

Esben Maaløe

unread,
Jun 19, 2024, 11:06:34 AM6/19/24
to CopyQ
Thanks Lukas!

Still having problems, nothing happens at all.

This is what I've done:


And the advanced tab:

https://pasteboard.co/78otkJsZC9Di.png

If you look at the code, you'll see that I inserted an extra popup on line 2, just to see if the command is invoked at all - it's not invoked.

Any idea what I am missing?

Esben Maaløe

unread,
Jun 19, 2024, 11:08:19 AM6/19/24
to CopyQ
(oh, on the screenshot the actual popup-code is inserted on line 5, but it doesn't matter - no popups and no sanitized querystring)

Lukáš Holeček

unread,
Jun 23, 2024, 4:12:57 AM6/23/24
to Esben Maaløe, CopyQ
Ah, the regex was missing additional '\' (escape character) and also some function call to modify the text to store in CopyQ.

Here is the full command:

[Command]
Automatic=true
Command="

    copyq:
    const text = str(input());
    const regex = new RegExp('\\\\bfbclid=[^&]*', 'g');
    const newText = text.replace(regex, '');
    if (text != newText) {
      popup('Removed fbclid query parameter');
      copy(newText);
      setData(mimeText, newText);
      removeData(mimeTextUtf8);
      removeData(mimeHtml);
    }"
Icon=
Input=text/plain
Name=Replace in Selection


Esben Maaløe

unread,
Jul 4, 2024, 3:09:37 AM7/4/24
to CopyQ
It works - genius!

Thank you Lukáš :-D

Esben Maaløe

unread,
Jul 4, 2024, 3:10:04 AM7/4/24
to CopyQ
There's no popup for some reason, but that's ok
Reply all
Reply to author
Forward
0 new messages