RedirectChineseWikipedia

Force redirect Chinese Wikipedia from other locales to zh-cn (and also from mobile ver to desktop ver)

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         RedirectChineseWikipedia
// @name:zh-CN   中文维基重定向
// @namespace    https://zh.wikipedia.org
// @include      https://zh.wikipedia.org/wiki/*
// @include      https://zh.wikipedia.org/zh-hk/*
// @include      https://zh.wikipedia.org/zh-mo/*
// @include      https://zh.wikipedia.org/zh-tw/*
// @include      https://zh.wikipedia.org/zh-my/*
// @include      https://zh.wikipedia.org/zh-sg/*
// @include      https://zh.m.wikipedia.org/wiki/*
// @include      https://zh.m.wikipedia.org/zh-hk/*
// @include      https://zh.m.wikipedia.org/zh-mo/*
// @include      https://zh.m.wikipedia.org/zh-tw/*
// @include      https://zh.m.wikipedia.org/zh-my/*
// @include      https://zh.m.wikipedia.org/zh-sg/*
// @include      https://zh.m.wikipedia.org/zh-cn/*
// @version      0.3
// @description  Force redirect Chinese Wikipedia from other locales to zh-cn (and also from mobile ver to desktop ver)
// @description:zh-CN  重定向中文维基的其他版本(繁体中文等)到简体中文,同时重定向手机端页面到桌面端页面。
// @author       aisuneko
// @icon         https://zh.wikipedia.org/favicon.ico
// @license      MIT
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    let variants = ["wiki", "zh-hk", "zh-mo", "zh-tw","zh-my", "zh-sg"];
    let url = window.location.href;
    let desturl = url;
    let header = "zh.wikipedia.org/";
    let mobile_header = "zh.m.wikipedia.org/";
    if(url.search(mobile_header) != -1) desturl = url.replace(mobile_header, header);

    let target = header + "zh-cn";
    for(let i = 0; i < variants.length; i++){
        let searchstr = header + variants[i];
        if(url.search(searchstr) != -1){
            desturl = url.replace(searchstr, target);
            break;
        }
    }
    window.location.replace(desturl);
})();