var param={}; var link = window.location.href; var host = window.location.host; var referrer = trim(document.referrer); var titleName = document.title; var selfsrc = document.scripts[document.scripts.length - 1].src; param["host"]=host; param["rf"]=encodeUrl(referrer); param["rfk"]=getKeyword(referrer); param["url"]=encodeUrl(link); param["title"]=titleName; param["br"]=getBr(); param["scr"]=screen.width+"x"+screen.height; param["sys"]=getOS(); param["lang"]=getLan(); param["cid"]=req(selfsrc,"cid"); param["coid"]=req(selfsrc,"coid"); param["sid"]=req(selfsrc,"sid"); var dest = selfsrc.substring(0,selfsrc.indexOf("/common/stat.js")); dest = dest+"/stat?" stat(); function stat(){ var s = document.createElement("script"); s.src = dest+mergeParam(param); (document.getElementsByTagName("head")[0]||document.getElementsByTagName("body")[0]).appendChild(s); } function onOut(){ stat(); } var loadtime = new Date().getTime(); function KeepAlive(){ var t = new Date().getTime(); // console.log(t-loadtime); if(t-loadtime>60000){ loadtime = t; stat(); } } if(window.attachEvent){ window.attachEvent("onbeforeunload",onOut); document.attachEvent("onmousemove",KeepAlive); window.attachEvent("onscroll",KeepAlive); }else if(window.addEventListener){ window.addEventListener('beforeunload',onOut,false); document.addEventListener("mousemove",KeepAlive,false); window.addEventListener("scroll",KeepAlive,false); } function encodeUrl(str){ return encodeURI(str).replace(/=/g,"%3D").replace(/\+/g,"%2B").replace(/\?/g,"%3F").replace(/\&/g,"%26").replace(/\#/g,"%23"); } function mergeParam(map){ var sb = []; for(var prop in map){ if(map[prop]){ sb.push(prop+"="+trim(map[prop])); } } return sb.join("&"); } function trim(str){ return str.replace(/(^\s*)|(\s*$)/g,""); } function req(url, paras) { var paraString = url.substring(url.indexOf("?") + 1, url.length).split("&"); var paraObj = {} for (i = 0; j = paraString[i]; i++) { paraObj[j.substring(0, j.indexOf("=")).toLowerCase()] = j.substring(j.indexOf("=") + 1, j.length); } var returnValue = paraObj[paras.toLowerCase()]; if (typeof (returnValue) == "undefined") { return ""; } else { return returnValue; } } function getOS() { var ua = navigator.userAgent.toLowerCase(); isWin8 = ua.indexOf("nt 6.2") > -1 isWin7 = ua.indexOf("nt 6.1") > -1 isVista = ua.indexOf("nt 6.0") > -1 isWin2003 = ua.indexOf("nt 5.2") > -1 isWinXp = ua.indexOf("nt 5.1") > -1 isWin2000 = ua.indexOf("nt 5.0") > -1 isWindows = (ua.indexOf("windows") != -1 || ua.indexOf("win32") != -1) isMac = (ua.indexOf("macintosh") != -1 || ua.indexOf("mac os x") != -1) isAir = (ua.indexOf("adobeair") != -1) isLinux = (ua.indexOf("linux") != -1) isAndroid = ua.match(/android/i) === "android" isIpad = ua.match(/ipad/i) === "ipad" isIphoneOs = ua.match(/iphone os/i) === "iphone os" var broser = ""; if (isWin7) { sys = "Windows 7"; } else if (isWin8) { sys = "Windows 8"; } else if (isVista) { sys = "Vista"; } else if (isWinXp) { sys = "Windows XP"; } else if (isWin2003) { sys = "Windows 2003"; } else if (isWin2000) { sys = "Windows 2000"; } else if (isWindows) { sys = "Windows"; } else if (isMac) { sys = "Macintosh"; } else if (isAir) { sys = "Adobeair"; } else if (isLinux) { sys = "Linux"; } else if (isAndroid) { sys = "Android"; } else if (isIpad) { sys = "IPad"; } else if (isIphoneOs) { sys = "Iphone"; } else { sys = "其他"; } return sys; } function getBr() { var userAgent = navigator.userAgent, rMsie = /(msie\s|trident.*rv:)([\w.]+)/, rFirefox = /(firefox)\/([\w.]+)/, rOpera = /(opera).+version\/([\w.]+)/, rChrome = /(chrome)\/([\w.]+)/, rSafari = /version\/([\w.]+).*(safari)/; var browser; var version; var ua = userAgent.toLowerCase(); function uaMatch(ua){ var match = rMsie.exec(ua); if(match != null){ return { browser : "IE", version : match[2] || "0" }; } var match = rFirefox.exec(ua); if (match != null) { return { browser : match[1] || "", version : match[2] || "0" }; } var match = rOpera.exec(ua); if (match != null) { return { browser : match[1] || "", version : match[2] || "0" }; } var match = rChrome.exec(ua); if (match != null) { //chrome返回代号 return { browser : 'chrome' || "", version : "" }; } var match = rSafari.exec(ua); if (match != null) { return { browser : match[2] || "", version : match[1] || "0" }; } if (match != null) { return { browser : "", version : "0" }; } } var browserMatch = uaMatch(userAgent.toLowerCase()); if (browserMatch.browser){ browser = browserMatch.browser; version = browserMatch.version; } return (browser+version); } function getLan() { var lan = ''; if (navigator.systemLanguage != "undefined" && navigator.systemLanguage != null) { lan = navigator.systemLanguage; } else { lan = navigator.language; } var lang = lan.substr(0,2); if(lang == "zh"){ return "中文"; }else if(lang == "af"){ return "荷兰语"; }else if(lang == "sq"){ return "阿尔巴尼亚语"; }else if(lang == "er"){ return "阿拉伯语"; }else if(lang == "hy"){ return "亚美尼亚语"; }else if(lang == "az"){ return "阿塞拜疆语"; }else if(lang == "eu"){ return "巴斯克语"; }else if(lang == "bg"){ return "保加利亚语"; }else if(lang == "hr"){ return "克罗埃西亚语"; }else if(lang == "cs"){ return "捷克语"; }else if(lang == "en"){ return "英语"; }else if(lang == "et"){ return "爱沙尼亚语"; }else if(lang == "fr"){ return "法语"; }else if(lang == "de"){ return "德语"; }else if(lang == "it"){ return "意大利语"; }else if(lang == "ja"){ return "日语"; }else if(lang == "ko"){ return "韩语"; }else if(lang == "no"){ return "蒙语"; }else if(lang == "ru"){ return "俄语"; }else if(lang == "es"){ return "西班牙语"; }else if(lang == "th"){ return "泰语"; }else if(lang == "vi"){ return "越南语"; }else{ return lan.toLowerCase(); } } // 获取来自搜索引擎的关键词 function getKeyword(url) { if (url.toString().indexOf(".baidu.com") > 0) { return req(url, "wd"); } else if (url.toString().indexOf(".so.com") > 0 || url.toString().indexOf(".haosou.com") > 0 || url.toString().indexOf(".chinaso.com") > 0 || url.toString().indexOf(".youdao.com") > 0) { return req(url, "q"); } else if (url.toString().indexOf("google") > 0) { return req(url, "q"); } else if (url.toString().indexOf(".zhongsou.com") > 0) { return req(url, "w"); } else if (url.toString().indexOf(".sogou.com") > 0) { return req(url, "query"); } else if (url.toString().indexOf(".soso.com") > 0) { return req(url, "query"); } else { return ""; } }