mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-08-07 07:21:35 -07:00
fix: Kiku field grouping, frequency particles, sidebar media, Yomitan popup visibility (#91)
This commit is contained in:
@@ -25,6 +25,7 @@ interface MpvClientLike {
|
||||
currentSubStart: number;
|
||||
currentSubEnd: number;
|
||||
currentSecondarySubText?: string;
|
||||
requestProperty?: (name: string) => Promise<unknown>;
|
||||
}
|
||||
|
||||
export function handleMultiCopyDigit(
|
||||
@@ -95,6 +96,32 @@ function getSecondarySubTextForMinedBlocks(
|
||||
return getCurrentSecondarySubText();
|
||||
}
|
||||
|
||||
function normalizeSecondarySubText(text: unknown, primaryText: string): string | undefined {
|
||||
if (typeof text !== 'string') {
|
||||
return undefined;
|
||||
}
|
||||
const trimmed = text.trim();
|
||||
if (!trimmed || trimmed === primaryText.trim()) {
|
||||
return undefined;
|
||||
}
|
||||
return trimmed;
|
||||
}
|
||||
|
||||
async function getCurrentSecondarySubTextForSentenceCard(
|
||||
mpvClient: MpvClientLike,
|
||||
): Promise<string | undefined> {
|
||||
const primaryText = mpvClient.currentSubText;
|
||||
if (mpvClient.requestProperty) {
|
||||
try {
|
||||
const latestSecondaryText = await mpvClient.requestProperty('secondary-sub-text');
|
||||
return normalizeSecondarySubText(latestSecondaryText, primaryText);
|
||||
} catch {
|
||||
// Fall back to the cached secondary subtitle below.
|
||||
}
|
||||
}
|
||||
return normalizeSecondarySubText(mpvClient.currentSecondarySubText, primaryText);
|
||||
}
|
||||
|
||||
export async function updateLastCardFromClipboard(deps: {
|
||||
ankiIntegration: AnkiIntegrationLike | null;
|
||||
readClipboardText: () => string;
|
||||
@@ -141,11 +168,12 @@ export async function mineSentenceCard(deps: {
|
||||
return false;
|
||||
}
|
||||
|
||||
const secondarySubText = await getCurrentSecondarySubTextForSentenceCard(mpvClient);
|
||||
return await anki.createSentenceCard(
|
||||
mpvClient.currentSubText,
|
||||
mpvClient.currentSubStart,
|
||||
mpvClient.currentSubEnd,
|
||||
mpvClient.currentSecondarySubText || undefined,
|
||||
secondarySubText,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user