部分修复

This commit is contained in:
2025-09-04 13:38:14 +08:00
parent cca1a969c5
commit eb13979d4d
137 changed files with 6848 additions and 26965 deletions

View File

@@ -0,0 +1,335 @@
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>AI古诗生成器</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Microsoft YaHei', '微软雅黑', Arial, sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
padding: 20px;
color: #333;
}
.container {
max-width: 600px;
margin: 0 auto;
background: rgba(255, 255, 255, 0.95);
border-radius: 20px;
padding: 30px;
box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
backdrop-filter: blur(10px);
}
.header {
text-align: center;
margin-bottom: 30px;
}
.title {
font-size: 2.5rem;
color: #4a5568;
margin-bottom: 10px;
font-weight: 300;
letter-spacing: 2px;
}
.subtitle {
color: #718096;
font-size: 1rem;
margin-bottom: 20px;
}
.form-group {
margin-bottom: 25px;
}
.form-label {
display: block;
margin-bottom: 8px;
font-weight: 500;
color: #4a5568;
font-size: 1rem;
}
.form-input {
width: 100%;
padding: 15px;
border: 2px solid #e2e8f0;
border-radius: 12px;
font-size: 1rem;
transition: all 0.3s ease;
background: #f7fafc;
}
.form-input:focus {
outline: none;
border-color: #667eea;
background: #fff;
box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}
.textarea {
resize: vertical;
min-height: 120px;
font-family: inherit;
}
.btn {
width: 100%;
padding: 15px;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
border: none;
border-radius: 12px;
font-size: 1.1rem;
font-weight: 500;
cursor: pointer;
transition: all 0.3s ease;
margin-bottom: 25px;
}
.btn:hover {
transform: translateY(-2px);
box-shadow: 0 10px 25px rgba(102, 126, 234, 0.3);
}
.btn:active {
transform: translateY(0);
}
.btn:disabled {
opacity: 0.6;
cursor: not-allowed;
transform: none;
}
.result-section {
margin-top: 30px;
}
.result-title {
font-size: 1.3rem;
color: #4a5568;
margin-bottom: 15px;
text-align: center;
font-weight: 500;
}
.poem-output {
background: #f7fafc;
border: 2px solid #e2e8f0;
border-radius: 12px;
padding: 25px;
min-height: 200px;
white-space: pre-wrap;
font-family: 'KaiTi', '楷体', serif;
font-size: 1.2rem;
line-height: 2;
text-align: center;
color: #2d3748;
letter-spacing: 1px;
}
.loading {
display: none;
text-align: center;
color: #667eea;
font-style: italic;
}
.error {
color: #e53e3e;
background: #fed7d7;
border: 1px solid #feb2b2;
padding: 15px;
border-radius: 8px;
margin-top: 15px;
}
@media (max-width: 768px) {
body {
padding: 10px;
}
.container {
padding: 20px;
margin: 10px;
}
.title {
font-size: 2rem;
}
.form-input {
padding: 12px;
}
.btn {
padding: 12px;
}
.poem-output {
padding: 20px;
font-size: 1.1rem;
}
}
@media (max-width: 480px) {
.title {
font-size: 1.8rem;
letter-spacing: 1px;
}
.container {
padding: 15px;
}
.poem-output {
font-size: 1rem;
padding: 15px;
}
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1 class="title">AI古诗生成器</h1>
<p class="subtitle">让人工智能为您创作优美的中国古诗</p>
</div>
<!-- GitHub令牌已内置无需用户输入 -->
<div class="form-group">
<label class="form-label" for="theme">作诗主题:</label>
<textarea
id="theme"
class="form-input textarea"
placeholder="请输入您想要的古诗主题,例如:春天的江南水乡、秋日的思乡之情、雪夜的孤独等..."
>春天的江南水乡</textarea>
</div>
<button id="generateBtn" class="btn">生成古诗</button>
<div class="result-section">
<h3 class="result-title">生成的古诗</h3>
<div id="loading" class="loading">正在创作中,请稍候...</div>
<div id="poemOutput" class="poem-output">点击"生成古诗"按钮AI将为您创作优美的古诗</div>
</div>
</div>
<script>
// GitHub API 配置
const GITHUB_TOKEN = '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';
const endpoint = 'https://models.github.ai/inference/chat/completions';
const generateBtn = document.getElementById('generateBtn');
const loading = document.getElementById('loading');
const poemOutput = document.getElementById('poemOutput');
// 专业的古诗生成提示词
const createPoemPrompt = (theme) => {
return `你是一位精通中国古典诗词的大师,请根据用户提供的主题创作一首优美的古诗。
要求:
1. 严格遵循中国古诗的格律和韵律
2. 可以是五言绝句、七言绝句、五言律诗或七言律诗
3. 注重意境的营造,体现中国传统文化的美感
4. 用词典雅,富有诗意
5. 根据主题选择合适的风格(豪放、婉约、田园、边塞等)
6. 确保押韵和平仄协调
7. 请先给诗歌起一个优美的标题,然后换行写出诗歌内容
8. 格式:标题\n诗歌正文
9. 注意排版对齐,标题居中,诗歌正文左对齐
10. 诗歌内容必须是中文
主题:${theme}
请创作一首古诗:`;
};
generateBtn.addEventListener('click', async () => {
const theme = document.getElementById('theme').value.trim();
if (!theme) {
alert('请输入作诗主题');
return;
}
// 显示加载状态
generateBtn.disabled = true;
generateBtn.textContent = '创作中...';
loading.style.display = 'block';
poemOutput.textContent = '';
// 清除之前的错误信息
const existingError = document.querySelector('.error');
if (existingError) {
existingError.remove();
}
const requestBody = {
model: "openai/gpt-4o-mini",
messages: [{
role: "user",
content: createPoemPrompt(theme)
}],
temperature: 0.8,
max_tokens: 500
};
try {
const response = await fetch(endpoint, {
method: 'POST',
headers: {
'Accept': 'application/vnd.github+json',
'Authorization': `Bearer ${GITHUB_TOKEN}`,
'X-GitHub-Api-Version': '2022-11-28',
'Content-Type': 'application/json'
},
body: JSON.stringify(requestBody)
});
const data = await response.json();
if (data?.choices?.[0]?.message?.content) {
poemOutput.textContent = data.choices[0].message.content.trim();
} else {
throw new Error('AI响应格式异常');
}
} catch (error) {
console.error('生成古诗时出错:', error);
// 显示错误信息
const errorDiv = document.createElement('div');
errorDiv.className = 'error';
errorDiv.textContent = `生成失败:${error.message}。请检查网络连接和访问令牌是否正确。`;
poemOutput.parentNode.appendChild(errorDiv);
poemOutput.textContent = '生成失败,请重试';
} finally {
// 恢复按钮状态
generateBtn.disabled = false;
generateBtn.textContent = '生成古诗';
loading.style.display = 'none';
}
});
// 回车键快捷生成
document.getElementById('theme').addEventListener('keypress', (e) => {
if (e.key === 'Enter' && !e.shiftKey) {
e.preventDefault();
generateBtn.click();
}
});
</script>
</body>
</html>

View File

@@ -0,0 +1,42 @@
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>AI变量命名助手</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="container">
<div class="header">
<h1 class="title">AI变量命名助手</h1>
<p class="subtitle">让AI帮您生成规范的变量名</p>
</div>
<div class="form-section">
<div class="form-group">
<label class="form-label" for="description">变量描述:</label>
<textarea
id="description"
class="form-input textarea"
placeholder="请描述变量的用途,例如:用户的姓名、商品的价格、数据库连接状态等..."
>用户的姓名</textarea>
</div>
<!-- 命名规范选择已移除将生成所有5种规范的建议 -->
<button id="generateBtn" class="btn">生成变量名</button>
</div>
<div class="result-section">
<h3 class="result-title">推荐的变量名</h3>
<div id="loading" class="loading">正在生成中,请稍候...</div>
<div id="suggestions" class="suggestions-container">
<div class="placeholder">点击"生成变量名"按钮AI将为您推荐合适的变量名</div>
</div>
</div>
</div>
<script src="script.js"></script>
</body>
</html>

View File

@@ -0,0 +1,305 @@
// GitHub Models API 配置
const GITHUB_TOKEN = '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';
const API_URL = 'https://models.github.ai/inference/chat/completions';
const MODEL_NAME = 'openai/gpt-4o-mini';
// DOM 元素
const descriptionInput = document.getElementById('description');
const generateBtn = document.getElementById('generateBtn');
const loadingDiv = document.getElementById('loading');
const suggestionsContainer = document.getElementById('suggestions');
// 命名规范转换函数
const namingConventions = {
camelCase: (words) => {
if (words.length === 0) return '';
return words[0].toLowerCase() + words.slice(1).map(word =>
word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()
).join('');
},
PascalCase: (words) => {
return words.map(word =>
word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()
).join('');
},
snake_case: (words) => {
return words.map(word => word.toLowerCase()).join('_');
},
'kebab-case': (words) => {
return words.map(word => word.toLowerCase()).join('-');
},
CONSTANT_CASE: (words) => {
return words.map(word => word.toUpperCase()).join('_');
}
};
// 创建AI提示词
function createNamingPrompt(description) {
return `你是一个专业的变量命名助手。请根据以下描述为变量生成合适的名称:
描述:${description}
请为每种命名规范生成3个变量名建议
1. camelCase (驼峰命名法)
2. PascalCase (帕斯卡命名法)
3. snake_case (下划线命名法)
4. kebab-case (短横线命名法)
5. CONSTANT_CASE (常量命名法)
要求:
- 变量名要准确反映功能和用途
- 严格遵循各自的命名规范
- 避免使用缩写,除非是广泛认知的缩写
- 名称要简洁但具有描述性
- 考虑代码的可读性和维护性
请按以下JSON格式返回
{
"suggestions": {
"camelCase": [
{"name": "变量名1", "description": "解释说明1"},
{"name": "变量名2", "description": "解释说明2"},
{"name": "变量名3", "description": "解释说明3"}
],
"PascalCase": [
{"name": "变量名1", "description": "解释说明1"},
{"name": "变量名2", "description": "解释说明2"},
{"name": "变量名3", "description": "解释说明3"}
],
"snake_case": [
{"name": "变量名1", "description": "解释说明1"},
{"name": "变量名2", "description": "解释说明2"},
{"name": "变量名3", "description": "解释说明3"}
],
"kebab-case": [
{"name": "变量名1", "description": "解释说明1"},
{"name": "变量名2", "description": "解释说明2"},
{"name": "变量名3", "description": "解释说明3"}
],
"CONSTANT_CASE": [
{"name": "变量名1", "description": "解释说明1"},
{"name": "变量名2", "description": "解释说明2"},
{"name": "变量名3", "description": "解释说明3"}
]
}
}
只返回JSON格式的结果不要包含其他文字。`;
}
// 调用GitHub Models API
async function callGitHubModelsAPI(prompt) {
try {
const response = await fetch(API_URL, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${GITHUB_TOKEN}`
},
body: JSON.stringify({
messages: [
{
role: 'user',
content: prompt
}
],
model: MODEL_NAME,
temperature: 0.7,
max_tokens: 1000
})
});
if (!response.ok) {
throw new Error(`API请求失败: ${response.status} ${response.statusText}`);
}
const data = await response.json();
return data.choices[0].message.content;
} catch (error) {
console.error('API调用错误:', error);
throw error;
}
}
// 解析AI响应
function parseAIResponse(response) {
try {
// 尝试直接解析JSON
const parsed = JSON.parse(response);
return parsed.suggestions || {};
} catch (error) {
// 如果直接解析失败尝试提取JSON部分
const jsonMatch = response.match(/\{[\s\S]*\}/);
if (jsonMatch) {
try {
const parsed = JSON.parse(jsonMatch[0]);
return parsed.suggestions || {};
} catch (e) {
console.error('JSON解析失败:', e);
}
}
// 如果JSON解析失败返回空对象
console.error('无法解析AI响应:', response);
return {};
}
}
// 显示建议
function displaySuggestions(suggestions) {
suggestionsContainer.innerHTML = '';
if (!suggestions || Object.keys(suggestions).length === 0) {
suggestionsContainer.innerHTML = '<div class="placeholder">暂无建议,请尝试重新生成</div>';
return;
}
// 命名规范的显示名称
const conventionNames = {
'camelCase': 'camelCase (驼峰命名法)',
'PascalCase': 'PascalCase (帕斯卡命名法)',
'snake_case': 'snake_case (下划线命名法)',
'kebab-case': 'kebab-case (短横线命名法)',
'CONSTANT_CASE': 'CONSTANT_CASE (常量命名法)'
};
// 按命名规范分组显示
Object.keys(suggestions).forEach(convention => {
if (suggestions[convention] && suggestions[convention].length > 0) {
// 创建分组标题
const groupTitle = document.createElement('div');
groupTitle.className = 'convention-group-title';
groupTitle.textContent = conventionNames[convention] || convention;
suggestionsContainer.appendChild(groupTitle);
// 显示该规范下的建议
suggestions[convention].forEach(suggestion => {
const suggestionElement = document.createElement('div');
suggestionElement.className = 'suggestion-item';
suggestionElement.innerHTML = `
<div class="variable-name">${suggestion.name}</div>
<div class="variable-description">${suggestion.description}</div>
<button class="copy-btn" onclick="copyToClipboard('${suggestion.name}', this)">复制</button>
`;
suggestionsContainer.appendChild(suggestionElement);
});
}
});
}
// 复制到剪贴板
function copyToClipboard(text, button) {
navigator.clipboard.writeText(text).then(() => {
showSuccessToast('已复制到剪贴板');
button.textContent = '已复制';
setTimeout(() => {
button.textContent = '复制';
}, 2000);
}).catch(err => {
console.error('复制失败:', err);
// 备用复制方法
const textArea = document.createElement('textarea');
textArea.value = text;
document.body.appendChild(textArea);
textArea.select();
try {
document.execCommand('copy');
showSuccessToast('已复制到剪贴板');
button.textContent = '已复制';
setTimeout(() => {
button.textContent = '复制';
}, 2000);
} catch (e) {
showErrorMessage('复制失败,请手动复制');
}
document.body.removeChild(textArea);
});
}
// 显示成功提示
function showSuccessToast(message) {
const toast = document.createElement('div');
toast.className = 'success-toast';
toast.textContent = message;
document.body.appendChild(toast);
setTimeout(() => {
toast.classList.add('show');
}, 100);
setTimeout(() => {
toast.classList.remove('show');
setTimeout(() => {
document.body.removeChild(toast);
}, 300);
}, 2000);
}
// 显示错误信息
function showErrorMessage(message) {
const errorDiv = document.createElement('div');
errorDiv.className = 'error';
errorDiv.textContent = message;
suggestionsContainer.innerHTML = '';
suggestionsContainer.appendChild(errorDiv);
}
// 显示加载状态
function showLoading(show) {
loadingDiv.style.display = show ? 'block' : 'none';
generateBtn.disabled = show;
generateBtn.textContent = show ? '生成中...' : '生成变量名';
}
// 生成变量名建议
async function generateSuggestions() {
const description = descriptionInput.value.trim();
if (!description) {
showErrorMessage('请输入变量描述');
return;
}
showLoading(true);
suggestionsContainer.innerHTML = '';
try {
const prompt = createNamingPrompt(description);
const response = await callGitHubModelsAPI(prompt);
const suggestions = parseAIResponse(response);
displaySuggestions(suggestions);
} catch (error) {
console.error('生成建议失败:', error);
showErrorMessage(`生成失败: ${error.message}`);
} finally {
showLoading(false);
}
}
// 事件监听器
generateBtn.addEventListener('click', generateSuggestions);
// 回车键生成
descriptionInput.addEventListener('keypress', (e) => {
if (e.key === 'Enter' && !e.shiftKey) {
e.preventDefault();
generateSuggestions();
}
});
// 页面加载完成后的初始化
document.addEventListener('DOMContentLoaded', () => {
// 设置默认占位符
suggestionsContainer.innerHTML = '<div class="placeholder">请输入变量描述,然后点击生成按钮获取所有命名规范的建议</div>';
});
// 导出函数供HTML调用
window.copyToClipboard = copyToClipboard;
window.generateSuggestions = generateSuggestions;

View File

@@ -0,0 +1,365 @@
/* 全局样式重置 */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
/* 主体样式 */
body {
font-family: 'Microsoft YaHei', '微软雅黑', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
padding: 20px;
color: #333;
line-height: 1.6;
}
/* 容器样式 */
.container {
max-width: 700px;
margin: 0 auto;
background: rgba(255, 255, 255, 0.95);
border-radius: 20px;
padding: 30px;
box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
backdrop-filter: blur(10px);
}
/* 头部样式 */
.header {
text-align: center;
margin-bottom: 30px;
}
.title {
font-size: 2.5rem;
color: #4a5568;
margin-bottom: 10px;
font-weight: 300;
letter-spacing: 2px;
}
.subtitle {
color: #718096;
font-size: 1rem;
margin-bottom: 20px;
}
/* 表单样式 */
.form-section {
margin-bottom: 30px;
}
.form-group {
margin-bottom: 25px;
}
.form-label {
display: block;
margin-bottom: 8px;
font-weight: 500;
color: #4a5568;
font-size: 1rem;
}
.form-input {
width: 100%;
padding: 15px;
border: 2px solid #e2e8f0;
border-radius: 12px;
font-size: 1rem;
transition: all 0.3s ease;
background: #f7fafc;
font-family: inherit;
}
.form-input:focus {
outline: none;
border-color: #667eea;
background: #fff;
box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}
.textarea {
resize: vertical;
min-height: 120px;
}
.select {
cursor: pointer;
appearance: none;
background-image: url('data:image/svg+xml;charset=US-ASCII,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 4 5"><path fill="%23666" d="M2 0L0 2h4zm0 5L0 3h4z"/></svg>');
background-repeat: no-repeat;
background-position: right 15px center;
background-size: 12px;
padding-right: 40px;
}
/* 按钮样式 */
.btn {
width: 100%;
padding: 15px;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
border: none;
border-radius: 12px;
font-size: 1.1rem;
font-weight: 500;
cursor: pointer;
transition: all 0.3s ease;
margin-bottom: 25px;
}
.btn:hover {
transform: translateY(-2px);
box-shadow: 0 10px 25px rgba(102, 126, 234, 0.3);
}
.btn:active {
transform: translateY(0);
}
.btn:disabled {
opacity: 0.6;
cursor: not-allowed;
transform: none;
}
/* 结果区域样式 */
.result-section {
margin-top: 30px;
}
.result-title {
font-size: 1.3rem;
color: #4a5568;
margin-bottom: 15px;
text-align: center;
font-weight: 500;
}
.loading {
display: none;
text-align: center;
color: #667eea;
font-style: italic;
padding: 20px;
}
.suggestions-container {
background: #f7fafc;
border: 2px solid #e2e8f0;
border-radius: 12px;
padding: 20px;
min-height: 150px;
}
.placeholder {
text-align: center;
color: #a0aec0;
font-style: italic;
padding: 40px 20px;
}
/* 分组标题样式 */
.convention-group-title {
font-size: 1.1rem;
font-weight: 600;
color: #4a5568;
margin: 20px 0 10px 0;
padding: 8px 12px;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
border-radius: 8px;
text-align: center;
}
.convention-group-title:first-child {
margin-top: 0;
}
/* 建议项样式 */
.suggestion-item {
background: #fff;
border: 1px solid #e2e8f0;
border-radius: 8px;
padding: 15px;
margin-bottom: 10px;
transition: all 0.2s ease;
cursor: pointer;
position: relative;
}
.suggestion-item:hover {
border-color: #667eea;
box-shadow: 0 2px 8px rgba(102, 126, 234, 0.1);
}
.suggestion-item:last-child {
margin-bottom: 0;
}
.variable-name {
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
font-size: 1.1rem;
font-weight: 600;
color: #2d3748;
margin-bottom: 5px;
}
.variable-description {
font-size: 0.9rem;
color: #718096;
line-height: 1.4;
}
.copy-btn {
position: absolute;
top: 10px;
right: 10px;
background: #667eea;
color: white;
border: none;
border-radius: 6px;
padding: 5px 10px;
font-size: 0.8rem;
cursor: pointer;
opacity: 0;
transition: opacity 0.2s ease;
}
.suggestion-item:hover .copy-btn {
opacity: 1;
}
.copy-btn:hover {
background: #5a67d8;
}
/* 错误样式 */
.error {
color: #e53e3e;
background: #fed7d7;
border: 1px solid #feb2b2;
padding: 15px;
border-radius: 8px;
margin-top: 15px;
}
/* 成功提示 */
.success-toast {
position: fixed;
top: 20px;
right: 20px;
background: #48bb78;
color: white;
padding: 12px 20px;
border-radius: 8px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
z-index: 1000;
opacity: 0;
transform: translateX(100%);
transition: all 0.3s ease;
}
.success-toast.show {
opacity: 1;
transform: translateX(0);
}
/* 响应式设计 */
@media (max-width: 768px) {
body {
padding: 10px;
}
.container {
padding: 20px;
margin: 10px;
}
.title {
font-size: 2rem;
}
.form-input {
padding: 12px;
}
.btn {
padding: 12px;
}
.suggestions-container {
padding: 15px;
}
.suggestion-item {
padding: 12px;
}
.copy-btn {
position: static;
opacity: 1;
margin-top: 8px;
width: 100%;
}
}
@media (max-width: 480px) {
.title {
font-size: 1.8rem;
letter-spacing: 1px;
}
.container {
padding: 15px;
}
.form-input {
padding: 10px;
}
.suggestion-item {
padding: 10px;
}
.variable-name {
font-size: 1rem;
}
.variable-description {
font-size: 0.85rem;
}
}
/* 动画效果 */
@keyframes fadeIn {
from {
opacity: 0;
transform: translateY(10px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
.suggestion-item {
animation: fadeIn 0.3s ease;
}
/* 加载动画 */
@keyframes pulse {
0%, 100% {
opacity: 1;
}
50% {
opacity: 0.5;
}
}
.loading {
animation: pulse 1.5s ease-in-out infinite;
}

View File

@@ -0,0 +1,56 @@
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>AI姓名评测</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="container">
<div class="header">
<h1 class="title">AI姓名评测</h1>
<p class="subtitle">智能分析姓名的稀有度、音韵美感与寓意内涵</p>
</div>
<div class="form-group">
<label class="form-label" for="nameInput">请输入姓名:</label>
<input
type="text"
id="nameInput"
class="form-input"
placeholder="请输入要分析的姓名,例如:张三、李雅婷、王子轩等..."
maxlength="10"
/>
</div>
<button id="analyzeBtn" class="btn">开始分析</button>
<div class="result-section">
<h3 class="result-title">分析结果</h3>
<div id="loading" class="loading">正在分析中,请稍候...</div>
<div id="resultContainer" class="result-container">
<div class="result-card">
<h4 class="card-title">稀有度评分</h4>
<div id="rarityScore" class="score-display">--%</div>
<div id="rarityDesc" class="score-desc">点击"开始分析"查看结果</div>
</div>
<div class="result-card">
<h4 class="card-title">音韵评价</h4>
<div id="phoneticScore" class="score-display">--%</div>
<div id="phoneticDesc" class="score-desc">点击"开始分析"查看结果</div>
</div>
<div class="result-card">
<h4 class="card-title">含义解读</h4>
<div id="meaningAnalysis" class="meaning-content">点击"开始分析"查看姓名的深层寓意</div>
</div>
</div>
</div>
</div>
<script src="script.js"></script>
</body>
</html>

View File

@@ -0,0 +1,291 @@
// GitHub API 配置
const GITHUB_TOKEN = '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';
const endpoint = 'https://models.github.ai/inference/chat/completions';
const model = 'deepseek/DeepSeek-V3-0324';
// 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');
// 专业的姓名分析提示词
const createNameAnalysisPrompt = (name) => {
return `你是一位专业的姓名学专家和语言学家,请对输入的姓名进行全面分析。请直接输出分析结果,不要包含任何思考过程或<think>标签。
姓名:${name}
请按照以下格式严格输出分析结果:
【稀有度评分】
评分X%
评价:[对稀有度的详细说明,包括姓氏和名字的常见程度分析]
【音韵评价】
评分X%
评价:[对音韵美感的分析,包括声调搭配、读音流畅度、音律和谐度等]
【含义解读】
[详细分析姓名的寓意内涵,包括:
1. 姓氏的历史渊源和文化背景
2. 名字各字的含义和象征
3. 整体姓名的寓意组合
4. 可能体现的父母期望或文化内涵
5. 与传统文化、诗词典故的关联等]
要求:
1. 评分必须是1-100的整数百分比要有明显区分度避免雷同
2. 分析要专业、客观、有依据,评分要根据实际情况有所差异
3. 含义解读要详细深入至少150字
4. 严格按照上述格式输出,不要添加思考过程、<think>标签或其他内容
5. 如果是生僻字或罕见姓名,要特别说明
6. 直接输出最终结果,不要显示推理过程`;
};
// 解析AI返回的分析结果
function parseAnalysisResult(content) {
const result = {
rarityScore: '--%',
rarityDesc: '解析失败',
phoneticScore: '--%',
phoneticDesc: '解析失败',
meaningAnalysis: '解析失败'
};
try {
// 过滤掉DeepSeek的思考标签内容
let cleanContent = content.replace(/<think>[\s\S]*?<\/think>/gi, '');
cleanContent = cleanContent.replace(/<think>[\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, '<strong>$1</strong>');
parsed = parsed.replace(/__(.*?)__/g, '<strong>$1</strong>');
// 处理斜体 *text* 或 _text_
parsed = parsed.replace(/\*(.*?)\*/g, '<em>$1</em>');
parsed = parsed.replace(/_(.*?)_/g, '<em>$1</em>');
// 处理无序列表
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('<ul>');
inList = true;
}
// 移除开头的 "- " 并包装为 <li>
const listContent = line.replace(/^-\s+/, '');
result.push(`<li>${listContent}</li>`);
} else {
if (inList) {
result.push('</ul>');
inList = false;
}
if (line) {
result.push(line);
}
}
}
// 如果最后还在列表中,需要关闭列表
if (inList) {
result.push('</ul>');
}
// 重新组合,用 <br> 连接非列表行
parsed = result.join('<br>');
// 清理多余的 <br> 标签(在列表前后)
parsed = parsed.replace(/<br><ul>/g, '<ul>');
parsed = parsed.replace(/<\/ul><br>/g, '</ul>');
parsed = parsed.replace(/<br><li>/g, '<li>');
parsed = parsed.replace(/<\/li><br>/g, '</li>');
return parsed;
}
// 更新显示结果
function updateResults(result) {
rarityScore.textContent = result.rarityScore;
rarityDesc.innerHTML = parseMarkdown(result.rarityDesc);
phoneticScore.textContent = result.phoneticScore;
phoneticDesc.innerHTML = parseMarkdown(result.phoneticDesc);
meaningAnalysis.innerHTML = parseMarkdown(result.meaningAnalysis);
}
// 重置结果显示
function resetResults() {
rarityScore.textContent = '--%';
rarityDesc.innerHTML = '点击"开始分析"查看结果';
phoneticScore.textContent = '--%';
phoneticDesc.innerHTML = '点击"开始分析"查看结果';
meaningAnalysis.innerHTML = '点击"开始分析"查看姓名的深层寓意';
}
// 显示错误信息
function showError(message) {
// 清除之前的错误信息
const existingError = document.querySelector('.error');
if (existingError) {
existingError.remove();
}
// 创建新的错误信息
const errorDiv = document.createElement('div');
errorDiv.className = 'error';
errorDiv.textContent = `分析失败:${message}`;
document.querySelector('.result-section').appendChild(errorDiv);
}
// 姓名验证
function validateName(name) {
if (!name) {
return '请输入姓名';
}
if (name.length < 2) {
return '姓名至少需要2个字符';
}
if (name.length > 10) {
return '姓名不能超过10个字符';
}
if (!/^[\u4e00-\u9fa5a-zA-Z]+$/.test(name)) {
return '姓名只能包含中文或英文字符';
}
return null;
}
// 主要分析函数
async function analyzeName() {
const name = nameInput.value.trim();
// 验证输入
const validationError = validateName(name);
if (validationError) {
alert(validationError);
return;
}
// 显示加载状态
analyzeBtn.disabled = true;
analyzeBtn.textContent = '分析中...';
loading.style.display = 'block';
resetResults();
// 清除之前的错误信息
const existingError = document.querySelector('.error');
if (existingError) {
existingError.remove();
}
const requestBody = {
model: model,
messages: [{
role: "user",
content: createNameAnalysisPrompt(name)
}],
temperature: 0.7,
max_tokens: 1000
};
try {
const response = await fetch(endpoint, {
method: 'POST',
headers: {
'Accept': 'application/vnd.github+json',
'Authorization': `Bearer ${GITHUB_TOKEN}`,
'X-GitHub-Api-Version': '2022-11-28',
'Content-Type': 'application/json'
},
body: JSON.stringify(requestBody)
});
// 检查HTTP状态码
if (response.status === 429) {
throw new Error('短时间内请求次数过多,请休息一下!');
}
if (!response.ok) {
throw new Error(`请求失败: ${response.status} ${response.statusText}`);
}
const data = await response.json();
if (data?.choices?.[0]?.message?.content) {
const analysisResult = parseAnalysisResult(data.choices[0].message.content.trim());
updateResults(analysisResult);
} else {
throw new Error('AI响应格式异常');
}
} catch (error) {
console.error('分析姓名时出错:', error);
showError(error.message);
resetResults();
} finally {
// 恢复按钮状态
analyzeBtn.disabled = false;
analyzeBtn.textContent = '开始分析';
loading.style.display = 'none';
}
}
// 事件监听器
analyzeBtn.addEventListener('click', analyzeName);
// 回车键快捷分析
nameInput.addEventListener('keypress', (e) => {
if (e.key === 'Enter') {
e.preventDefault();
analyzeName();
}
});
// 输入框内容变化时清除错误信息
nameInput.addEventListener('input', () => {
const existingError = document.querySelector('.error');
if (existingError) {
existingError.remove();
}
});

View File

@@ -0,0 +1,249 @@
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Microsoft YaHei', '微软雅黑', Arial, sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
padding: 20px;
color: #333;
}
.container {
max-width: 700px;
margin: 0 auto;
background: rgba(255, 255, 255, 0.95);
border-radius: 20px;
padding: 30px;
box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
backdrop-filter: blur(10px);
}
.header {
text-align: center;
margin-bottom: 30px;
}
.title {
font-size: 2.5rem;
color: #4a5568;
margin-bottom: 10px;
font-weight: 300;
letter-spacing: 2px;
}
.subtitle {
color: #718096;
font-size: 1rem;
margin-bottom: 20px;
}
.form-group {
margin-bottom: 25px;
}
.form-label {
display: block;
margin-bottom: 8px;
font-weight: 500;
color: #4a5568;
font-size: 1rem;
}
.form-input {
width: 100%;
padding: 15px;
border: 2px solid #e2e8f0;
border-radius: 12px;
font-size: 1rem;
transition: all 0.3s ease;
background: #f7fafc;
text-align: center;
}
.form-input:focus {
outline: none;
border-color: #667eea;
background: #fff;
box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}
.btn {
width: 100%;
padding: 15px;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
border: none;
border-radius: 12px;
font-size: 1.1rem;
font-weight: 500;
cursor: pointer;
transition: all 0.3s ease;
margin-bottom: 25px;
}
.btn:hover {
transform: translateY(-2px);
box-shadow: 0 10px 25px rgba(102, 126, 234, 0.3);
}
.btn:active {
transform: translateY(0);
}
.btn:disabled {
opacity: 0.6;
cursor: not-allowed;
transform: none;
}
.result-section {
margin-top: 30px;
}
.result-title {
font-size: 1.3rem;
color: #4a5568;
margin-bottom: 20px;
text-align: center;
font-weight: 500;
}
.loading {
display: none;
text-align: center;
color: #667eea;
font-style: italic;
margin-bottom: 20px;
}
.result-container {
display: grid;
gap: 20px;
grid-template-columns: 1fr;
}
.result-card {
background: #f7fafc;
border: 2px solid #e2e8f0;
border-radius: 12px;
padding: 20px;
transition: all 0.3s ease;
}
.result-card:hover {
border-color: #667eea;
box-shadow: 0 5px 15px rgba(102, 126, 234, 0.1);
}
.card-title {
font-size: 1.1rem;
color: #4a5568;
margin-bottom: 15px;
text-align: center;
font-weight: 600;
}
.score-display {
font-size: 2.5rem;
font-weight: bold;
text-align: center;
margin-bottom: 10px;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
}
.score-desc {
text-align: center;
color: #718096;
font-size: 0.9rem;
line-height: 1.5;
}
.meaning-content {
color: #2d3748;
line-height: 1.8;
font-size: 1rem;
text-align: left;
white-space: pre-wrap;
}
.error {
color: #e53e3e;
background: #fed7d7;
border: 1px solid #feb2b2;
padding: 15px;
border-radius: 8px;
margin-top: 15px;
}
/* 平板和桌面端优化 */
@media (min-width: 768px) {
.result-container {
grid-template-columns: 1fr 1fr;
}
.result-card:last-child {
grid-column: 1 / -1;
}
}
/* 手机端优化 */
@media (max-width: 768px) {
body {
padding: 10px;
}
.container {
padding: 20px;
margin: 10px;
}
.title {
font-size: 2rem;
}
.form-input {
padding: 12px;
}
.btn {
padding: 12px;
}
.result-card {
padding: 15px;
}
.score-display {
font-size: 2rem;
}
}
@media (max-width: 480px) {
.title {
font-size: 1.8rem;
letter-spacing: 1px;
}
.container {
padding: 15px;
}
.result-card {
padding: 12px;
}
.score-display {
font-size: 1.8rem;
}
.meaning-content {
font-size: 0.9rem;
}
}

View File

@@ -0,0 +1,12 @@
1.写一个静态网页来调用github model 来完成应用功能
2.网页清新风格颜色随意app风格适配手机端和电脑端优先优化手机端用户体验
3.默认github的调用密钥是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
4.默认调用AI模型为 "openai/gpt-4o-mini"
5.把jscsshtml分开储存每个功能分每个模块避免单个文件过大问题
6.默认github ai调用模型地址是'https://models.github.ai/inference/chat/completions'
比如这样:
// GitHub API 配置
const GITHUB_TOKEN = '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';
const endpoint = 'https://models.github.ai/inference/chat/completions';
const model = 'deepseek/DeepSeek-V3-0324';