import { STOP_WORDS } from '../data/stopwords.js'; import { state } from '../core/state.js'; import { saveSchedule, saveWords } from '../core/storage.js'; import { showToast } from '../ui/toast.js'; import { speak } from '../services/tts.js'; import { callAI, translateWord } from '../services/ai.js'; import { initWordSchedule } from '../services/ebbinghaus.js'; import { getMastery } from '../services/stats.js'; import { escapeHtml, formatFormsHtml } from '../ui/dom.js'; import { findWordContext } from '../services/extractor.js'; import { getNextId } from './words.js'; import { beginMailLearnRequest, isCurrentMailLearnRequest } from './mail-learn.js'; export let readerTranslations = {}; export let readerSentences = []; let readerSessionGeneration = 0; // ==================== Full-Text Reading Mode ==================== export function splitSentences(text) { const raw = text.split(/(?<=[.!?])\s+|(?:\r?\n){2,}/); return raw.map(s => s.trim()).filter(s => s.length > 0); } export function isStopWord(w) { return STOP_WORDS.has(w.toLowerCase()); } export function buildReadingSentenceHtml(sentence) { const knownMap = {}; state.words.forEach(w => { knownMap[w.english.toLowerCase()] = w; }); const tokens = sentence.split(/(\s+|[,.;:!?'"()\[\]{}<>\/\\—–\-])/); let html = ''; tokens.forEach(tok => { const clean = tok.toLowerCase().replace(/[^a-z'-]/g, ''); const word = knownMap[clean]; if (word && clean.length >= 2) { html += `${escapeHtml(tok)}`; } else if (/^[a-zA-Z]{2,}$/.test(clean) && !isStopWord(clean)) { html += `${escapeHtml(tok)}`; } else { html += escapeHtml(tok); } }); return html; } export async function startFullReading() { const sessionGeneration = ++readerSessionGeneration; const text = document.getElementById('mail-learn-input').value.trim(); if (!text) { showToast('请粘贴邮件内容', 'error'); return; } const sentences = splitSentences(text); if (!sentences.length) { showToast('无法解析邮件内容', 'error'); return; } const resultEl = document.getElementById('mail-learn-result'); const request = beginMailLearnRequest(resultEl); resultEl.innerHTML = '