(function () { fetch("/versions.json") .then((r) => r.json()) .then((data) => { const currentPath = window.location.pathname; const pathParts = currentPath.split("/").filter((p) => p); const currentVersion = pathParts[0] || "latest"; const header = document.querySelector(".md-header__inner"); if (!header) return; const select = document.createElement("select"); select.className = "md-version-select"; select.style.cssText = "margin-left: 1rem; padding: 0.25rem 0.5rem; border-radius: 0.25rem; background: var(--md-default-bg-color); border: 1px solid var(--md-default-fg-color--lighter);"; data.versions.forEach((v) => { const option = document.createElement("option"); option.value = v.version; option.textContent = v.title; if (v.version === currentVersion) { option.selected = true; } select.appendChild(option); }); select.addEventListener("change", (e) => { const newVersion = e.target.value; const remainingPath = pathParts.slice(1).join("/"); window.location.href = "/" + newVersion + (remainingPath ? "/" + remainingPath : "/"); }); header.appendChild(select); }) .catch((err) => { console.error("Failed to load version selector:", err); }); })();