(function() {
var PROTOCOL = window.location.protocol;
var HOSTNAME = window.location.hostname;
var PORT = window.location.port;
var PATHNAME = window.location.pathname;
const CURRENT_VERSION_MATCH = window.location.pathname.match(/\/([^\/]+?)\//g);
const potentialPaths = [
'versions.json',
'../versions.json',
'../../versions.json',
'/rxRust/versions.json',
'/versions.json'
];
function initVersionPicker(versions) {
var sidebar = document.querySelector('.sidebar');
if (!sidebar) return;
var container = document.createElement('div');
container.style.padding = '10px 15px';
container.style.textAlign = 'center';
container.style.borderBottom = '1px solid var(--border-color)';
container.style.backgroundColor = 'var(--sidebar-bg)';
container.style.position = 'sticky';
container.style.top = '0';
container.style.zIndex = '100';
container.className = 'version-picker-container';
var label = document.createElement('div');
label.textContent = 'Version:';
label.style.fontWeight = 'bold';
label.style.marginBottom = '5px';
label.style.fontSize = '0.9em';
label.style.color = 'var(--sidebar-fg)';
container.appendChild(label);
var select = document.createElement('select');
select.style.width = '100%';
select.style.padding = '5px';
select.style.borderRadius = '3px';
select.style.backgroundColor = 'var(--bg)';
select.style.color = 'var(--fg)';
select.style.border = '1px solid var(--border-color)';
select.style.cursor = 'pointer';
var currentPath = window.location.pathname;
var currentVersion = versions.find(v => currentPath.includes('/' + v.path + '/')) || versions[0];
versions.forEach(function(v) {
var option = document.createElement('option');
option.value = v.path;
option.textContent = v.name;
if (currentVersion && v.path === currentVersion.path) {
option.selected = true;
}
select.appendChild(option);
});
select.addEventListener('change', function(e) {
var targetVersion = e.target.value;
if (currentVersion) {
var newPath = currentPath.replace('/' + currentVersion.path + '/', '/' + targetVersion + '/');
window.location.href = newPath;
} else {
window.location.href = window.location.origin + window.location.pathname.split('/').slice(0, 2).join('/') + '/' + targetVersion + '/';
}
});
container.appendChild(select);
var scrollbox = sidebar.querySelector('.sidebar-scrollbox');
if (scrollbox) {
scrollbox.insertBefore(container, scrollbox.firstChild);
} else {
sidebar.insertBefore(container, sidebar.firstChild);
}
}
function fetchVersions(paths) {
if (paths.length === 0) return;
var path = paths.shift();
fetch(path)
.then(response => {
if (!response.ok) throw new Error("404");
return response.json();
})
.then(data => {
if (Array.isArray(data)) {
initVersionPicker(data);
}
})
.catch(err => {
fetchVersions(paths);
});
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', () => fetchVersions(potentialPaths));
} else {
fetchVersions(potentialPaths);
}
})();