MSDN语言切换

切换MSDN文档的中英语言版版本(switch Chinese/English language in MSDN)

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         MSDN语言切换
// @namespace    https://github.com/maidouofgithub
// @version      0.2.1
// @description  切换MSDN文档的中英语言版版本(switch Chinese/English language in MSDN)
// @author       landwind
// @match        https://docs.microsoft.com/*
// ==/UserScript==

(function() {
    'use strict';

    Init();

    function  Init()
    {
        AppendButton();
    }

    function AppendButton()
    {

        console.log('will append language switch button!');
        let url = location.href;
        var a = document.createElement('a');
        a.style.cssText =  'background-color:#66CC99;text-align:center;opacity:0.7;color:white;cursor:pointer;position:fixed;bottom:70%;width:45px;height:25px;right:10px;z-index:9999';
        a.innerHTML ='中/英';
        a.addEventListener('click', function(){
            if (url.indexOf('en-us')> -1){
                window.location.replace(url.replace('en-us','zh-cn'));
            }
           else if (url.indexOf('zh-cn') >= -1){
                window.location.replace(url.replace('zh-cn','en-us'));
            }
        }, false );
        document.body.appendChild(a);
    }
})();