Skip to content

Commit

Permalink
Add "search extensions"
Browse files Browse the repository at this point in the history
  • Loading branch information
dbuezas committed Oct 2, 2024
1 parent 26bd237 commit 67b2674
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 13 deletions.
Binary file modified chrome-palette.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "chrome-palette",
"displayName": "Chrome Palette",
"version": "2.0.0",
"version": "2.1.0",
"description": "Command Palette for Chrome",
"license": "MIT",
"packageManager": "[email protected]",
Expand Down
2 changes: 1 addition & 1 deletion src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const manifest = defineManifest(async () => ({
"tabs",
"sessions",
"bookmarks",
// "processes",
"management",
"history",
"favicon",
],
Expand Down
2 changes: 2 additions & 0 deletions src/pages/popup/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import Shortcut from "./Shortcut";
import audibleTabSuggestions from "./commands/audio";
import bookmarkThisSuggestions from "./commands/bookmark-this";
import bookmarkSuggestions from "./commands/bookmarks";
import extenionsSuggestions from "./commands/extensions";
import generalSuggestions, { Command } from "./commands/general";
import historySuggestions from "./commands/history";
import switchTabSuggestions from "./commands/tabs";
Expand All @@ -42,6 +43,7 @@ const allCommands = createMemo(() => {
...switchTabSuggestions(),
...historySuggestions(),
...bookmarkSuggestions(),
...extenionsSuggestions(),
...websitesSuggestions(),
...themeSuggestions(),
];
Expand Down
9 changes: 6 additions & 3 deletions src/pages/popup/Entry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import Shortcut from "./Shortcut";
import { Command } from "./commands/general";
import { parsedInput } from "./util/signals";

function faviconURL(u: string) {
export function faviconURL(u?: string) {
if (!u) return u;
const url = new URL(chrome.runtime.getURL("/_favicon/"));
url.searchParams.set("pageUrl", u);
url.searchParams.set("size", "32");
Expand Down Expand Up @@ -56,14 +57,14 @@ export default function Entry(props: {
});
}}
>
<Show when={props.command.icon}>
<Show when={props.command.icon || faviconURL(props.command.url)}>
{(icon) => (
<img
classList={{
img: true,
img_big: !!(subtitle() || url()),
}}
src={faviconURL(icon())}
src={icon()}
alt=""
loading="lazy"
/>
Expand All @@ -80,6 +81,8 @@ export default function Entry(props: {
<Show when={parsedInput().query} fallback={props.command.subtitle}>
{subtitle()}
</Show>
</div>
<div class="subtitle">
<Show when={parsedInput().query} fallback={props.command.url}>
{url()}
</Show>
Expand Down
3 changes: 2 additions & 1 deletion src/pages/popup/commands/bookmark-this.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { createLazyResource, matchCommand, setInput } from "~/util/signals";

import { faviconURL } from "../Entry";
import { Command } from "./general";

const KEYWORD = "bt";
Expand All @@ -14,7 +15,7 @@ const traverse = (
if (!url && path !== "") {
list.push({
title: path,
icon: "chrome://favicon/",
icon: faviconURL("chrome://favicon/"),
lastVisitTime: dateAdded,
command: async function () {
const [tab] = await chrome.tabs.query({
Expand Down
5 changes: 3 additions & 2 deletions src/pages/popup/commands/bookmarks.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { createLazyResource, matchCommand, setInput } from "~/util/signals";

import { faviconURL } from "../Entry";
import { Command } from "./general";

const KEYWORD = "b";
Expand All @@ -18,7 +19,7 @@ const traverse = (
url ||= "";
return {
title: `${title} > ${breadcrumb}`,
icon: "chrome://favicon/" + url,
icon: faviconURL(url),
lastVisitTime: dateAdded,
url,
};
Expand All @@ -36,7 +37,7 @@ const base: Command[] = [
command: async function () {
setInput(KEYWORD + ">");
},
icon: "chrome://bookmarks/",
icon: faviconURL("chrome://bookmarks/"),
keyword: KEYWORD + ">",
},
];
Expand Down
42 changes: 42 additions & 0 deletions src/pages/popup/commands/extensions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { createLazyResource, matchCommand, setInput } from "~/util/signals";

import { faviconURL } from "../Entry";
import { Command } from "./general";

const KEYWORD = "e";

const commands = createLazyResource<Command[]>([], async (setVal) => {
return (await chrome.management.getAll()).map(
({ name, icons, id, enabled, version, description }) => {
return {
title: `${name} (${version})`,
subtitle: description,
icon:
icons
?.map((o) => o?.url)
.filter(Boolean)
.at(-1) ?? "chrome://extensions/",
url: `chrome://extensions/?id=${id}`,
enabled,
};
}
);
});

const base: Command[] = [
{
title: "Search Extensions",
icon: faviconURL("chrome://extensions/"),
command: async function () {
setInput(KEYWORD + ">");
},
keyword: KEYWORD + ">",
},
];

export default function extensionSuggestions(): Command[] {
const { isMatch, isCommand } = matchCommand(KEYWORD);
if (isMatch) return commands();
if (isCommand) return [];
return base;
}
2 changes: 2 additions & 0 deletions src/pages/popup/commands/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { resetHistory } from "~/util/last-used";
import { inputSignal, parsedInput } from "~/util/signals";

import { faviconURL } from "../Entry";
import { isTruthy } from "../util/isTruthy";

export type Command = {
Expand Down Expand Up @@ -78,6 +79,7 @@ const base: Command[] = [
title: "Open Settings",
shortcut: "⌘ ,",
url: "chrome://settings",
icon: faviconURL("chrome://settings"),
},
{
title: "Close Current Tab",
Expand Down
5 changes: 3 additions & 2 deletions src/pages/popup/commands/history.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { createLazyResource, matchCommand, setInput } from "~/util/signals";

import { faviconURL } from "../Entry";
import { Command } from "./general";

const KEYWORD = "h";
Expand Down Expand Up @@ -32,7 +33,7 @@ const commands = createLazyResource<Command[]>([], async (setVal) => {
return {
title: title || "Untitled",
lastVisitTime,
icon: url,
icon: faviconURL(url),
url,
};
})
Expand All @@ -50,7 +51,7 @@ const commands = createLazyResource<Command[]>([], async (setVal) => {
const base: Command[] = [
{
title: "Search History",
icon: "chrome://history/",
icon: faviconURL("chrome://history/"),
command: async function () {
setInput(KEYWORD + ">");
},
Expand Down
5 changes: 3 additions & 2 deletions src/pages/popup/commands/tabs.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import niceUrl from "~/util/nice-url";
import { createLazyResource, matchCommand, setInput } from "~/util/signals";

import { faviconURL } from "../Entry";
import { Command } from "./general";

const KEYWORD = "t";
Expand All @@ -12,7 +13,7 @@ const commands = createLazyResource<Command[]>([], async () => {
return {
title: title || "Untitled",
subtitle: niceUrl(url),
icon: url,
icon: faviconURL(url),
command: () => {
chrome.tabs.update(id!, { highlighted: true });
chrome.windows.update(windowId!, { focused: true });
Expand All @@ -29,7 +30,7 @@ const base: Command[] = [
setInput(KEYWORD + ">");
},
keyword: KEYWORD + ">",
icon: "about:blank",
icon: faviconURL("about:blank"),
},
];

Expand Down
3 changes: 2 additions & 1 deletion src/pages/popup/commands/website-search.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { matchCommand, parsedInput, setInput } from "~/util/signals";

import { faviconURL } from "../Entry";
import { Command } from "./general";

type Template = {
Expand Down Expand Up @@ -37,7 +38,7 @@ const templates: Template[] = [

const base: Command[] = templates.map((template) => ({
title: `Search ${template.title}`,
icon: template.icon,
icon: faviconURL(template.icon),
command: async function () {
setInput(template.keyword + ">");
},
Expand Down

0 comments on commit 67b2674

Please sign in to comment.