document.addEventListener('DOMContentLoaded', function() { const downloadLink = document.getElementById('download-ts'); let preloadedDownloadLinks = null; // 预加载的 JSON 数据缓存(新增) // 移动设备检测函数 const isMobile = function() { return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent); }; // 平台检测函数 const getPlatform = function() { if (/Win/i.test(navigator.platform)) { return 'windows'; } else if (/Mac/i.test(navigator.platform)) { return 'macos'; } else if (/Linux/i.test(navigator.platform)) { return 'linux'; } else { return 'other'; } }; // 创建弹窗的完整函数 const createModal = function(content) { const modal = document.createElement('div'); modal.className = 'download-modal'; modal.innerHTML = [ '
' ].join(''); document.body.appendChild(modal); setTimeout(function() { modal.classList.add('visible'); }, 10); const closeModal = function() { modal.classList.remove('visible'); setTimeout(function() { modal.remove(); }, 300); }; modal.querySelector('.close-btn').addEventListener('click', closeModal); modal.addEventListener('click', function(event) { if (event.target === modal) { closeModal(); } }); return modal; }; // 预加载 JSON 数据(新增) fetch('https://file-us.ovofish.com/local_download_links.json') .then(function(response) { if (!response.ok) { throw new Error('预加载失败:网络响应不正常'); } return response.json(); }) .then(function(data) { preloadedDownloadLinks = data; // 缓存预加载数据 }) .catch(function(error) { console.error('预加载下载链接失败:', error); // 预加载失败不影响后续逻辑,用户点击时会重新请求 }); if (downloadLink) { downloadLink.addEventListener('click', function(event) { event.preventDefault(); // 移动设备处理 if (isMobile()) { createModal([ '🚫 暂不支持移动端下载
', '请使用桌面设备访问:
', '' ].join('')); return; } // 桌面设备处理(修改:优先使用预加载数据) const platform = getPlatform(); const dataSource = preloadedDownloadLinks || fetch('https://file-us.ovofish.com/local_download_links.json'); // 优先使用缓存 // 若预加载成功,直接使用缓存数据;否则重新请求 if (preloadedDownloadLinks) { handleDownload(preloadedDownloadLinks, platform); } else { fetch('https://file-us.ovofish.com/local_download_links.json') .then(function(response) { if (!response.ok) { throw new Error('网络响应不正常'); } return response.json(); }) .then(function(data) { handleDownload(data, platform); }) .catch(function(error) { console.error('获取下载链接失败:', error); if (error.message.includes('CORS')) { createModal([ '无法获取下载链接,可能是服务器配置问题,请稍后再试或联系管理员。
' ].join('')); } window.open('https://teamspeak.com/en/downloads/', '_blank'); }); } // 提取下载逻辑为独立函数(新增) function handleDownload(data, platform) { const modalContent = [ '