// lyrics_detail.js — 歌词详情页：复制 + 状态轮询
(function() {
    // Copy lyrics
    window.copyLyrics = function() {
        const box = document.getElementById('lyrics-box');
        if (!box) return;
        navigator.clipboard.writeText(box.textContent).then(() => {
            alert('已复制到剪贴板');
        });
    };

    // Poll status if not finished
    const badge = document.getElementById('status-badge');
    if (!badge) return;
    const status = badge.textContent.trim();
    if (status === 'completed' || status === 'failed') return;

    const STATUS_URL = badge.dataset.statusUrl;

    const timer = setInterval(async () => {
        try {
            const resp = await fetch(STATUS_URL);
            const data = await resp.json();
            badge.textContent = data.status;
            badge.className = 'badge badge-' + data.status;
            if (data.status === 'completed' || data.status === 'failed') {
                clearInterval(timer);
                location.reload();
            }
        } catch {}
    }, 3000);
})();
