MSDN切换中英文按钮

在MSDN文档的左上角加一个快速切换中英文的按钮

  1. // ==UserScript==
  2. // @name MSDN切换中英文按钮
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description 在MSDN文档的左上角加一个快速切换中英文的按钮
  6. // @author You
  7. // @match https://docs.microsoft.com/*
  8. // @icon https://www.google.com/s2/favicons?domain=microsoft.com
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14. var href = window.location.href;
  15. var div = document.createElement('div');
  16. var button = document.createElement('button');
  17.  
  18.  
  19. if(href.includes('/en-us/')){
  20. button.innerText = '中文';
  21. button.onclick = () => {
  22. var url = window.location.href;
  23. var zh = url.replace("/en-us/", "/zh-cn/");
  24. window.location.href = zh;
  25. };
  26. }
  27. else{
  28. button.onclick = () => {
  29. var url = window.location.href;
  30. var zh = url.replace(/.com\/[\w\-]+\//, ".com/en-us/");
  31. window.location.href = zh;
  32. };
  33. button.innerText = '英文';
  34. }
  35.  
  36.  
  37. div.style.position = 'fixed';
  38. div.style.top = '0';
  39. div.style.left = '0';
  40.  
  41. div.appendChild(button);
  42. document.body.appendChild(div);
  43. // Your code here...
  44. })();

QingJ © 2025

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