/** * 历史回顾和日志功能 */ import { requestSave } from './save-manager.js'; import { getSettings, LOREBOOK_NAME_PREFIX, LOREBOOK_NAME_SUFFIX } from './config.js'; import { escapeHtml } from './utils.js'; import { showToast } from './toast.js'; // 最大日志数量 const MAX_LOGS = 20; // 获取错误日志 export function getErrorLogs() { const settings = getSettings(); return settings.errorLogs || []; } // 添加错误日志 export function addErrorLog(error, context = '') { const settings = getSettings(); if (!settings.errorLogs) settings.errorLogs = []; const now = new Date(); const timeStr = now.getHours().toString().padStart(2,'0') + ':' + now.getMinutes().toString().padStart(2,'0') + ':' + now.getSeconds().toString().padStart(2,'0'); // 生成简短的错误摘要(约15字) const errorMsg = error?.message || String(error); let summary = context ? context + ': ' : ''; // 截取关键信息 if (errorMsg.length > 15 - summary.length) { summary += errorMsg.substring(0, 15 - summary.length) + '...'; } else { summary += errorMsg; } const logEntry = { time: timeStr, summary: summary.substring(0, 18), // 确保不超过18字 message: errorMsg, context: context }; settings.errorLogs.unshift(logEntry); // 只保留最近的 MAX_LOGS 条 if (settings.errorLogs.length > MAX_LOGS) { settings.errorLogs = settings.errorLogs.slice(0, MAX_LOGS); } requestSave(); return logEntry; } // 清空错误日志 export function clearErrorLogs() { const settings = getSettings(); settings.errorLogs = []; requestSave(); } // 刷新日志列表显示 export function refreshLogsList() { const listEl = document.getElementById('wechat-logs-list'); if (!listEl) return; const logs = getErrorLogs(); if (logs.length === 0) { listEl.innerHTML = '