微軟文檔中英切換

在微軟文檔中切換中文 / 英文

目前為 2017-12-24 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name MicrosoftDocsSwitchingLanguage
  3. // @name:zh-CN 微软文档中英切换
  4. // @name:zh-TW 微軟文檔中英切換
  5. // @description switch Chinese/English language in Microsoft docs websites.
  6. // @description:zh-CN 在微软文档中切换中文 / 英文
  7. // @description:zh-TW 在微軟文檔中切換中文 / 英文
  8. // @author dangoron
  9. // @contributor ladit
  10. // @version 1.2.0
  11. // @namespace https://greasyfork.org/zh-CN/scripts/33209
  12. // @homepageURL https://github.com/ladit/Userscripts
  13. // @supportURL https://github.com/ladit/Userscripts
  14. // @grant none
  15.  
  16. // @match http*://msdn.microsoft.com/en-us/*
  17. // @match http*://msdn.microsoft.com/zh-cn/*
  18. // @match http*://docs.microsoft.com/en-us/*
  19. // @match http*://docs.microsoft.com/zh-cn/*
  20. // ==/UserScript==
  21.  
  22. var switcher = document.createElement('li');
  23. switcher.innerHTML = '<a href="#">中文 / English 切换</a>';
  24. var actionList = document.querySelector('.action-list');
  25. actionList.insertBefore(switcher, actionList.firstElementChild);
  26.  
  27. switcher.firstElementChild.addEventListener('click', function () {
  28. if (document.URL.search(/\/en-us\//) != -1) {
  29. window.location.replace(location.href.replace(/\/en-us\//, '\/zh-cn\/'));
  30. }
  31. if (document.URL.search(/\/zh-cn\//) != -1) {
  32. window.location.replace(location.href.replace(/\/zh-cn\//, '\/en-us\/'));
  33. }
  34. }, false);