Search two (or more) sites at once

For @kxxc:

// #popclip
// { name: 2x Search, lang: js }
const query = encodeURIComponent(popclip.input.text);
popclip.openUrl("https://example1.com/?q=" + query);
popclip.openUrl("https://example2.com/?q=" + query);

(The above block is an extension snippet - select it then click “Install Extension” in PopClip.)

To search more sites, just add more lines.

4 Likes

yees! thank you
but looks like these lines no longer working on js code, haha… :joy:

icon: iconify:tabler:square-rounded-number-4
requirements: [text, “!urls”]
after: copy-selection

Post the whole thing for me so I can take a look.
BTW, when posting the forum you can write ``` on the line before and after the code to format it as a code block

2 Likes

Gave me a shaking X feedback :rofl:

// { name: test, lang: js }
icon: iconify:tabler:square-rounded-number-4
requirements: [text, "!urls"]
const query = encodeURIComponent(popclip.input.text);
popclip.openUrl("https://www.apple.com/tw/search/" + query);
popclip.openUrl("https://www.youtube.com/results?search_query=" + query);
after: copy-selection

Nice job with the ``` :slight_smile:

So the extension has two parts, the settings and the code, which need to be kept separate.

The extension settings go in the in the top part, with // before each line, like this:

// #popclip
// name: test
// lang: js
// icon: iconify:tabler:square-rounded-number-4
// requirements: [text, "!urls"]
// after: copy-selection
const query = encodeURIComponent(popclip.input.text);
popclip.openUrl("https://www.apple.com/tw/search/" + query);
popclip.openUrl("https://www.youtube.com/results?search_query=" + query);
1 Like

I’m alive again! thank u vm!
so many ways in PopClip so much mystery.
every Mac user should use it :smiling_face_with_three_hearts:

2 Likes

@nick

I made some changes and added the ‘alternate URL’ parameter, but it doesn’t seem to work. Did I make any mistakes?


// PopClip
// name: Twitter
// lang: js
// icon: iconify:bi:twitter
// requirements: [text, “!urls”]
// after: copy-selection
const query = encodeURIComponent(popclip.input.text);
url: https://twitter.com/search?q=*** lang:zh-cn
alternate url:
popclip.openUrl(“https://twitter.com/search?q=” + query);
popclip.openUrl(“https://twitter.com/search?q=” + query + " filter:follows");

It isn’t clear from the snippet you posted what you’re trying to achieve. Please describe in words what want the extension to do.

I’m sorry, my previous description was not clear enough. What I hope to achieve is:

  1. By default, when I click, it performs a default search:
    https://twitter.com/search?q=*** lang:zh-cn

  2. When I hold down the ‘Option’ key and click, it opens two links simultaneously for searching:
    https://twitter.com/search?q=***
    https://twitter.com/search?q=*** filter:follows

This should be close:

// #popclip
// name: test
// lang: js
// requirements: [text, "!urls"]
// after: copy-selection
const query = encodeURIComponent(popclip.input.text);
if (popclip.modifiers.option) {
  popclip.openUrl(`https://twitter.com/search?q=${query}`);
  popclip.openUrl(`https://twitter.com/search?q=${query}%20filter:follows`);
} else {
  popclip.openUrl(`https://twitter.com/search?q=${query}%20lang:zh-cn`);
}
1 Like

Wow, thank you! The interaction works fine. However, I encountered one issue during usage, and I’m not sure what the reasons are:

The ‘lang:zh-cn’ parameter needs to be placed in the search box, for example, this snippet:

# popclip
name: Twitter
Icon: iconify:bi:twitter
url: https://twitter.com/search?q=*** lang:zh-cn



1 Like

Ah — I see. I have edited the original post

Thank you very much! It’s working mostly fine now, but there’s a minor issue. When searching in Chinese, the search results are correct, but the input box displays garbled characters. Is this an encoding error?

Try again – I edited again. I think I should have put a %20 instead of a space

Perfect! It’s working perfectly now! Thank you for your patience and assistance! ::

1 Like

2 posts were merged into an existing topic: Option modifier not working in extension