const config = window.getRuyinConfig(); const icons = { windows: '', mac: '', linux: '' }; function escapeHTML(value = "") { return String(value).replace(/[&<>'"]/g, char => ({ "&": "&", "<": "<", ">": ">", "'": "'", '"': """ }[char])); } function showToast(message) { const toast = document.querySelector(".toast"); if (!toast) return; toast.textContent = message; toast.classList.add("show"); clearTimeout(window.__toastTimer); window.__toastTimer = setTimeout(() => toast.classList.remove("show"), 2400); } function platformKey() { const platform = (navigator.userAgentData?.platform || navigator.platform || "").toLowerCase(); if (platform.includes("mac")) return "mac"; if (platform.includes("linux")) return "linux"; return "windows"; } function bindDownload(link, data) { link.href = data?.url || "#"; if (!data?.url || data.url === "#") { link.addEventListener("click", event => { event.preventDefault(); showToast(`${data?.label || "此平台"} 下载链接暂未配置`); }); } } function renderHome() { const hero = document.querySelector("[data-home]"); if (!hero) return; document.querySelector("[data-headline]").textContent = config.product.headline; document.querySelector("[data-description]").textContent = config.product.description; document.querySelectorAll("[data-version]").forEach(el => el.textContent = config.product.version); const enabledDownloads = Object.entries(config.downloads).filter(([, item]) => item.enabled !== false); const detectedKey = platformKey(); const selectedKey = config.downloads[detectedKey]?.enabled !== false ? detectedKey : enabledDownloads[0]?.[0]; const selected = selectedKey ? config.downloads[selectedKey] : null; const primary = document.querySelector("[data-primary-download]"); if (selected) { primary.innerHTML = `${icons[selectedKey]}下载 ${escapeHTML(selected.label)} 版`; bindDownload(primary, selected); } else { primary.innerHTML = "暂无可用下载"; primary.removeAttribute("href"); primary.classList.add("disabled"); primary.setAttribute("aria-disabled", "true"); } const grid = document.querySelector("[data-download-grid]"); grid.innerHTML = enabledDownloads.length ? enabledDownloads.map(([key, item]) => `
${icons[key]}

${escapeHTML(item.label)}

${escapeHTML(item.meta)} · ${escapeHTML(item.size)}

获取安装包
`).join("") : '
下载通道正在维护中,请稍后再来。
'; grid.querySelectorAll("[data-download-key]").forEach(link => bindDownload(link, config.downloads[link.dataset.downloadKey])); } function renderDocs() { const list = document.querySelector("[data-docs-list]"); if (!list) return; const nav = document.querySelector("[data-docs-nav]"); if (!config.docs.length) { list.innerHTML = '
文档正在整理中。
'; nav.innerHTML = ""; return; } nav.innerHTML = config.docs.map((doc, index) => `${escapeHTML(doc.title)}`).join(""); list.innerHTML = config.docs.map(doc => `
${escapeHTML(doc.category)}

${escapeHTML(doc.title)}

${escapeHTML(doc.summary)}

${escapeHTML(doc.content)}

`).join(""); } function renderChangelog() { const timeline = document.querySelector("[data-changelog]"); if (!timeline) return; if (!config.changelog.length) { timeline.innerHTML = '
暂时没有更新记录。
'; return; } timeline.innerHTML = config.changelog.map(item => `
${escapeHTML(item.type)}

v${escapeHTML(item.version)}

`).join(""); } renderHome(); renderDocs(); renderChangelog(); window.addEventListener("storage", event => { if (event.key === window.RUYIN_CONFIG_KEY) location.reload(); });