From 4f109a981fc60f65252398891ca7cfbab2bf4b42 Mon Sep 17 00:00:00 2001 From: Kuuuube <61125188+Kuuuube@users.noreply.github.com> Date: Mon, 24 Feb 2025 07:14:23 -0500 Subject: [PATCH] Add support for omnibox search with Yomitan (#1822) * Add support for omnibox search with Yomitan * Change keyword to "yomi" * Catch errors on omnibox listener --- dev/data/manifest-variants.json | 3 +++ ext/js/background/backend.js | 14 ++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/dev/data/manifest-variants.json b/dev/data/manifest-variants.json index 0dd2a22f6b..5b7e1bdb80 100644 --- a/dev/data/manifest-variants.json +++ b/dev/data/manifest-variants.json @@ -33,6 +33,9 @@ "service_worker": "sw.js", "type": "module" }, + "omnibox": { + "keyword": "yomi" + }, "content_scripts": [ { "run_at": "document_idle", diff --git a/ext/js/background/backend.js b/ext/js/background/backend.js index a533805c52..a9dbbc3e54 100644 --- a/ext/js/background/backend.js +++ b/ext/js/background/backend.js @@ -1373,6 +1373,8 @@ export class Backend { this._setupContextMenu(options); + this._attachOmniboxListener(); + void this._accessibilityController.update(this._getOptionsFull(false)); this._sendMessageAllTabsIgnoreResponse({action: 'applicationOptionsUpdated', params: {source}}); @@ -1404,6 +1406,18 @@ export class Backend { } } + /** */ + _attachOmniboxListener() { + try { + chrome.omnibox.onInputEntered.addListener((text) => { + const newURL = 'search.html?query=' + encodeURIComponent(text); + void chrome.tabs.create({url: newURL}); + }); + } catch (e) { + log.error(e); + } + } + /** * @param {boolean} useSchema * @returns {import('settings').Options}