var domains = {
  "apkmirror.com": 1,
  "appledaily.com": 1,
  "artstation.com": 1,
  "bbc.com": 1,
  "disqus.com": 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,
  "imgur.com": 1,
  "instagram.com": 1,
  "i.pximg.net": 1,
  "kobo.com": 1,
  "mega.io": 1,
  "mega.nz": 1,
  "nicovideo.jp": 1,
  "nyaa.si": 1,
  "nytimes.com": 1,
  "nyt.com": 1,
  "phncdn.com": 1,
  "pinterest.com": 1,
  "pixiv.net": 1,
  "quora.com": 1,
  "redd.it": 1,
  "reddit.com": 1,
  "redditmedia.com": 1,
  "startpage.com": 1,
  "steamcommunity.com": 1,
  "thetvdb.com": 1,
  "tumblr.com": 1,
  "tumblr.co": 1,
  "uptodown.com": 1,
  "vimeo.com": 1,
  "wenxuecity.com": 1,
  "wikipedia.org": 1,
  "mediawiki.org": 1,
  "wikiquote.org": 1,
  "wikinews.org": 1,
  "wikiversity.org": 1,
  "wiktionary.org": 1,
  "wikibooks.org": 1,
  "wikivoyage.org": 1,
  "wikisource.org": 1,
  "wikidata.org": 1,
  "singlelogin.re": 1,
  "singlelogin.se": 1,
  "archive.org": 1,
  "amazon.co.jp": 1,
  "discord.com": 1,
  "discordapp.com": 1,
  "discord.gg": 1,
  "duckduckgo.com": 1,
  "v2ex.com": 1,
  "twitch.tv": 1,
  "scratch.mit.edu": 1,
  "bandcamp.com": 1,
  "mastodon.social": 1
};

var shexps = {
  "*://onedrive.live.com/*": 1,
  "*://*.bbc.co.uk/*": 1,
  "*://*.bbci.co.uk/*": 1,
  "*://*.japantimes.co.jp/*": 1,
  "*://search.yahoo.co.jp/*": 1,
  "*://*.cna.com.tw/*": 1,
  "*://media.discordapp.net/*": 1,
  "*://*.dmc.nico/*": 1,
  "*://*.pixivsketch.net/*": 1,
  "*://*.githubassets.com/*": 1,
  "*://*.githubusercontent.com/*": 1,
  "*://*.redditstatic.com/*": 1
};

var proxy = "PROXY {{host}}:{{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);
    }
}
