var ssr = 'socks5 127.0.0.1:1080';
var ict = 'DIRECT';

var rules = [
    ".npupt.com",
    ".ipv6-test.com",
    ".chinapyg.com",
    ".webofknowledge.com",
    ".bilibili.com",
    ".isiknowledge.com",
    ".windowsazure.com",
    ".aspnetcdn.com",
    ".msecnd.net",
    ".12530.com",
    ".geetest.com",
    ".douyu.tv",
    ".douyu.com",
    ".speedtest.net",
    ".07073.com",
    ".0x110.com",
    ".10010.com",
    ".100tjs.com",
    ".100ye.com",
    ".114la.com",
    ".115.com",
    ".115img.com",
    ".120ask.com",
    ".123cha.com",
    ".126.com",
    ".126.net",
    ".1616.net",
    ".163.com",
    ".1717388.com",
    ".17173.com",
    ".1778.com",
    ".178.com",
    ".17cdn.com",
    ".17kuxun.com",
    ".17u.com",
    ".198game.com",
    ".19lou.com",
    ".1o26.com",
    ".1ting.com",
    ".1uuc.com",
    ".21cn.com",
    ".2345.com",
    ".24quan.com",
    ".265.com",
    ".265g.com",
    ".28.com",
    ".28tui.com",
    ".293.net",
    ".2hua.com",
    ".2mdn.net",
    ".315che.com",
    ".3366.com",
    ".360buy.com",
    ".360buyimg.com",
    ".360doc.com",
    ".360safe.com",
    ".360tl.com",
    ".36kr.com",
    ".37see.com",
    ".39.net",
    ".3dmgame.com",
    ".4399.com",
    ".4738.com",
    ".5000pk.com",
    ".500wan.com",
    ".5173.com",
    ".51auto.com",
    ".51buy.com",
    ".51.com",
    ".51cto.com",
    ".51fanli.com",
    ".51img1.com",
    ".51jobcdn.com",
    ".51job.com",
    ".51.la",
    ".51nb.com",
    ".51yes.com",
    ".52kmh.com",
    ".52pk.net",
    ".52tlbb.com",
    ".53kf.com",
    ".55bbs.com",
    ".55tuan.com",
    ".56.com",
    ".58.com",
    ".591hx.com",
    ".5d6d.com",
    ".5d6d.net",
    ".61.com",
    ".6dad.com",
    ".6rooms.com",
    ".701sou.com",
    ".70e.com",
    ".766.com",
    ".777wyx.com",
    ".778669.com",
    ".7c.com",
    ".7k7k.com",
    ".859652.com",
    ".88db.com",
    ".91.com",
    ".968tl.com",
    ".9787.com",
    ".99114.com",
    ".99bill.com",
    ".a135.net",
    ".a963.com",
    ".abang.com",
    ".abchina.com",
    ".acfun.tv",
    ".ad1111.com",
    ".admin5.com",
    ".adnxs.com",
    ".adobe.com",
    ".adroll.com",
    ".ads8.com",
    ".adsame.com",
    ".adsonar.com",
    ".adtechus.com",
    ".advon.net",
    ".aibang.com",
    ".aifang.com",
    ".aili.com",
    ".aipai.com",
    ".aizhan.com",
    ".ali213.net",
    ".alibaba.com",
    ".alicdn.com",
    ".aliexpress.com",
    ".aliimg.com",
    ".alimama.com",
    ".alipay.com",
    ".alipayobjects.com",
    ".alisoft.com",
    ".alivv.com",
    ".aliyun.com",
    ".aliyun-inc.com",
    ".allyes.com",
    ".anjuke.com",
    ".anzhi.com",
    ".aol.com",
    ".appgame.com",
    ".appinn.com",
    ".apple.com",
    ".arpg2.com",
    ".atdmt.com",
    ".atpanel.com",
    ".b2b168.com",
    ".babytree.com",
    ".baidu.com",
    ".baidupcs.com",
    ".baidustatic.com",
    ".baihe.com",
    ".baixing.com",
    ".bankcomm.com",
    ".baomihua.com",
    ".bdimg.com",
    ".bdstatic.com",
    ".bendibao.com",
    ".bestb2b.com",
    ".betrad.com",
    ".bilibili.tv",
    ".bing.com",
    ".bitauto.com",
    ".bjbus.com",
    ".blog.163.com",
    ".blogbus.com",
    ".blogchina.com",
    ".blueidea.com",
    ".bluekai.com",
    ".bokee.net",
    ".booksky.org",
    ".boosj.com",
    ".brothersoft.com",
    ".cache.netease.com",
    ".caing.com",
    ".caixin.com",
    ".ccb.com",
    ".ccidnet.com",
    ".cctv.com",
    ".cctvcom",
    ".cdn20.com",
    ".changyou.com",
    ".chdbits.org",
    ".chetx.com",
    ".chinabyte.com",
    ".china.com",
    ".chinahr.com",
    ".chinamobile.com",
    ".chinanews.com",
    ".chinaren.com",
    ".chinaunix.net",
    ".chinaw3.com",
    ".chinaz.com",
    ".chiphell.com",
    ".chuangelm.com",
    ".ci123.com",
    ".cmbchina.com",
    ".cn",
    ".cnbeta.com",
    ".cnblogs.com",
    ".cncn.com",
    ".cnepub.com",
    ".cnfol.com",
    ".cngba.com",
    ".cnhubei.com",
    ".cnki.net",
    ".cnmo.com",
    ".cntv.net",
    ".cnwest.com",
    ".cnxad.com",
    ".cnzz.com",
    ".cocoren.com",
    ".compete.com",
    ".comsenz.com",
    ".coo8.com",
    ".cqnews.net",
    ".cqtiyu.com",
    ".crsky.com",
    ".csdn.net",
    ".ct10000.com",
    ".ctrip.com",
    ".dangdang.com",
    ".daqi.com",
    ".dayoo.com",
    ".dbank.com",
    ".ddmap.com",
    ".dedecms.com",
    ".dh818.com",
    ".diandian.com",
    ".dianping.com",
    ".didatuan.com",
    ".dipan.com",
    ".discuz.net",
    ".doc88.com",
    ".docin.com",
    ".donews.com",
    ".dospy.com",
    ".douban.com",
    ".douban.fm",
    ".doubleclick.com",
    ".doubleclick.net",
    ".douyutv.com",
    ".dpfile.com",
    ".dream4ever.org",
    ".duapp.com",
    ".duba.net",
    ".duomi.com",
    ".duote.com",
    ".duowan.com",
    ".dwstatic.com",
    ".dy2018.com",
    ".dytt8.net",
    ".dzwww.com",
    ".eastday.com",
    ".eastmoney.com",
    ".eb80.com",
    ".ebay.com",
    ".egou.com",
    ".ele.me",
    ".elemecdn.com",
    ".ellechina.com",
    ".elong.com",
    ".emarbox.com",
    ".ename.net",
    ".et8.org",
    ".etao.com",
    ".exam8.com",
    ".eye.rs",
    ".eyoudi.com",
    ".fantong.com",
    ".fastcdn.com",
    ".fastif.net",
    ".fat999.com",
    ".fblife.com",
    ".fengniao.com",
    ".fenzhi.com",
    ".ffdy.cc",
    ".fishlee.net",
    ".flickr.com",
    ".fobshanghai.com",
    ".ftchinese.com",
    ".ftuan.com",
    ".funshion.com",
    ".fx120.net",
    ".game3737.com",
    ".game3896.com",
    ".gamersky.com",
    ".gamestlbb.com",
    ".gamesville.com",
    ".gamewan.net",
    ".ganji.com",
    ".gaopeng.com",
    ".getfirebug.com",
    ".gfan.com",
    ".gfw.io",
    ".gfx.ms",
    ".ggmm777.com",
    ".go2map.com",
    ".gongchang.com",
    ".goodbabygroup.com",
    ".gougou.com",
    ".greencompute.org",
    ".gtimg.com",
    ".gy9y.com",
    ".gzmama.com",
    ".haliyuya.com",
    ".hao123.com",
    ".haodf.com",
    ".harrenmedianetwork.com",
    ".hc360.com",
    ".hdslb.com",
    ".hefei.cc",
    ".help.apple.com",
    ".hf365.com",
    ".hiapk.com",
    ".hichina.com",
    ".hi-pda.com",
    ".hlwan.net",
    ".homeinns.com",
    ".hoopchina.com",
    ".hotsales.net",
    ".house365.com",
    ".huaban.com",
    ".huanqiu.com",
    ".hudong.com",
    ".huochepiao.com",
    ".hupu.com",
    ".iask.com",
    ".ibm.com",
    ".iciba.com",
    ".icson.com",
    ".idailyapp.com",
    ".ifeng.com",
    ".ifengimg.com",
    ".ifensi.com",
    ".ijinshan.com",
    ".iloveyouxi.com",
    ".im286.com",
    ".imanhua.com",
    ".img.cctvpic.com",
    ".img-space.com",
    ".imrworldwide.com",
    ".inc.gs",
    ".infzm.com",
    ".invitemedia.com",
    ".ip138.com",
    ".ipinyou.com",
    ".iqilu.com",
    ".iqiyi.com",
    ".irs01.com",
    ".irs01.net",
    ".is686.com",
    ".it168.com",
    ".iteye.com",
    ".itgeeker.net",
    ".ithome.com",
    ".iweek.ly",
    ".iyaya.com",
    ".james520.com",
    ".jandan.net",
    ".jb51.net",
    ".jd.com",
    ".jiathis.com",
    ".jiatx.com",
    ".jiayuan.com",
    ".jiepang.com",
    ".jijinb.com",
    ".jing.fm",
    ".jinti.com",
    ".jiuyaoyouxi.com",
    ".jjwxc.net",
    ".jomodns.com",
    ".joqoo.com",
    ".jqw.com",
    ".jstv.com",
    ".jumei.com",
    ".junshijia.com",
    ".jxedt.com",
    ".jysq.net",
    ".kaixin001.com",
    ".kandian.com",
    ".kandian.net",
    ".kanimg.com",
    ".kankan.com",
    ".kdnet.net",
    ".keyunzhan.com",
    ".kimiss.com",
    ".koudai8.com",
    ".ku6cdn.com",
    ".ku6.com",
    ".ku6img.com",
    ".kuaidi100.com",
    ".kuaiwan.com",
    ".kuaizhan.com",
    ".kugou.com",
    ".l99.com",
    ".lady8844.com",
    ".lafaso.com",
    ".lampdrive.com",
    ".lashou.com",
    ".lashouimg.com",
    ".legolas-media.com",
    ".lehecai.com",
    ".leho.com",
    ".letao.com",
    ".letvcdn.com",
    ".letvcloud.com",
    ".letv.com",
    ".letvimg.com",
    ".liebiao.com",
    ".lietou.com",
    ".linezing.com",
    ".linkedin.com",
    ".local",
    ".localhost",
    ".logmein.com",
    ".lohas.ly",
    ".loli.mg",
    ".loli.vg",
    ".longhoo.net",
    ".love21cn.com",
    ".lusongsong.com",
    ".lvping.com",
    ".lxdns.com",
    ".lycos.com",
    ".lygo.com",
    ".m18.com",
    ".m1905.com",
    ".made-in-china.com",
    ".makepolo.com",
    ".mangocity.com",
    ".manzuo.com",
    ".mapabc.com",
    ".mapbar.com",
    ".mathtag.com",
    ".mediaplex.com",
    ".mediav.com",
    ".meilele.com",
    ".meilishuo.com",
    ".meishichina.com",
    ".meituan.com",
    ".meituan.net",
    ".meizu.com",
    ".miaozhen.com",
    ".mi.com",
    ".miercn.com",
    ".mlt01.com",
    ".mmstat.com",
    ".mnwan.com",
    ".mogujie.com",
    ".mookie1.com",
    ".moonbasa.com",
    ".mop.com",
    ".mosso.com",
    ".mozilla.org",
    ".mplife.com",
    ".msn.com",
    ".mtime.com",
    ".mumayi.com",
    ".my.cl.ly",
    ".mydrivers.com",
    ".nbweekly.com",
    ".net114.com",
    ".netease.com",
    ".neubt.com",
    ".newsmth.net",
    ".ngacn.cc",
    ".nipic.com",
    ".njobt.com",
    ".nowec.com",
    ".nuomi.com",
    ".oadz.com",
    ".oeeee.com",
    ".okbuy.com",
    ".okooo.com",
    ".onetad.com",
    ".onlinedown.net",
    ".onlylady.com",
    ".oschina.net",
    ".otwan.com",
    ".p5w.net",
    ".paipai.com",
    ".paipaiimg.com",
    ".paypal.com",
    ".pcbeta.com",
    ".pchome.net",
    ".pcpop.com",
    ".pengyou.com",
    ".php100.com",
    ".phpwind.net",
    ".pingan.com",
    ".pixlr.com",
    ".pkg.org",
    ".pp.cc",
    ".pplive.com",
    ".ppstream.com",
    ".pptv.com",
    ".ppurl.com",
    ".pr56789.com",
    ".pubmatic.com",
    ".q150.com",
    ".qhimg.com",
    ".qianlong.com",
    ".qianqian.com",
    ".qidian.com",
    ".qingdaonews.com",
    ".qiniucdn.com",
    ".qire123.com",
    ".qiushibaike.com",
    ".qiyi.com",
    ".qiyipic.com",
    ".qiyou.com",
    ".qjy168.com",
    ".qq937.com",
    ".qq.com",
    ".qqmail.com",
    ".qstatic.com",
    ".quantserve.com",
    ".qunar.com",
    ".qvbuy.com",
    ".rakuten.co.jp",
    ".ranwen.com",
    ".wentropy.com",
    ".readnovel.com",
    ".renren.com",
    ".rrimg.com",
    ".rtbidder.net",
    ".ruanmei.com",
    ".ruby-china.org",
    ".sanguosha.com",
    ".scanscout.com",
    ".scorecardresearch.com",
    ".sdo.com",
    ".seowhy.com",
    ".serving-sys.com",
    ".sf-express.com",
    ".sg560.com",
    ".shangdu.com",
    ".shuangtv.net",
    ".si.kz",
    ".sinaapp.com",
    ".sina.com",
    ".sinaedge.com",
    ".sinahk.net",
    ".sinaimg.com",
    ".sinajs.com",
    ".sj-tl.com",
    ".skycn.com",
    ".smzdm.com",
    ".snsfun.cc",
    ".snyu.com",
    ".sodu.org",
    ".sogou.com",
    ".sohu.com",
    ".soku.com",
    ".sootoo.com",
    ".soso.com",
    ".soufun.com",
    ".soufunimg.com",
    ".springer.com",
    ".staticsdo.com",
    ".stockstar.com",
    ".sttlbb.com",
    ".suning.com",
    ".synacast.com",
    ".szhome.com",
    ".sznews.com",
    ".tangdou.com",
    ".tanx.com",
    ".tao123.com",
    ".taobaocdn.com",
    ".taobao.com",
    ".tbcache.com",
    ".tdimg.com",
    ".tencent.com",
    ".tenpay.com",
    ".tgbus.com",
    ".thawte.com",
    ".theplanet.com",
    ".thethirdmedia.com",
    ".tiancity.com",
    ".tianji.com",
    ".tianyaui.com",
    ".tiao8.info",
    ".tiebaimg.com",
    ".tiexue.net",
    ".titan24.com",
    ".tlbb2.com",
    ".tlbb8.com",
    ".tlbbsifu.com",
    ".tmall.com",
    ".tom.com",
    ".toocle.com",
    ".tremormedia.com",
    ".tuan800.com",
    ".tudou.com",
    ".tudouui.com",
    ".tui18.com",
    ".tuniu.com",
    ".tvmao.com",
    ".twcczhu.com",
    ".u17.com",
    ".ucjoy.com",
    ".ulink.cc",
    ".umiwi.com",
    ".uniontoufang.com",
    ".up2c.com",
    ".upaiyun.com",
    ".uusee.com",
    ".uuu9.com",
    ".uuzu.com",
    ".vancl.com",
    ".vcimg.com",
    ".verycd.com",
    ".v.iask.com",
    ".vipshop.com",
    ".vizu.com",
    ".vjia.com",
    ".wandoujia.com",
    ".wdjimg.com",
    ".web887.com",
    ".weibo.com",
    ".weiphone.com",
    ".west263.com",
    ".whlongda.com",
    ".wikipedia.org",
    ".williamlong.info",
    ".woniu.com",
    ".wordpress.org",
    ".wrating.com",
    ".wsj.com",
    ".wumii.com",
    ".www.renren.com",
    ".xi666.com",
    ".xiachufang.com",
    ".xiami.com",
    ".xiami.net",
    ".xiaomi.com",
    ".xiaonei.com",
    ".xiazaiba.com",
    ".xici.net",
    ".xilu.com",
    ".xinhuanet.com",
    ".xinnet.com",
    ".xitek.com",
    ".xiu8.com",
    ".xiu.com",
    ".xiyou53.com",
    ".xiyou54.com",
    ".xlpan.com",
    ".xmfish.com",
    ".xn--fiqs8s",
    ".xp9365.com",
    ".xtltt.com",
    ".xungou.com",
    ".xunlei.com",
    ".xyxy.net",
    ".yaolan.com",
    ".ydstatic.com",
    ".yesky.com",
    ".yhd.com",
    ".yieldmanager.com",
    ".yihaodian.com",
    ".yihaodianimg.com",
    ".yingjiesheng.com",
    ".yintai.com",
    ".yinyuetai.com",
    ".yiqifa.com",
    ".yixun.com",
    ".yiyi.cc",
    ".ykimg.com",
    ".ynet.com",
    ".yocc.net",
    ".yoka.com",
    ".yolk7.com",
    ".youboy.com",
    ".youdao.com",
    ".yougou.com",
    ".youku.com",
    ".youshang.com",
    ".youwo123.com",
    ".yupoo.com",
    ".yxlady.com",
    ".yyets.com",
    ".zaobao.com",
    ".zaojiao.com",
    ".zbjimg.com",
    ".zdface.com",
    ".zdmimg.com",
    ".zhanqi.tv",
    ".zhaodao123.com",
    ".zhaopin.com",
    ".zhenai.com",
    ".zhibo8.cc",
    ".zhibo8.com",
    ".zhi.hu",
    ".zhihu.com",
    ".zhiimg.com",
    ".zhongsou.net",
    ".zhubajie.com",
    ".zjstv.com",
    ".zongheng.com",
    ".zoopda.com",
    ".zoosnet.net",
    ".zqgame.com",
    ".ztgame.com",
    ".zx915.com"
];

var academy = [
    ".ieee.org",
    ".acm.org"
];

function FindProxyForURL(url, host) {
    function check_ipv4() {
        // check if the ipv4 format (TODO: ipv6)
        //   http://home.deds.nl/~aeron/regex/
        var re_ipv4 = /^\d+\.\d+\.\d+\.\d+$/g;
        if (re_ipv4.test(host)) {
            // in theory, we can add chnroutes test here.
            // but that is probably too much an overkill.
            return true;
        }
        return false;
    }

    function check_ftp() {
        return (/^ftps?:\/\//.test(url));
    }

    function isDomain(domain) {
        var host_length, domain_length;
        return ((domain[0] === '.') ? (host === domain.slice(1) || ((host_length = host.length) >= (domain_length = domain.length) && host.slice(host_length - domain_length) === domain)) : (host === domain));
    }

    function rule_filter(callback) {
        // IMPORTANT: Respect the order of RULES.

        for (var i = 0; i < rules.length; i++) {
            if (callback(rules[i]) === true) {
                return true;
            }
        }
        return false;
    }

    function academy_filter(callback) {
        for (var i = 0; i < academy.length; i++) {
            if (callback(academy[i]) === true) {
                return true;
            }
        }
        return false;
    }

    // skip local hosts
    if (isPlainHostName(host) || check_ipv4() || check_ftp() || rule_filter(isDomain)) {
        // if (isPlainHostName(host) === true || check_ipv4() === true || rule_filter(isDomain) === true) {
        return "DIRECT";
    } else if (academy_filter(isDomain)) {
        return ict;
    } else {
        // if none of above cases, it is always safe to use the proxy
        // return la;
        return ssr;
    }
}
