feat: simple extension setup

This commit is contained in:
2026-05-31 21:37:04 +02:00
parent d6f170ac2f
commit 98f0fd10b0
12 changed files with 522 additions and 0 deletions

46
src/content.ts Normal file
View File

@@ -0,0 +1,46 @@
import { State, STORAGE_KEY } from "./types";
const KEY_BINDINGS: Record<string, string> = {
// TODO
};
let enabled = false;
const clickButton = (selector: string): void => {
const el = document.querySelector<HTMLElement>(selector);
el?.click();
};
const onKeyDown = (event: KeyboardEvent): void => {
if (!enabled) return;
const target = event.target as HTMLElement;
if (
target.tagName === "INPUT" ||
target.tagName === "TEXTAREA" ||
target.isContentEditable
) return;
const selector = KEY_BINDINGS[event.code];
if (selector) {
event.preventDefault();
clickButton(selector);
}
};
const init = async (): Promise<void> => {
const result = await chrome.storage.local.get(STORAGE_KEY);
const state = result[STORAGE_KEY] as State | undefined;
enabled = state?.enabled ?? true;
document.addEventListener("keydown", onKeyDown);
chrome.storage.onChanged.addListener((changes) => {
if (STORAGE_KEY in changes) {
const next = changes[STORAGE_KEY].newValue as State;
enabled = next.enabled;
}
});
};
init();