// 导出数据 document.getElementById('export').addEventListener('click', async () => { const { aliases } = await chrome.storage.local.get('aliases'); const blob = new Blob([JSON.stringify(aliases || {}, null, 2)], { type: 'application/json' }); const url = URL.createObjectURL(blob); const timestamp = new Date() .toLocaleString('sv-SE') // ISO-like 格式 .replace(' ', '_') .replace(/:/g, '-'); // 避免非法文件名 const a = document.createElement('a'); a.href = url; a.download = `teams-alias-${timestamp}.json`; a.click(); URL.revokeObjectURL(url); }); // 手动同步 document.getElementById('sync').addEventListener('click', async () => { const btn = document.getElementById('sync'); const originalText = btn.textContent; btn.textContent = '同步中...'; btn.disabled = true; try { if (typeof fetchAliasesFromDB !== 'function') { throw new Error("utils.js not loaded properly"); } const aliases = await fetchAliasesFromDB(); await chrome.storage.local.set({ aliases, lastSync: Date.now() }); alert(`同步成功!共获取 ${Object.keys(aliases).length} 条数据。`); } catch (error) { alert('同步失败,请检查网络或控制台日志。'); console.error(error); } finally { btn.textContent = originalText; btn.disabled = false; } });