From 37eb8b4f4acc37b8fcabba79fa7d0049ed9e8f31 Mon Sep 17 00:00:00 2001 From: "opencode-agent[bot]" Date: Tue, 17 Mar 2026 05:39:36 +0000 Subject: [PATCH] Removed redundant waitForElement function Co-authored-by: Benjamincf0 --- AGENTS.md | 2 +- src/uimanager.ts | 6 ++++-- src/utils.ts | 22 ---------------------- 3 files changed, 5 insertions(+), 25 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index b6f96a7..c40d9f5 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -182,7 +182,7 @@ export class UIManager { ## Patterns & Best Practices -1. **MutationObserver for dynamic content**: Use `waitFor` or `waitForElement` utilities (utils.ts) for elements that load asynchronously +1. **MutationObserver for dynamic content**: Use `waitFor` utility (utils.ts) for elements that load asynchronously 2. **Key normalization**: Use `normalizeKey()` to handle cross-platform modifiers (mod = Cmd on Mac, Ctrl on Windows) diff --git a/src/uimanager.ts b/src/uimanager.ts index f51a78a..59682a8 100644 --- a/src/uimanager.ts +++ b/src/uimanager.ts @@ -1,4 +1,4 @@ -import { waitForElement } from "./utils.js"; +import { waitFor } from "./utils.js"; import type { ExtensionCore } from "./types.js"; export class UIManager { @@ -12,7 +12,9 @@ export class UIManager { } async initUI(): Promise { - await waitForElement("body"); + await new Promise((resolve) => { + waitFor("body", () => resolve()); + }); this.box = document.createElement("div"); const h1 = document.createElement("h1"); diff --git a/src/utils.ts b/src/utils.ts index 3e75d65..bc3cb85 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -12,28 +12,6 @@ export const waitFor = ( }), ): MutationObserver => (o.observe(document.body, { childList: true, subtree: true }), o); -export function waitForElement(selector: string): Promise { - const element = document.querySelector(selector); - if (element) { - return Promise.resolve(element); - } - - return new Promise((resolve) => { - const observer = new MutationObserver(() => { - const element = document.querySelector(selector); - if (element) { - observer.disconnect(); - resolve(element); - } - }); - - observer.observe(document, { - childList: true, - subtree: true, - }); - }); -} - export const log = { info: (...args: unknown[]) => console.log("[BetterWeb]", ...args), warn: (...args: unknown[]) => console.warn("[BetterWeb]", ...args),