Address second CodeRabbit review round

This commit is contained in:
2026-04-10 03:18:22 -07:00
committed by sudacode
parent fd05b3f868
commit 5711e1cb49
9 changed files with 320 additions and 15 deletions

View File

@@ -1,6 +1,11 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import { YOMITAN_LOOKUP_EVENT, registerYomitanLookupListener } from './yomitan-popup.js';
import {
YOMITAN_LOOKUP_EVENT,
YOMITAN_POPUP_VISIBLE_HOST_SELECTOR,
isYomitanPopupVisible,
registerYomitanLookupListener,
} from './yomitan-popup.js';
test('registerYomitanLookupListener forwards the SubMiner Yomitan lookup event', () => {
const target = new EventTarget();
@@ -16,3 +21,12 @@ test('registerYomitanLookupListener forwards the SubMiner Yomitan lookup event',
assert.deepEqual(calls, ['lookup']);
});
test('isYomitanPopupVisible falls back to querySelector when querySelectorAll is unavailable', () => {
const root = {
querySelector: (selector: string) =>
selector === YOMITAN_POPUP_VISIBLE_HOST_SELECTOR ? ({} as Element) : null,
} as ParentNode;
assert.equal(isYomitanPopupVisible(root), true);
});

View File

@@ -62,10 +62,14 @@ function queryPopupElements<T extends Element>(
root: ParentNode | null | undefined,
selector: string,
): T[] {
if (typeof root?.querySelectorAll !== 'function') {
return [];
if (typeof root?.querySelectorAll === 'function') {
return Array.from(root.querySelectorAll<T>(selector));
}
return Array.from(root.querySelectorAll<T>(selector));
if (typeof root?.querySelector === 'function') {
const first = root.querySelector(selector) as T | null;
return first ? [first] : [];
}
return [];
}
export function isYomitanPopupVisible(root: ParentNode | null | undefined = document): boolean {