// 添加单个URL async function addSingleUrl() { const url = document.getElementById('singleUrl').value.trim(); if (!url) { showToast('请输入链接', 'error'); return; } try { const response = await fetch(`${API_BASE}/api/urls`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ url }) }); const data = await response.json(); if (data.success) { showToast('添加成功', 'success'); document.getElementById('singleUrl').value = ''; } else { showToast(data.message || '添加失败', 'error'); } } catch (error) { showToast('添加失败: ' + error.message, 'error'); } } // 批量添加URL async function addBatchUrls() { const text = document.getElementById('batchUrls').value.trim(); if (!text) { showToast('请输入链接', 'error'); return; } const urls = text.split('\n').map(u => u.trim()).filter(u => u); if (urls.length === 0) { showToast('请输入有效链接', 'error'); return; } try { const response = await fetch(`${API_BASE}/api/urls`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ urls }) }); const data = await response.json(); if (data.success) { showToast(`成功添加 ${data.added_count}/${data.total_count} 个链接`, 'success'); document.getElementById('batchUrls').value = ''; } else { showToast(data.message || '添加失败', 'error'); } } catch (error) { showToast('添加失败: ' + error.message, 'error'); } }