(function addThemePicker() { const rightButtonsElement = document.querySelector('.right-buttons'); rightButtonsElement.insertAdjacentHTML("afterbegin", ` `); const language = document.documentElement.getAttribute("lang"); let langToggle = document.getElementById("language-toggle"); let langList = document.getElementById("language-list"); langToggle.addEventListener("click", (event) => { langList.style.display = langList.style.display == "block" ? "none" : "block"; }); let selectedLang = document.getElementById(language); if (selectedLang) { selectedLang.parentNode.classList.add("theme-selected"); } // The path to the root, taking the current language into account. let full_path_to_root = language == "en" ? `${mdbookPathToRoot}` : `${mdbookPathToRoot}../`; // The page path (mdbook only gives us access to the path to the Markdown file). let path = mdbookPath.replace(/\.md$/, ".html"); for (let lang of langList.querySelectorAll("a")) { if (lang.id == "en") { lang.href = `${full_path_to_root}${path}`; } else { lang.href = `${full_path_to_root}${lang.id}/${path}`; } } })();