Android 开发者镜像站重定向

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

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 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);
}