In a Google Chrome extension, I want to process a custom string in the same or a similar way to how the Omnibox works.
I think this is easiest to demonstrate with some examples:
http://example.org => We should open the website
example.org => We should also open the website
example.co.uk/test => We should also open the website
example => We should open the default search engine for that term
wp Test => Given that 'wp' is a shortcut for Wikipedia, we should
open the wiki page for 'Test'
Basically what I want to achieve by this is to never have to use the Omnibox again and instead use the VIM-inspired keyboard-only navigation provided by vimium with the additional benefit of allowing me to navigate to custom pages.
There are now actually two question to it:
-
To what degree does the Chrome API or nasty workarounds allow me to avoid and replicate the logic needed to parse the input? Can I take advantage of, e.g., an existing list of top-level domains or available URL schemes? Is there even a way to let Chrome do all the work? After all, this stuff needs to be somewhere inside Chrome already, as the Omnibox uses the same algorithm.
-
If I am unlucky and I have to implement the logic by myself, how can I get necessary information like the configured default search engine or the available shortcuts and their associated URL format strings?
To clarify: I am not interested in implementations of the parsing algorithm itself. If the necessary information is available, implementing the algorithm shouldn’t be too hard, after all.
I ended up completely writing this from scratch: https://github.com/niklasb/vimium/blob/fuzzy/lib/completion.js