MicrosoftDocLanguageSwitchButton

fix the language switch button in Microsoft Docs, set your expected language in the script data manually

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name                MicrosoftDocLanguageSwitchButton
// @name:zh-CN          微软文档语言切换按钮
// @name:zh-TW          微軟文檔語言切換按鈕
// @description         fix the language switch button in Microsoft Docs, set your expected language in the script data manually
// @description:zh-CN   修复微软文档中的语言切换按钮,在脚本数据中手动设置你期望的语言
// @description:zh-TW   修復微軟文檔中的語言切換按鈕,在腳本數據中手動設置你期望的語言
// @author              ladit
// @version             1.2.2
// @namespace           https://greasyfork.org/zh-CN/scripts/33209
// @homepageURL         https://github.com/ladit/Userscripts
// @supportURL          https://github.com/ladit/Userscripts

// @grant               GM.setValue
// @grant               GM.getValue
// @match               http*://learn.microsoft.com/en-us/*
// ==/UserScript==

(async () => {
  let userLanguage = await GM.getValue('language')
  if (!userLanguage) {
    userLanguage = navigator.language || navigator.userLanguage
    await GM.setValue('language', userLanguage)
  }

  const button = document.querySelector('#lang-link-tablet')
  const url = button.getAttribute('href').replace(/\/en-us\//, `/${userLanguage.toLowerCase()}/`)
  button.setAttribute('href', url)
  button.querySelector('.is-visually-hidden').textContent = `Read in ${userLanguage}`
  button.removeAttribute('hidden')
})()