微软URL重定向工具

如果打开的连接是非中文,则自动跳转到中文版

  1. // ==UserScript==
  2. // @name 微软URL重定向工具
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.3
  5. // @description 如果打开的连接是非中文,则自动跳转到中文版
  6. // @author 九零
  7. // @license MIT
  8. // @match https://*.microsoft.com/*
  9. // @exclude https://docs.microsoft.com/*/answers/*
  10. // @exclude https://learn.microsoft.com/*/answers/*
  11. // @grant none
  12. // ==/UserScript==
  13.  
  14. (function () {
  15. 'use strict';
  16.  
  17. let url = window.location.href;
  18. var reg = new RegExp("(https://\\S*.microsoft.com)/(en-us|zh-hk|zh-tw)/", "ig");
  19. let result = reg.exec(url);
  20. if (result == null) {
  21. return;
  22. }
  23.  
  24. window.document.write("<div style='text-align:center;font-size: 30px;margin-top: 30px;color: #B6895A;'>" + "准备为您跳转到中文版" + "</div>");
  25. //原始路径,类似https://docs.microsoft.com/en-us/
  26. let srcPart = result[0];
  27. //去掉语言部分的路径,类似https://docs.microsoft.com
  28. let dstPart = result[1];
  29.  
  30. //清除原始地址的头部
  31. url = url.replace(srcPart, "");
  32.  
  33. //拼装中文版地址并跳转
  34. url = dstPart + "/zh-cn/" + url;
  35.  
  36. window.location.href = url;
  37. })();

QingJ © 2025

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