From f1e3eace1a124a28d9ef846ef0f0419fc1442974 Mon Sep 17 00:00:00 2001 From: Steven Date: Fri, 11 Aug 2023 00:26:04 +0800 Subject: [PATCH] feat: add omnibox to extension --- extension/package.json | 3 +++ extension/src/background.ts | 9 +++++++++ extension/src/options.tsx | 2 +- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/extension/package.json b/extension/package.json index c4c3f2c..4be21fd 100644 --- a/extension/package.json +++ b/extension/package.json @@ -47,6 +47,9 @@ "typescript": "5.1.6" }, "manifest": { + "omnibox": { + "keyword": "s" + }, "permissions": [ "tabs", "storage" diff --git a/extension/src/background.ts b/extension/src/background.ts index c1266ba..c4d032b 100644 --- a/extension/src/background.ts +++ b/extension/src/background.ts @@ -20,6 +20,15 @@ chrome.tabs.onUpdated.addListener(async (tabId, _, tab) => { } }); +chrome.omnibox.onInputEntered.addListener(async (text) => { + const shortcuts = (await storage.getItem("shortcuts")) || []; + const shortcut = shortcuts.find((shortcut) => shortcut.name === text); + if (!shortcut) { + return; + } + return chrome.tabs.update({ url: shortcut.link }); +}); + const getShortcutNameFromUrl = (urlString: string) => { const matchResult = urlRegex.exec(urlString); if (matchResult === null) { diff --git a/extension/src/options.tsx b/extension/src/options.tsx index 0194386..aabae42 100644 --- a/extension/src/options.tsx +++ b/extension/src/options.tsx @@ -110,7 +110,7 @@ const IndexOptions = () => { - {isInitialized && shortcuts.length > 0 && ( + {isInitialized && ( <>