Greasy Fork

Greasy Fork is available in English.

微软URL重定向工具

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

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         微软URL重定向工具
// @namespace    http://tampermonkey.net/
// @version      1.3
// @description  如果打开的连接是非中文,则自动跳转到中文版
// @author       九零
// @license      MIT
// @match        https://*.microsoft.com/*
// @exclude      https://docs.microsoft.com/*/answers/*
// @exclude      https://learn.microsoft.com/*/answers/*
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    let url = window.location.href;
    var reg = new RegExp("(https://\\S*.microsoft.com)/(en-us|zh-hk|zh-tw)/", "ig");
    let result = reg.exec(url);
    if (result == null) {
        return;
    }

    window.document.write("<div style='text-align:center;font-size: 30px;margin-top: 30px;color: #B6895A;'>" + "准备为您跳转到中文版" + "</div>");
    //原始路径,类似https://docs.microsoft.com/en-us/
    let srcPart = result[0];
    //去掉语言部分的路径,类似https://docs.microsoft.com
    let dstPart = result[1];

    //清除原始地址的头部
    url = url.replace(srcPart, "");

    //拼装中文版地址并跳转
    url = dstPart + "/zh-cn/" + url;

    window.location.href = url;
})();