// ==UserScript== // @name MS-Docs Language-Toggle // @version 1 // @grant none // @include https://learn.microsoft.com/* // ==/UserScript==
const localLang = "de-DE"; const defaultLang = "en-US";
if (document.location.pathname.toLowerCase().startsWith(/${localLang.toLowerCase()}/
)) {
addLangButton(localLang, defaultLang);
} else if (document.location.pathname.toLowerCase().startsWith(/${defaultLang.toLowerCase()}/
)) {
addLangButton(defaultLang, localLang);
}
function addLangButton(origLang, targetLang) {
const switchLangButton = document.createElement("A");
switchLangButton.innerText = targetLang.toUpperCase();
switchLangButton.href = /${targetLang}/${document.location.pathname.substr(
/${origLang}/.length)}
;
switchLangButton.className = "button button-sm button-primary button-filled";
switchLangButton.style = "position: fixed; margin: 10px; bottom: 0; right: 0;";
document.body.appendChild(switchLangButton);
}