Skip to content

Instantly share code, notes, and snippets.

@lettucebo
Last active March 28, 2024 00:52
Show Gist options
  • Save lettucebo/fa14fd6954dfa403c437d02010b9589f to your computer and use it in GitHub Desktop.
Save lettucebo/fa14fd6954dfa403c437d02010b9589f to your computer and use it in GitHub Desktop.
MS Learn 文件快速繁中英切換
// ==UserScript==
// @name 中英快速切換 - TW
// @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-tw.js
// @updateURL https://gist.githubusercontent.com/lettucebo/75f05f94b7ee2dace41b5ec06b6bf022/raw/548ae23f363124b5226d6c01181e1abe470f8574/ms-learn-lang-switch-tw.js
// @grant none
// ==/UserScript==
(function() {
'use strict';
const m = location.href.match(/com\/(en-us|zh-tw)\//);
if (m) {
const isEn = m[1] == 'en-us';
const style = document.createElement('style');
style.innerHTML = `
#lang-switch-tw {
position:fixed;top:40px;right:6px;z-index:999;opacity:0.3;cursor:pointer;
padding:2px 6px;background-color:cadetblue;color:white;font-size:11pt;
}
#lang-switch-tw:hover {
opacity: 1;
}
`;
document.head.appendChild(style);
const div = document.createElement('div');
div.innerText = isEn ? '繁' : 'EN';
div.id = 'lang-switch-tw';
div.onclick = function() {
const toUrl = location.toString().replace(/com\/(en-us|zh-tw)\//, `com/${(isEn ? 'zh-tw' : '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