${escapeHTML(item.label)}
${escapeHTML(item.meta)} · ${escapeHTML(item.size)}
获取安装包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]) => `
${escapeHTML(item.meta)} · ${escapeHTML(item.size)}${escapeHTML(item.label)}
${escapeHTML(doc.summary)}
${escapeHTML(doc.content)}