window.globalConfig = {
    // jdShopUrls: {
    //     indexPageUrl: 'https://shop.jd.com',
    //     domain: 'shop.jd.com',
    //     venderInfoUrl: 'https://yj.shop.jd.com/api/vender/backs/info/jsonp?callback=jQuery183016760030131389825_{0}&_={1}',
    //     pType: 'jdClient'
    // },
    jdYmHttpServerUrls: {
        indexPageUrl: 'http://ym.shujymei.com/index.php?c=index&s=ymhome',
        domain: 'http://ym.shujymei.com',
        pType: 'jdYm'
    },
    jdYmHttpsServerUrls: {
        indexPageUrl: 'https://ym.shujymei.com/index.php?c=index&s=ymhome',
        domain: 'https://ym.shujymei.com',
        pType: 'jdYm'
    },
    jdPrintServerUrls: {
        indexPageUrl: 'http://jp.shujymei.com/index.php?c=index&s=ymhome',
        domain: 'jp.shujymei.com',
        pType: 'jdPrint'
    },
    xhsYmHttpServerUrls: {
        indexPageUrl: 'http://ym.xhs.shujymei.com/#/dashboard',
        domain: 'http://ym.xhs.shujymei.com',
        pType: 'xhsYm'
    },
    xhsYmHttpsServerUrls: {
        indexPageUrl: 'https://ym.xhs.shujymei.com/#/dashboard',
        domain: 'https://ym.xhs.shujymei.com',
        pType: 'xhsYm'
    },
    dyYmHttpsServerUrls: {
        indexPageUrl: 'http://ymdy.shujymei.com',
        domain: 'http://ymdy.shujymei.com',
        pType: 'dyYm'
    },
    parseVenderInfoUrl: 'http://116.198.44.110/parse_vender_info?session_key={0}',
    crawlItemUrl: 'http://116.198.44.110/collect/item',
    // parseVenderInfoUrl: 'http://127.0.0.1:8000/parse_vender_info?session_key={0}',
    // crawlItemUrl: 'http://127.0.0.1:8000/collect/item',

    platformIdNameMap: {
        0: 'taobao',
        1: 'tmall',
        2: '1688',
        3: 'jd',
        4: 'pdd'
    },
    loginUrlMaps: {
        'taobao': {
            platformName: '淘宝',
            url: 'https://login.taobao.com/member/login.jhtml'
        },
		'tmall': {
            platformName: '天猫',
            url: 'https://login.tmall.com'
        },
		'1688': {
            platformName: '1688',
            url: 'https://login.1688.com/member/signin.htm'
        },
		'jd': {
            platformName: '京东',
            url: 'https://passport.jd.com/uc/login'
        },
        'pdd': {
            platformName: '拼多多',
            url: 'http://mobile.yangkeduo.com/login.html'
        }
    },
    loginStatusCheckUrlMaps: {
        'taobao': {
            loginOutWords: '密码登录',
            regExpUserName: /_nk_=(.*?);|_nk_=(.*?)$/g,
            regExpUrl: /taobao.com/g,
            loginUrlRegExp: /taobao.com.*login/g,
            url:'https://buyertrade.taobao.com/trade/itemlist/list_bought_items.htm'
        },
		'tmall': {
            loginOutWords: '密码登录',
            regExpUserName: /_nk_=(.*?);|_nk_=(.*?)$/g,
            regExpUrl: /tmall|liangxinyao/g,
            loginUrlRegExp: /login.tmall.com/g,
            url:'https://buyertrade.taobao.com/trade/itemlist/list_bought_items.htm'
        },
		'1688': {
            loginOutWords: '请在此登录',
            regExpUserName: /c_lid=(.*?)\||; lid=(.*?);/g,
            regExpUrl: /1688.com/g,
            loginUrlRegExp: /1688.com.*signin/g,
            url:'https://trade.1688.com/order/buyer_order_list.htm'
        },
		'jd': {
            loginOutWords: '账户登录',
            regExpUserName: /unick=(.*?);|unick=(.*?)$/g,
            regExpUrl: /www.jd.com|item.*jd.com/g,
            loginUrlRegExp: /jd.com.*login/g,
            url:'https://order.jd.com/center/list.action'
        },
        'pdd': {
            loginOutWords: '<div id="main"></div>',
            regExpUserName: /class="nickname".*?>(.*?)</g,
            regExpUrl: /mobile.yangkeduo.com/g,
            loginUrlRegExp: /yangkeduo.com.*login.htm/g,
            url:'https://mobile.yangkeduo.com/personal.html'
        }
    }
};

function checkServerDomain() {
    var serverUrls = null;
    if (document.location.href.indexOf(window.globalConfig.jdPrintServerUrls.domain) > -1) {
        serverUrls = window.globalConfig.jdPrintServerUrls;
    } else if (document.location.href.indexOf(window.globalConfig.jdYmHttpServerUrls.domain) > -1) {
        serverUrls = window.globalConfig.jdYmHttpServerUrls;
    } else if (document.location.href.indexOf(window.globalConfig.jdYmHttpsServerUrls.domain) > -1) {
        serverUrls = window.globalConfig.jdYmHttpsServerUrls;
    } else if (document.location.href.indexOf(window.globalConfig.xhsYmHttpServerUrls.domain) > -1) {
        serverUrls = window.globalConfig.xhsYmHttpServerUrls;
    } else if (document.location.href.indexOf(window.globalConfig.xhsYmHttpsServerUrls.domain) > -1) {
        serverUrls = window.globalConfig.xhsYmHttpsServerUrls;
    } else if (document.location.href.indexOf(window.globalConfig.dyYmHttpsServerUrls.domain) > -1) {
        serverUrls = window.globalConfig.dyYmHttpsServerUrls;
    }


    chrome.runtime.sendMessage({type: 'getBackgroundCacheValue', key: 'serverUrls'},  function (value) {
        if (!serverUrls && !value) {
            serverUrls = window.globalConfig.jdShopUrls;    //默认配置
        }
        console.log(serverUrls);
        serverUrls && chrome.runtime.sendMessage({type: 'setBackgroundCacheValue', key: 'serverUrls', value: serverUrls});
    });
}
checkServerDomain();
