</pre> </section> <!-- 下载区域 --> <div class="download-section"> <div class="download-buttons"> <button class="download-btn" onclick="downloadLyric('lrc')"> 📥 下载LRC歌词 </button> <button class="download-btn" style="background: linear-gradient(135deg, #81C784 0%, #66BB6A 100%);" onclick="downloadLyric('txt')"> 📄 下载TXT歌词 </button> </div> <p class="download-tip">支持卡拉OK同步显示,可用记事本编辑</p> </div> </div> <!-- 返回顶部按钮 --> <button class="back-to-top" onclick="scrollToTop()" title="返回顶部">↑</button> <script> // 歌词切换功能 function showLyric(type) { document.querySelectorAll('.lyric-section').forEach(section => { section.style.display = 'none'; }); document.querySelectorAll('.switch-btn').forEach(btn => { btn.classList.remove('active'); }); const targetSection = document.getElementById(`${type}-lyric`); if (targetSection) { targetSection.style.display = 'block'; event.target.classList.add('active'); } } // 复制歌词功能 async function copyLyric(sectionId) { const lyricSection = document.getElementById(sectionId); const lyricContent = lyricSection.querySelector('.lyric-content'); const copyBtn = lyricSection.querySelector('.copy-btn'); const originalText = copyBtn.innerHTML; const text = lyricContent.innerText; try { await navigator.clipboard.writeText(text); // 显示复制成功反馈 copyBtn.innerHTML = '<span>✅</span> 已复制'; copyBtn.classList.add('copied'); // 2秒后恢复原状 setTimeout(() => { copyBtn.innerHTML = originalText; copyBtn.classList.remove('copied'); }, 2000); } catch (err) { console.error('复制失败:', err); // 备用复制方法 const textArea = document.createElement('textarea'); textArea.value = text; document.body.appendChild(textArea); textArea.select(); try { document.execCommand('copy'); // 显示复制成功反馈 copyBtn.innerHTML = '<span>✅</span> 已复制'; copyBtn.classList.add('copied'); setTimeout(() => { copyBtn.innerHTML = originalText; copyBtn.classList.remove('copied'); }, 2000); } catch (err2) { console.error('备用复制方法也失败:', err2); alert('复制失败,请手动选择文本复制'); } document.body.removeChild(textArea); } } // 下载歌词功能 function downloadLyric(type) { let content = ''; let filename = ''; const songName = '洗澡(Live)'; const artistName = '林欣彤'; switch(type) { case 'lrc': content = document.querySelector('#lrc-lyric .lyric-content').innerText; filename = `${songName}-${artistName}.lrc`; break; case 'txt': content = document.querySelector('#plain-lyric .lyric-content').innerText; filename = `${songName}-${artistName}.txt`; break; case 'translated': content = document.querySelector('#translated-lyric .lyric-content').innerText; filename = `${songName}-${artistName}-翻译.txt`; break; default: return; } // 创建Blob对象 const blob = new Blob([content], { type: 'text/plain;charset=utf-8' }); // 创建下载链接 const url = URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; a.download = filename; document.body.appendChild(a); a.click(); // 清理 setTimeout(() => { document.body.removeChild(a); URL.revokeObjectURL(url); }, 100); } // 返回顶部功能 function scrollToTop() { window.scrollTo({ top: 0, behavior: 'smooth' }); } // 显示/隐藏返回顶部按钮 window.addEventListener('scroll', function() { const backToTopBtn = document.querySelector('.back-to-top'); if (window.pageYOffset > 300) { backToTopBtn.classList.add('show'); } else { backToTopBtn.classList.remove('show'); } }); // 页面加载完成后初始化 document.addEventListener('DOMContentLoaded', function() { // 确保纯歌词版本默认显示 showLyric('plain'); }); </script> </body></html>