Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to feed the url selected in vomnibar into sendToExtension command #573

Closed
leodream opened this issue Mar 15, 2022 · 8 comments
Closed

Comments

@leodream
Copy link

What command or commands

vomnibar and sendToExtension

How should a feature do

When a user has done such steps:

  • open vomnibar and select an URL

then Vimium C should do:

  • run sendToExtension with the selected URL to trigger actions in another addons

Is it possible to create such mapping currently? Appreciate if anyone can shine a light on it.

@gdh1995
Copy link
Owner

gdh1995 commented Mar 16, 2022

You may add se: vimium://run/sendToExtension#id=abcd&#data=$S SendToExt to Custom search engines.

Currently through this method data can only be a whole URL, while you can not embed URL into a JSON value. Do you need to send anything like { "url": "...", "foo": 123 } ?

If you do need, then I may add a syntax of data={"foo":123} data.url=$S to work with current features.

image

@leodream
Copy link
Author

  • Indeed, the API I use consumes a JSON with URL as a field.
  • It seems like, with that configuration, vimium-c will only sent what I typed if I open the vomnibar and begin with "se". To send a URL, I need to first choose a candidate in vomnibar and then move the cursor to the beginning and insert "se ", which is a bit cumbersome and the candidate must not match any search engine rules -- to not replace with parsed keywords.

Anyway, it feels good to know a new method to call another addons. Thanks.
Also, is there a way to consume the return of await browser.runtime.sendMessage() and test it in the condition mentioned in https://github.com/gdh1995/vimium-c/wiki/Auto-run-a-tree-of-commands?

@gdh1995
Copy link
Owner

gdh1995 commented Mar 18, 2022

  1. yes, you have to select a URL, move caret to start, and then insert se
  2. if a URL is parsed as keyword + query, press Ctrl+] to toggle which item to show in the query input
    1. query text should switch among parsed query, real url, and title text
  1. map xxx Vomnibar.activate keyword="se" will help, since it auto sets se (s, e, and a space) as the default query text.
  2. the response of runtime.sendMessage can be boolean | string, or any other JSON objects
    1. if it's string, then show a HUD with its value
    1. currently, sendToExtension returns true, if and only if a response is not false

@gdh1995
Copy link
Owner

gdh1995 commented Mar 18, 2022

To auto insert "se " on Enter, I'll add some options to Vomnibar to do so.

To pass JSON, please wait furture versions, too. V1.97 may be in weeks or more than 1 month.

@gdh1995
Copy link
Owner

gdh1995 commented Mar 23, 2022

Hello, v1.97.0 is waiting for extension stores to check and publish. With v1.97.0, you may:

  1. add this to Custom Key Mappings: map xxx Vomnibar.activate sed sedKeys="1" itemSedKeys="1"
  2. add to Auto substitution of various text:
1@^@$&@,btoa
# hfjbmagddngcpeloejdejnfgbamkjaeg should be replaced with a target ID
1@^.*$@vimium://run/sendToExtension#id=hfjbmagddngcpeloejdejnfgbamkjaeg&#data={"url":"$&","key":42}@

When you use xxx to show Vomnibar, type something, select a suggestion item and then press Enter, Vimium C will:

  • use itemSedKeys to match rules in Auto substitution of various text
  • run matched rules one by one, so:
    • do base64 encoding
    • replace the result with vimium://run/......, and now the data can be a valid JSON object (must not include any space character)
  • execute the vimium://url command URL.

In the future, I'll add a new way named json to replace btoa, so that you may embed any string into {"url":"$&"} safely

@leodream
Copy link
Author

leodream commented Apr 2, 2022

It works, except that it seems there is no way to specify raw in vimium://run/sendToExtension.
I use following as workaround.

map <v-tst> sendToExtension id="ADDONID" raw

1@^.*$@vimium://run/<v-tst>##data={"type":"create","params":{"url":"$&"}}@

@gdh1995
Copy link
Owner

gdh1995 commented Apr 2, 2022

1@^.*$@vimium://run/<v-tst>#raw&#data={"type":"create","params":{"url":"$&"}}@ should work.

The first # means to begin a parameter list, like a URL's hash section; a parameter name starting with # (here is #data) means all of the following characters make up its value and should not be URL-decoded.

@gdh1995
Copy link
Owner

gdh1995 commented May 2, 2022

Hello, since v1.98.0 the solution is much more intuitive.

Please add such a key mapping:

# `itemSedKeys` is executed when the current selected is a suggestion on enter
# - use `sedKeys` when the current is the input itself
# then `itemKeyword` is used to build a new URL
map xxx Vomnibar.activate itemSedKeys="1" sedKeys="1" itemKeyword="sendUrl"
map <v-ste> sendToExtension id="ADDONID" raw

Add this to Custome search engines:

sendUrl: vimium://run/<v-ste>##data={"type":"create","params":{"url":"$1"}}

Add this to Auto substitution of various text:

# always encode a string to ensure `"${it}"` is a valid JSON string
1@^@@,json

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants