// 从配置文件导入设置 // 配置在 env.js 文件中定义 // DOM 元素 const nameInput = document.getElementById('nameInput'); const analyzeBtn = document.getElementById('analyzeBtn'); const loading = document.getElementById('loading'); const rarityScore = document.getElementById('rarityScore'); const rarityDesc = document.getElementById('rarityDesc'); const phoneticScore = document.getElementById('phoneticScore'); const phoneticDesc = document.getElementById('phoneticDesc'); const meaningAnalysis = document.getElementById('meaningAnalysis'); // 解析AI返回的分析结果 function parseAnalysisResult(content) { const result = { rarityScore: '--%', rarityDesc: '解析失败', phoneticScore: '--%', phoneticDesc: '解析失败', meaningAnalysis: '解析失败' }; try { // 过滤掉DeepSeek的思考标签内容 let cleanContent = content.replace(/[\s\S]*?<\/think>/gi, ''); cleanContent = cleanContent.replace(/[\s\S]*$/gi, ''); // 处理未闭合的think标签 cleanContent = cleanContent.trim(); console.log('清理后的内容:', cleanContent); // 提取稀有度评分(百分比格式) const rarityMatch = cleanContent.match(/【稀有度评分】[\s\S]*?评分:(\d+)%[\s\S]*?评价:([\s\S]*?)(?=【|$)/); if (rarityMatch) { result.rarityScore = rarityMatch[1] + '%'; result.rarityDesc = rarityMatch[2].trim(); } // 提取音韵评价(百分比格式) const phoneticMatch = cleanContent.match(/【音韵评价】[\s\S]*?评分:(\d+)%[\s\S]*?评价:([\s\S]*?)(?=【|$)/); if (phoneticMatch) { result.phoneticScore = phoneticMatch[1] + '%'; result.phoneticDesc = phoneticMatch[2].trim(); } // 提取含义解读 const meaningMatch = cleanContent.match(/【含义解读】[\s\S]*?\n([\s\S]+)$/); if (meaningMatch) { result.meaningAnalysis = meaningMatch[1].trim(); } } catch (error) { console.error('解析结果时出错:', error); } return result; } // 简单的markdown解析函数 function parseMarkdown(text) { if (!text || typeof text !== 'string') return text; // 处理加粗 **text** 或 __text__ let parsed = text.replace(/\*\*(.*?)\*\*/g, '$1'); parsed = parsed.replace(/__(.*?)__/g, '$1'); // 处理斜体 *text* 或 _text_ parsed = parsed.replace(/\*(.*?)\*/g, '$1'); parsed = parsed.replace(/_(.*?)_/g, '$1'); // 处理无序列表 const lines = parsed.split('\n'); let inList = false; let result = []; for (let i = 0; i < lines.length; i++) { const line = lines[i].trim(); // 检查是否是列表项(以 - 开头,后面跟空格) if (line.match(/^-\s+/)) { if (!inList) { result.push(''); inList = false; } if (line) { result.push(line); } } } // 如果最后还在列表中,需要关闭列表 if (inList) { result.push(''); } // 重新组合,用
连接非列表行 parsed = result.join('
'); // 清理多余的
标签(在列表前后) parsed = parsed.replace(/