-
-
Save lettucebo/75f05f94b7ee2dace41b5ec06b6bf022 to your computer and use it in GitHub Desktop.
MS Learn 文件快速中英切換
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name 中英快速切換 - CN | |
// @namespace http://tampermonkey.net/ | |
// @version 0.2 | |
// @description MS Learn 文件中英文切換 | |
// @author You | |
// @match https://learn.microsoft.com/*/* | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=microsoft.com | |
// @downloadURL https://gist.githubusercontent.com/lettucebo/75f05f94b7ee2dace41b5ec06b6bf022/raw/548ae23f363124b5226d6c01181e1abe470f8574/ms-learn-lang-switch-cn.js | |
// @updateURL https://gist.githubusercontent.com/lettucebo/75f05f94b7ee2dace41b5ec06b6bf022/raw/548ae23f363124b5226d6c01181e1abe470f8574/ms-learn-lang-switch-cn.js | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
const m = location.href.match(/com\/(en-us|zh-cn)\//); | |
if (m) { | |
const isEn = m[1] == 'en-us'; | |
const style = document.createElement('style'); | |
style.innerHTML = ` | |
#lang-switch { | |
position:fixed;top:6px;right:6px;z-index:999;opacity:0.3;cursor:pointer; | |
padding:2px 6px;background-color:cadetblue;color:white;font-size:11pt; | |
} | |
#lang-switch:hover { | |
opacity: 1; | |
} | |
`; | |
document.head.appendChild(style); | |
const div = document.createElement('div'); | |
div.innerText = isEn ? '簡' : 'EN'; | |
div.id = 'lang-switch'; | |
div.onclick = function() { | |
const toUrl = location.toString().replace(/com\/(en-us|zh-cn)\//, `com/${(isEn ? 'zh-cn' : 'en-us')}/`); | |
location.href = toUrl; | |
}; | |
document.body.appendChild(div); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment