Android 开发者镜像站重定向

Android 开发者谷歌官方网站自动跳转到无需穿墙的镜像站。

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Android 开发者镜像站重定向
// @name:en      Android Developer Chinese Version
// @namespace
// @version      1.0
// @description  Android 开发者谷歌官方网站自动跳转到无需穿墙的镜像站。
// @description:en Go to developer.android.google.cn when visit developer.android.com in China.
// @author       LEORChn
// @match        http*://developer.android.com/*
// @match        http*://link.zhihu.com/*
// @match        http*://www.jianshu.com/*
// @run-at       document-start
// @grant        none
// @namespace https://greasyfork.org/users/159546
// ==/UserScript==
var hf=location.href;
var reg=hf.split('=http');
var newwindow=false;
(function() {
    //alert('detect: '+hf);//知乎的鼠标事件捕捉不到,但是可以加载一点数据,就用读图模式。简书可以抓鼠标事件,就用光标模式
    if(location.host==='developer.android.com') {//源墙站 自跳转,但无法在未加载的情况下跳转。以抢读模式支持
        jump();
    }else if(reg.length==2){//知乎、 ,以抢读模式支持
        prepare();
    }
    if(location.host==='www.jianshu.com'){//简书 ,以光标模式支持
        window.addEventListener('mousedown', function(e){
            //alert(e);
            hf=e.target.toString();//此处的target并非String对象所以需要toString
            reg=hf.split('=http');//hf被重载,所以reg也要一起重载
            newwindow=true;
            if(hf.startsWith('http'))prepare();
        },true);
    }
})();

function prepare(){
    //alert(hf);
    hf= hf.replace(reg[0]+'=','');
    hf= decodeURIComponent(hf);
    //alert(hf);
    jump();
}

function jump(){
    hf=hf.replace('developer.android.com','developer.android.google.cn');
    //alert('-> '+hf);
    if(newwindow) window.open(hf);
    else location.replace(hf);
}