From 262e871ca36235f3d352c1e71442f5adaac653e4 Mon Sep 17 00:00:00 2001 From: Violet Millie Date: Fri, 26 Jan 2024 15:33:00 +0000 Subject: [PATCH] Implement search keybind --- src/extension/typescript/RegisterKeybinds.ts | 2 ++ .../typescript/keybinds/SearchKeybind.ts | 32 +++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 src/extension/typescript/keybinds/SearchKeybind.ts diff --git a/src/extension/typescript/RegisterKeybinds.ts b/src/extension/typescript/RegisterKeybinds.ts index 43ea2ca..e4392f8 100644 --- a/src/extension/typescript/RegisterKeybinds.ts +++ b/src/extension/typescript/RegisterKeybinds.ts @@ -1,8 +1,10 @@ import type KeybindManager from "./KeybindManager"; import ComposeKeybind from "./keybinds/ComposeKeybind"; +import SearchKeybind from "./keybinds/SearchKeybind"; export default async function (keybindManager: KeybindManager) { keybindManager.registerKeybind(ComposeKeybind); + keybindManager.registerKeybind(SearchKeybind); } diff --git a/src/extension/typescript/keybinds/SearchKeybind.ts b/src/extension/typescript/keybinds/SearchKeybind.ts new file mode 100644 index 0000000..29604c6 --- /dev/null +++ b/src/extension/typescript/keybinds/SearchKeybind.ts @@ -0,0 +1,32 @@ +import type { Keybind } from "../KeybindManager"; + +const keybind: Keybind = { + key: "s", + + execute: function () { + const buttonElement = document.querySelector( + "button.nav-icon:nth-child(1)" + ); + + if (!buttonElement) { + return; + } + + const button = buttonElement as HTMLElement; + + button.click(); + + const inputElement = document.querySelector("#search-bar-input"); + + if (!inputElement) { + return; + } + + const input = inputElement as HTMLElement; + + input.focus(); + }, +}; + +export default keybind; +