blob: fb0a187f1633609d759e0be5d8df8440d50556d1 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
(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);
});
})();
|