Greasy Fork镜像 支持简体中文。

微软文档语言切换

微软文档快捷语言切换按钮

  1. // ==UserScript==
  2. // @name 微软文档语言切换
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.1
  5. // @description 微软文档快捷语言切换按钮
  6. // @author iron2han
  7. // @match *://learn.microsoft.com/*
  8. // @icon https://www.google.com/s2/favicons?domain=tampermonkey.net
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (function () {
  13. 'use strict';
  14.  
  15. window.addEventListener('load', function () {
  16. let lang = getCurrentLang();
  17.  
  18. if (lang == null) {
  19. return;
  20. }
  21.  
  22. let xpathResult = document.evaluate('//*[@id="ms--secondary-nav"]//div[@class="buttons"]', document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null)
  23.  
  24. if (xpathResult.snapshotLength == 0) {
  25. return;
  26. }
  27.  
  28. let ele = xpathResult.snapshotItem(0);
  29.  
  30. lang = lang.toLowerCase();
  31.  
  32. if (lang != 'zh-cn') {
  33. ele.appendChild(createZHCNElement())
  34. }
  35.  
  36. if (lang != 'en-us') {
  37. ele.appendChild(createENUSElement())
  38. }
  39.  
  40. }, false);
  41. })();
  42.  
  43. function createENUSElement() {
  44. let div = document.createElement('div');
  45.  
  46. div.style = "margin-left: 5px";
  47.  
  48. let url = replaceUrl('en-us');
  49.  
  50. div.innerHTML = `<a data-test-id="navbar-primary-cta" class="button button-sm button-primary button-filled margin-right-none" href="${url}" data-bi-name="secondary-nav-cta-primary-download-dotnet">
  51. 切换到英文
  52. </a>`;
  53.  
  54. return div;
  55. }
  56.  
  57.  
  58. function createZHCNElement() {
  59. let div = document.createElement('div');
  60.  
  61. div.style = "margin-left: 5px";
  62.  
  63. let url = replaceUrl('zh-cn');
  64.  
  65. div.innerHTML = `<a data-test-id="navbar-primary-cta" class="button button-sm button-primary button-filled margin-right-none" href="${url}" data-bi-name="secondary-nav-cta-primary-download-dotnet">
  66. 切换到中文
  67. </a>`;
  68.  
  69. return div;
  70. }
  71.  
  72. function replaceUrl(lang) {
  73. let currentLang = getCurrentLang();
  74.  
  75. if (currentLang == null) {
  76. return location.href;
  77. }
  78.  
  79. return location.href.replace(currentLang, lang);
  80. }
  81.  
  82. function getCurrentLang() {
  83. let match = this.location.href.match('com\/([a-zA-Z]{2,2}\-[a-zA-Z]{2,2})\/');
  84.  
  85. if (match == null) {
  86. return null;
  87. }
  88.  
  89. let lang = match[1];
  90. return lang;
  91. }

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址