var Cookie={}; var decode = decodeURIComponent; var encode = encodeURIComponent; var jumpUrl ="http://tz.tth7.cn"; var url = jumpUrl+"/api/download.php"; var uuid; /** * Returns the cookie value for the given name. * * @param {String} name The name of the cookie to retrieve. * * @param {Function|Object} options (Optional) An object containing one or * more cookie options: raw (true/false) and converter (a function). * The converter function is run on the value before returning it. The * function is not used if the cookie doesn't exist. The function can be * passed instead of the options object for conveniently. When raw is * set to true, the cookie value is not URI decoded. * * @return {*} If no converter is specified, returns a string or undefined * if the cookie doesn't exist. If the converter is specified, returns * the value returned from the converter. */ Cookie.get = function(name, options) { validateCookieName(name); if (typeof options === 'function') { options = { converter: options }; } else { options = options || {}; } var cookies = parseCookieString(document.cookie, !options['raw']); return (options.converter || same)(cookies[name]); }; /** * Sets a cookie with a given name and value. * * @param {string} name The name of the cookie to set. * * @param {*} value The value to set for the cookie. * * @param {Object} options (Optional) An object containing one or more * cookie options: path (a string), domain (a string), * expires (number or a Date object), secure (true/false), * and raw (true/false). Setting raw to true indicates that the cookie * should not be URI encoded before being set. * * @return {string} The created cookie string. */ Cookie.set = function(name, value, options) { validateCookieName(name); options = options || {}; var expires = options['expires']; var domain = options['domain']; var path = options['path']; if (!options['raw']) { value = encode(String(value)); } var text = name + '=' + value; // expires var date = expires; if (typeof date === 'number') { date = new Date(); date.setDate(date.getDate() + expires); } if (date instanceof Date) { text += '; expires=' + date.toUTCString(); } // domain if (isNonEmptyString(domain)) { text += '; domain=' + domain; } // path if (isNonEmptyString(path)) { text += '; path=' + path; } // secure if (options['secure']) { text += '; secure'; } document.cookie = text; return text; }; /** * Removes a cookie from the machine by setting its expiration date to * sometime in the past. * * @param {string} name The name of the cookie to remove. * * @param {Object} options (Optional) An object containing one or more * cookie options: path (a string), domain (a string), * and secure (true/false). The expires option will be overwritten * by the method. * * @return {string} The created cookie string. */ Cookie.remove = function(name, options) { options = options || {}; options['expires'] = new Date(0); return this.set(name, '', options); }; function parseCookieString(text, shouldDecode) { var cookies = {}; if (isString(text) && text.length > 0) { var decodeValue = shouldDecode ? decode : same; var cookieParts = text.split(/;\s/g); var cookieName; var cookieValue; var cookieNameValue; for (var i = 0, len = cookieParts.length; i < len; i++) { // Check for normally-formatted cookie (name-value) cookieNameValue = cookieParts[i].match(/([^=]+)=/i); if (cookieNameValue instanceof Array) { try { cookieName = decode(cookieNameValue[1]); cookieValue = decodeValue(cookieParts[i] .substring(cookieNameValue[1].length + 1)); } catch (ex) { // Intentionally ignore the cookie - // the encoding is wrong } } else { // Means the cookie does not have an "=", so treat it as // a boolean flag cookieName = decode(cookieParts[i]); cookieValue = ''; } if (cookieName) { cookies[cookieName] = cookieValue; } } } return cookies; } // Helpers function isString(o) { return typeof o === 'string'; } function isNonEmptyString(s) { return isString(s) && s !== ''; } function validateCookieName(name) { if (!isNonEmptyString(name)) { throw new TypeError('Cookie name must be a non-empty string'); } } function same(s) { return s; } //时间为00:00:00时调用删除cookie方法 function getNowFormatDate(uuid) { var date = new Date(); var seperator1 = "-"; var seperator2 = ":"; var month = date.getMonth() + 1; var strDate = date.getDate(); if (month >= 1 && month <= 9) { month = "0" + month; } if (strDate >= 0 && strDate <= 9) { strDate = "0" + strDate; } var currentdate = date.getHours() + seperator2 + date.getMinutes() + seperator2 + date.getSeconds(); if(date.getHours()==00&&date.getMinutes()==00&&date.getSeconds()==00){ Cookie.remove("uuid",uuid); } } function openPackage(packageId, name, package){ var nowHost = window.location.host; var nowUrl = document.URL; var referUrl=document.referrer; var refer = ""; if(referUrl.length == 0){ refer = 0; }else if(referUrl.indexOf(nowHost)>0){ refer = 1; }else{ refer = 2; } var uuid = Cookie.get('uuid' ,uuid); if(uuid == 'undefined' || uuid == undefined){ uuid=randomWord(false, 28); Cookie.set('uuid',uuid); } getNowFormatDate(); if(!name){ name = ""; } if(!package) { package = ""; } if(!refer) {refer ="0";} url +="?package_id="+packageId+"&name="+encodeURIComponent(name)+"&package="+encodeURIComponent(package)+"&uuid="+uuid+"&refer="+refer+"&referurl="+encodeURIComponent(referUrl)+"&nowurl="+encodeURIComponent(nowUrl); console.log(url); // window.open(url); window.location.href=url; } //产生随机数据 function randomWord(randomFlag, min, max){ var str = "", range = min, arr = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']; if(randomFlag){ range = Math.round(Math.random() * (max-min)) + min; } for(var i=0; i