extract-url.js 833 Bytes
/**
 * 提取URL中的参数
 * @author: xuqi<qi.xu@yoho.cn>
 * @date: 2015/11/19
 */

var opt = {};

var paramStr = window.location.search.split('?')[1];

var keyVal = paramStr.split('&');

var i, key, val;

for (i = keyVal.length; i > 0; i--) {
    key = keyVal[i - 1].split('=');

    val = key[1];
    key = key[0];

    //初始化默认参数
    opt[key] = val;

    //discount = p_d,同时需要两个参数
    if (key === 'discount' || key === 'p_d') {
        opt.discount = val;
        opt.p_d = val;
    }
}

if (typeof opt.gender === 'undefined') {
    switch (window.cookie('_Channel')) {
        case 'boys':
            opt.gender = '1,3';
            break;
        case 'girls':
            opt.gender = '2,3';
            break;
        default:
            opt.gender = '1,2,3';
    }
}

module.exports = opt;