var domains = {
  "apkmirror.com": 1,
  "appledaily.com": 1,
  "archiveofourown.org": 1,
  "artstation.com": 1,
  "bbc.com": 1,
  "disqus.com": 1,
  "dmc.nico": 1,
  "dropbox.com": 1,
  "dropboxapi.com": 1,
  "dropbox-dns.com": 1,
  "dw.com": 1,
  "e-hentai.org": 1,
  "epochtimes.com": 1,
  "euronews.com": 1,
  "exhentai.org": 1,
  "ftchinese.com": 1,
  "github.com": 1,
  "githubassets.com": 1,
  "githubusercontent.com": 1,
  "imgur.com": 1,
  "instagram.com": 1,
  "i.pximg.net": 1,
  "kobo.com": 1,
  "medium.com": 1,
  "mega.nz": 1,
  "nicovideo.jp": 1,
  "nyaa.si": 1,
  "nytimes.com": 1,
  "phncdn.com": 1,
  "pinterest.com": 1,
  "pixiv.net": 1,
  "pornhub.com": 1,
  "quora.com": 1,
  "redd.it": 1,
  "reddit.com": 1,
  "redditmedia.com": 1,
  "redditstatic.com":1,
  "startpage.com": 1,
  "steamcommunity.com": 1,
  "theepochtimes.com": 1,
  "thetvdb.com": 1,
  "tumblr.com": 1,
  "tumblr.co": 1,
  "uptodown.com": 1,
  "vimeo.com": 1,
  "wenxuecity.com": 1,
  "wikipedia.org": 1
};

var shexps = {
  "*://steamcommunity-a.akamaihd.net/*": 1,
  "*://steamuserimages-a.akamaihd.net/*": 1,
  "*://*.amazon.co.jp/*": 1,
  "*://*onedrive.live.com/*": 1,
  "*://*.bbc.co.uk/*": 1,
  "*://*.bbci.co.uk/*": 1,
  "*://*.japantimes.co.jp/*": 1,
  "*://*.yahoo.co.jp/*": 1,
  "*://*.cna.com.tw/*": 1
};

var proxy = "PROXY 127.0.0.1:{{port}};";

var direct = 'DIRECT;';

var hasOwnProperty = Object.hasOwnProperty;

function shExpMatchs(str, shexps) {
    for (shexp in shexps) {
        if (shExpMatch(str, shexp)) {
            return true;
        }
    }
    return false;
}

function FindProxyForURL(url, host) {
    var suffix;
    var pos = host.lastIndexOf('.');
    pos = host.lastIndexOf('.', pos - 1);
    while(1) {
        if (pos <= 0) {
            if (hasOwnProperty.call(domains, host)) {
                return proxy;
            } else if (shExpMatchs(url, shexps)) {
                return proxy;
            } else {
                return direct;
            }
        }
        suffix = host.substring(pos + 1);
        if (hasOwnProperty.call(domains, suffix)) {
            return proxy;
        }
        pos = host.lastIndexOf('.', pos - 1);
    }
}
