Skip to content

Instantly share code, notes, and snippets.

@GuillaumeGomez
Last active February 20, 2019 14:52
Show Gist options
  • Save GuillaumeGomez/2ea6c5b496c2d7b5e66b6ece6d41e12c to your computer and use it in GitHub Desktop.
Save GuillaumeGomez/2ea6c5b496c2d7b5e66b6ece6d41e12c to your computer and use it in GitHub Desktop.
function jump_version() {
if (window.location.protocol === "file:" || window.location.host !== "doc.rust-lang.org") {
return;
}
var version = window.location.path.split("/")[0];
if (version === "std") {
version = "stable";
}
var pick_version = document.createElement("select");
for (var i = 0; i < VERSIONS.length; ++i) {
var entry = document.createElement("option");
entry.innerText = VERSIONS[i];
entry.value = VERSIONS[i];
if (VERSIONS[i] === version) {
entry.selected = true;
}
pick_version.append(entry);
}
pick_version.style.position = "fixed";
pick_version.style.right = "5px";
pick_version.style.bottom = "5px";
pick_version.style.border = "1px solid #ccc";
pick_version.style.borderRadius = "3px";
pick_version.style.borderRadius = "3px";
pick_version.style.backgroundColor = "#eee";
pick_version.style.padding = "4px";
pick_version.style.fontSize = "1.1em";
pick_version.onchange = function() {
var parts = window.location.path.split("/");
if (parts[0] !== "std") {
parts.shift();
}
window.location.path = this.value + "/" + parts.join("/");
};
document.body.appendChild(pick_version);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment