Debugging 'Copy link to highlight' snippet

Hi! When I copy web source, I use ‘copy link to highlight’ feature frequently.

I’m using this snippet but this snippet just copy the website url simply.
How can I get selected text’s url? Which part should I edit?

#popclip
name: Copy text with url
icon: symbol:link.circle.fill
capture html: true
javascript: |
  const url = popclip.context.browserUrl;
  const text = popclip.input.text.trim();
  const title = popclip.context.browserTitle || 'Untitled';
  if (url && text) {
    const highlightLink = url + '#:~:text=' + encodeURIComponent(text);
    const formattedText = `${text} - [${title}](${url})`;
    popclip.copyText(formattedText);
    popclip.showSuccess();
  } else {
    popclip.showText('Unable to create link');
  }

Thank you!

This code is creating the highlightLink string correctly, but then doesn’t do anything with it.

You can update the formattedText line to use highlightLink instead of url:

const formattedText = `${text} - [${title}](${highlightLink})`;

Jesus!! Thank you so much! It works perfectly :+1:

1 Like