微软文档中英切换

微软文档中英切换;switch Chinese/English language in Microsoft Docs.

当前为 2017-09-15 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name 微软文档中英切换
  3. // @namespace https://microsoft.com/
  4. // @version 0.1
  5. // @description 微软文档中英切换;switch Chinese/English language in Microsoft Docs.
  6. // @author dangoron
  7. // @contributor ladit
  8. // @match http*://msdn.microsoft.com/en-us/*
  9. // @match http*://msdn.microsoft.com/zh-cn/*
  10. // @match http*://docs.microsoft.com/en-us/*
  11. // @match http*://docs.microsoft.com/zh-cn/*
  12. // @grant none
  13. // ==/UserScript==
  14.  
  15. (function () {
  16. 'use strict';
  17.  
  18. var url = location.href;
  19. var a = document.createElement('span');
  20.  
  21. function create_button() {
  22. var css = 'opacity: 0.5;color: black;cursor: pointer;position: fixed;bottom: 80%;left: 24%;z-index: 9999;';
  23. a.style.cssText = css;
  24. a.innerHTML = '中文 / English 切换';
  25. a.addEventListener('mouseover', function () {
  26. a.style.opacity = 1;
  27. }, false);
  28. a.addEventListener('mouseout', function () {
  29. a.style.opacity = 0.3;
  30. }, false);
  31. a.addEventListener('click', function () {
  32. if (url.search(/\/en-us\//) != -1) {
  33. window.location.replace(url.replace(/\/en-us\//, '\/zh-cn\/'));
  34. }
  35. if (url.search(/\/zh-cn\//) != -1) {
  36. window.location.replace(url.replace(/\/zh-cn\//, '\/en-us\/'));
  37. }
  38. }, false);
  39. document.body.appendChild(a);
  40. }
  41. create_button();
  42. })();