Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
6 changes: 4 additions & 2 deletions src/uimanager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { waitForElement } from "./utils.js";
import { waitFor } from "./utils.js";
import type { ExtensionCore } from "./types.js";

export class UIManager {
Expand All @@ -12,7 +12,9 @@ export class UIManager {
}

async initUI(): Promise<void> {
await waitForElement("body");
await new Promise<void>((resolve) => {
waitFor("body", () => resolve());
});

this.box = document.createElement("div");
const h1 = document.createElement("h1");
Expand Down
22 changes: 0 additions & 22 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,6 @@ export const waitFor = (
}),
): MutationObserver => (o.observe(document.body, { childList: true, subtree: true }), o);

export function waitForElement(selector: string): Promise<Element | null> {
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),
Expand Down