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

Implemented generic omnibar function. #90

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

blacklight
Copy link

@blacklight blacklight commented Nov 23, 2024

This is a follow-up of #73.

Please consider this as a proof-of-concept at the current stage: everything is up for debate in this implementation.

Documentation is also still missing from this PR - I'll add it if it goes through, after any required changes.

Since the API exposed by Surfingkeys is very limited (and it seems to become more limited on every release), and response times on PR also take their time, I've decided to add a new generic Omnibar implementation that exposes callbacks such as autocomplete, onEnter (with shiftKey and ctrlKey modifiers) and onResultClick to customize the behaviour (which e.g. allows POST requests, custom autocomplete hooks, close/keep open on input behaviour etc.).

It also provides a multiline mode to replace the default Omnibar input with a <textarea> - useful for example for ChatGPT input.

Two reference implementations are also provided in the comments:

  • Searxng search suggestions + search results directly in the Omnibar (via <Shift+Enter>) or search page opened upon <Enter>.
  • ChatGPT support in the Omnibar. The query is submitted with <Ctrl+Enter> and the response text is copied on item click or when <Enter> is pressed on a result.

Note that, since many of those low-level APIs are no longer exposed by Surfingkeys, I've had to reinvent half of the wheel and do some DOM plumbing to add items and event handlers.

I'd also like to add dynamic favicons to the results (based on the domain name), but I'm not sure how to do it with the current API without bumping into CORS.

Closes: #73

Since the API exposed by Surfingkeys is very limited (and it becomes
more limited on every release), I've added a new Omnibar implementation
that exposes callbacks such as `autocomplete`, `onEnter`, `onShiftEnter`
and `onResultClick` to customize the behaviour (which e.g. allows POST
requests, custom autocomplete hooks, close/keep open on input behaviour
etc.).
@b0o
Copy link
Owner

b0o commented Nov 26, 2024

This looks great! It's got me excited thinking of all the potential use-cases.

One suggestion, I think we should use DOMPurify inside of omnibar.js to sanitize the HTML before setting innerHTML or otherwise injecting external content into the DOM. There are some helper functions in util.js, or you can just import dompurify directly if you prefer. You can see some examples in search-engines.js.

@blacklight
Copy link
Author

Hi @b0o, thanks for the feedback! I have added htmlPurify to the parts of the code that set innerHTML .

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

Successfully merging this pull request may close these issues.

[Feature Request] Support for more complex HTTP requests in search_engines.js
2 participants