-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Using vimium to add custom javascript commands #1392
Comments
This is reasonable proposal, and we should entertain the idea. However, it needs to be fleshed out a bit. What Vimium does well is modes and key bindings. And those key bindings just end up calling JavaScript. So it's natural for users to want to bind their own JavaScript to keys. And the proposed syntax for key mappings is clean. The problem, as I see it, is that users will quickly (and reasonably) want more:
Vimium's current options page doesn't lend itself to these things. And extending it to do so would distract from the core Vimium design goals. Here's a half-baked idea I've been thinking about. Admit key mappings as @ggreenwood proposes:
Add a below-the-fold option
If
Why is this a good idea?
Why is this a bad idea?
Edit: Users will also quickly (and reasonably) want site-specific key mappings. Something like:
|
I'm inherently uncomfortable with running remote code in our privileged Vimium context. For now, I feel like the safest way to do this is to let other extensions register their own actions (by messaging us), potentially with default key bindings that we prompt the user before enabling. Surely anyone who can write and host some javascript can also write a 5 line
at the end of their code. (And of course load the extension into Chrome.) This removes the responsibility of managing someone else's code from us, which is a big security/stability win.
Suggest discussing this separately (#1188), since this is a useful feature to have for our existing commands too. Edit: documenting the commands is also an issue, the discussions on #1269, #1280 are potentially relevant. |
I have some thoughts, will come in soon.
|
@philc I'd quite like to get started on my suggestion here, what were your thoughts on the issue? |
Theoretically the idea of calling custom JS code with vimium sounds interesting. Do you have in mind any concrete examples, what are the snippets you would like to bind? I'm just curious if some snippets would appear to be so useful, that we would eventually like to ship pre-defined set of snippets as a part of vimium. |
When I start work on this, I'm planning to implement all the commands open as PRs blocked #1269, so these will be things that we're actively considering shipping. I'd also like to implement some commands for moving tabs between windows, but I'll submit a PR for that here first. |
I know that I would like to be able to open a predefined link in a new and current tab. For example, 'bf' could open facebook from any page, and 'br' would open Reddit. Other websites, like fimfiction.net, are well designed and consistent, but don't have keyboard shortcuts for every common functionality. By calling the page's javascript functions, I could implement them myself. |
Not really addressing your question, but I do something almost like this all the time....
The way Vimium does its scoring, whole words score higher than partial matches. So, If you really, really want to encourage Vimium to choose your bookmark, use "Facebook (FB FB)". It'll score even higher. It'd be nice if Vimium just got it right. But this is one way to help Vimium to get it right. |
Since we don't run in the page's javascript scope, we never actually get access to these. This leaves 2 options:
For page context, I recon we could just use a custom event ( |
Suggest drawing inspiration from Vimium's Firefox-verse counterpart, VimFx, which has custom commands pretty fleshed out. They are registered by other extensions, which provide a natural way to distribute them (and allow other addons to contribute their own commands/bindings). I'm assuming without verification that it's possible for a Chrome extension to expose an API for other extensions. |
I propose to allow multiple ways to define commands. I really like where #2109 is going, but for many things I would not want to create an extension since I can express them in one line if I use the existing vimium functions. Example: map I coffee v ->
v.goToTab url: 'https://inbox.google.com' I'm imagining you can write coffeescript, which will get transpiled and when run it gets a vimium api with nice functions to call. (note that the API could be both a parameter and |
Hey guys, Any progress on this feature? |
I also would love to see this functionality. Also, I agree with @wmertens -- a principle draw of the proposed functionality for me is that it's lightweight. I don't want to deal with creating and installing a custom extension to write a couple of javascript one-line convenience functions. FWIW, the functionality I'd like to have is simply hiding all images on a page. I have an extension I use for this on noisy pages, but I'd prefer to be able to activate it with a simple keyboard shortcut. |
@corbt you can use this branch (technically you only need 3d23c0a). To use, add a line similar to the following to your key mappings: Note: this doesn't always work with Firefox, (eg. on github) since they don't grant content scripts an exemption from the |
Usage: map <keys> js javascript=uricomponentencoded_javascript_code
In my Chrome 62.0.3202.94 this does not seem to be working. Any idea how can I debug this? But pressing 'aa' do not seem to trigger it at all |
This feature has not yet been implemented. |
I'd like to be able to extend vimium by mapping to my own plugins. If not arbitrary JS, a sendMessage, or I'd be fine with @mrmr1993's idea of registering my plugin with vimium. Bonus points if a count can be optionally given to the mapping. This would help keeping vimium's core features small and well maintained, while allowing people to extend it to their liking. Allowing people to extend vimium won't diminish its quality, people can install crap plugins in vim too, yet they tend to not do that... |
Hi there and any updates? Thanks for what you guys have tried! |
there is there a forum discussing that. im on the watch. I keep you posted. |
It seems this issue is not solved yet... Unfortunately, although Vimium's So I think the most simple solution is to add a check into
I've implemented this in my customized version of Vimium, Vimium C (https://github.com/gdh1995/vimium-c), which supports a command named
Communicate with other extensionsAs for communicating with other extensions, Vimium hasn't provided such a method. If anyone is still interested in this, you may take a try with Vimium C 's command of
|
for me, opening urls is easy if I save the bookmark with a particular name before the actual name. For example, bgh -> opens github, b opens up the vomnibar in bookmark mode and I saved my bookmark with |
This enlight me a workaround to use "custom search engine" to transfer parameter "target=%s" into local html file, and then you can use js to achieve your object. Of course it can be a js without any parameter. fy: file://C:\translate.html?target=%s Thank you! |
Any progress on this ? The API could be like // From my script.
function onKeyPress(data) {
// do something
}
const addToVimiumEvent = new CustomEvent('vimium_register_key', {
detail: {
key: 'g v' // Press `g` then `v` to initiate.
handler: onKeyPress,
callback: (error, message) => {
// check if adding failed or worked.
},
}
})
document.dispatchEvent(addToVimiumEvent); We can also try more ways of integrating deeply with Vimium, just like plugins integrate with vim/neovim. |
With the ease of making site-specific key mappings, I would like to add in the ability for the user to execute arbitrary javascript one-liners on the open webpage with a vimium hook. This would allow savvy users to quickly enhance keyboard support for a unique site, and create new vimium commands.
For example, the following mapping and command would be possible:
When the user presses 'a', vimium would eval the javascript stored under that command and alert the user.
I would be willing to code this feature, but I would like to ask a few things first:
Thanks, all.
-Garrett
The text was updated successfully, but these errors were encountered: