feat: add omnibox to extension

This commit is contained in:
Steven 2023-08-11 00:26:04 +08:00
parent 6f26523a11
commit f1e3eace1a
3 changed files with 13 additions and 1 deletions

View File

@ -47,6 +47,9 @@
"typescript": "5.1.6"
},
"manifest": {
"omnibox": {
"keyword": "s"
},
"permissions": [
"tabs",
"storage"

View File

@ -20,6 +20,15 @@ chrome.tabs.onUpdated.addListener(async (tabId, _, tab) => {
}
});
chrome.omnibox.onInputEntered.addListener(async (text) => {
const shortcuts = (await storage.getItem<Shortcut[]>("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) {

View File

@ -110,7 +110,7 @@ const IndexOptions = () => {
</div>
</div>
{isInitialized && shortcuts.length > 0 && (
{isInitialized && (
<>
<Divider className="!my-6" />