1var glbEvents = {}; 2var glbStartTime = (new Date()).getTime(); 3var glbCurlPool = {}; 4 5function ajax_request(url, poststr, callback, async) { 6 if(async == null) { 7 async = true; 8 } 9 var xhr = null; 10 if(window.XMLHttpRequest){ 11 xhr = new XMLHttpRequest(); 12 } else { 13 xhr = new ActiveXObject('Microsoft.XMLHTTP'); 14 } 15 xhr.onreadystatechange = function() { 16 if(xhr.readyState == 4 && xhr.status == 200 && callback != null && typeof(callback) == "function") { 17 callback(xhr.responseText); 18 } 19 }; 20 xhr.open('POST', url, async); 21 //xhr.setRequestHeader("P3P", 'CP="CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR"'); 22 xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); 23 xhr.send(poststr); 24} 25 26function curl_request(url, getstr) { 27 if(getstr) { 28 if(url.indexOf("?") < 0) { 29 url += "?"; 30 } else { 31 url += "&"; 32 } 33 url += getstr; 34 } 35 var img = new Image(); 36 img.src = url; 37 glbCurlPool[url] = img; 38} 39 40var _statLog = (new (function() { 41 42 var log = {} 43 var self = this; 44 var isLogoutGame = false; 45 var resHostBak = ""; 46 var firstWaitTime = 500; 47 var options = [ 48 'Preloader', 49 'WinLoad', 50 'ActiveTime', 51 'TotalTime', 52 'Window', 53 'Screen', 54 'Zoom', 55 'Flash', 56 'ResHost', 57 'NodeIP1', 58 'ResTime1', 59 'NodeIP2', 60 'ResTime2', 61 'Remark' 62 ]; 63 var listeners = {}; 64 65 log.Start = (new Date()).getTime(); 66 log.UseTimes = 0; 67 68 function getWinWH(){ 69 var o = {} 70 if(window.innerWidth){ 71 o.w = window.innerWidth; 72 o.h = window.innerHeight; 73 }else{ 74 o.w = document.documentElement.clientWidth; 75 o.h = document.documentElement.clientHeight; 76 } 77 return o; 78 } 79 80 self.detectZoom = function() { 81 var ratio = 0, 82 screen = window.screen, 83 ua = navigator.userAgent.toLowerCase(); 84 85 if (window.devicePixelRatio !== undefined) { 86 ratio = window.devicePixelRatio; 87 } 88 else if (~ua.indexOf('msie')) { 89 if (screen.deviceXDPI && screen.logicalXDPI) { 90 ratio = screen.deviceXDPI / screen.logicalXDPI; 91 } 92 } else if (window.outerWidth !== undefined && window.innerWidth !== undefined) { 93 ratio = window.outerWidth / window.innerWidth; 94 } 95 96 if (ratio) { 97 ratio = Math.round(ratio * 100); 98 } 99 100 return ratio; 101 }; 102 self.addListener = function(event, listener) { 103 if(typeof(listener) != 'function') { 104 console.log("addListener event: "+event+", listener is not function: ", listener); 105 return; 106 } 107 if(!listeners[event]) { 108 listeners[event] = []; 109 } 110 listeners[event].push(listener); 111 }; 112 113 var win = getWinWH(); 114 log.Window = win.w+'x'+win.h; 115 log.Screen = window.screen.width+'x'+window.screen.height; 116 log.Zoom = self.detectZoom(); 117 118 window.onmouseover = function(){ 119 if(log.UseTimes > 0){ 120 log.FocusTimes = new Date().getTime(); 121 }else{ 122 log.FocusTimes = log.Start; 123 } 124 } 125 126 window.onmouseout = function(){ 127 log.BlurTimes = new Date().getTime(); 128 log.UseTimes = log.UseTimes+(log.BlurTimes - log.FocusTimes); 129 } 130 131 function sendLog(str,type){ 132 if(str == "") { 133 return; 134 } 135 var url = "//"+glbStatConfig.stat_host+"/stat/mystat.php"; 136 //ajax_request(url, str); 137 str += "&load_type=js"; 138 if(typeof(localStorage) == 'object') { 139 str += "&client_id="+localStorage.getItem("hpstat_client_id"); 140 } 141 str += "&js_time="+(new Date()).getTime(); 142 if(type == 'Preloader') { 143 asyncLoadJS(url + "?" + str); 144 } else { 145 curl_request(url, str); 146 } 147 } 148 149 function toJsonParam(){ 150 var arr =[],str = 'data='; 151 for(var k in options){ 152 k = options[k]; 153 if(log[k]){ 154 var s = '"'+k+'":"'+log[k]+'"'; 155 arr.push(s); 156 } 157 } 158 str+=encodeURIComponent('{'+arr.join(',')+'}'); 159 str+='&click_id='+glbStatConfig.click_id; 160 return str; 161 } 162 163 /** 164 * æµéåè½ 165 */ 166 self.speedResponse = function(res_id, client_ip, server_host) { 167 var time = (new Date()).getTime() - log.Start; 168 log['NodeIP'+res_id] = client_ip; 169 log['ResTime'+res_id] = time; 170 traceLog(server_host+time); 171 //0.5så ï¼ä¸»CDNè¿ååï¼ç«å³å¼å§å è½½ã0.5såï¼å å°è å ç¨ã 172 if(res_id == 1 || time > firstWaitTime) { 173 loadGame(res_id, server_host); 174 } else { 175 if(resHostBak == "") { 176 resHostBak = server_host; 177 setTimeout(function() { 178 loadGame(res_id, resHostBak); 179 }, firstWaitTime - time); //0.5s å¤ç¨CDNå å°ï¼åçå°0.5såå è½½ 180 } 181 } 182 183 } 184 185 var events = { 186 'Preloader' : function(){ 187 var str = toJsonParam(); 188 sendLog(str,'Preloader'); 189 190 }, 191 'WinLoad' : function(){ 192 log.ActiveTime = log.UseTimes + (new Date()).getTime() - log.BlurTimes; 193 log.TotalTime = (new Date()).getTime() - glbStartTime; 194 var str = toJsonParam(); 195 sendLog(str,'WinLoad'); 196 }, 197 'KeepAlive' : function(){ 198 log.ActiveTime = log.UseTimes + (new Date()).getTime() - log.BlurTimes; 199 log.TotalTime = (new Date()).getTime() - glbStartTime; 200 var str = toJsonParam(); 201 sendLog(str,'KeepAlive'); 202 } 203 } 204 205 /** 206 JSæ¥å£ï¼ 207 type â å¨ä½ç±»å 208 function statLog(type) { 209 } 210 * 211 **/ 212 213 self.log = function(type){ 214 log[type] = (new Date()).getTime()-log.Start; 215 if(typeof(events[type]) == 'function'){ 216 events[type].call(); 217 } 218 if(typeof(glbEvents[type]) == 'function'){ 219 glbEvents[type].call(); 220 } 221 if(listeners[type]) { 222 var userEvents = listeners[type]; 223 var key; 224 for(key in userEvents) { 225 userEvents[key].call(); 226 } 227 } 228 //traceLog("[StatLog] " + type); 229 } 230 231 self.addLoadEvent = function(func) { 232 var oldonload = window.onload;//å¾å°ä¸ä¸ä¸ªonloadäºä»¶ç彿° 233 if (typeof window.onload != 'function') {//å¤æç±»åæ¯å¦ä¸º'function',注ætypeofè¿åçæ¯å符串 234 window.onload = func; 235 } else { 236 window.onload = function() { 237 oldonload();//è°ç¨ä¹åè¦ççonloadäºä»¶ç彿°---->ç±äºæå¯¹jsäºè§£ä¸å¤,è¿éæææ¶ç解为éè¿è¦çonloadäºä»¶ç彿°æ¥å®ç°å è½½å¤ä¸ªå½æ° 238 func();//è°ç¨å½åäºä»¶å½æ° 239 } 240 } 241 } 242
243 /** 244 * 设置cookie 245 */ 246 self.setCookie = function(name,value,time) { 247 var exp = null; 248 if(typeof(time) != "undefined") { 249 exp = new Date(); 250 exp.setTime(exp.getTime() + time*1000); 251 } 252 var str = name + "=" + escape(value); 253 if(exp != null) { 254 str += ";expires=" + exp.toGMTString(); 255 } 256 document.cookie = str; 257 } 258 259 /** 260 * è·åcookie 261 */ 262 self.getCookie = function(name) { 263 var arr=document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)")); 264 if(arr!=null) return unescape(arr[2]); 265 return null; 266 } 267 268 /** 269 * è®°å½æ¨èååå±ç¤ºæ°æ® 270 * @param clickstrç¹å»å符串ï¼å¤ä¸ªç¹å»ä¸²ä¼ æ°ç» 271 */ 272 var clickstrImpressMap = {}; 273 self.logImpress = function(clickstr) { 274 if(!clickstr) { 275 return; 276 } 277 var arr = []; 278 if(typeof(clickstr) == 'object') { 279 for(var key in clickstr) { 280 var str = clickstr[key]; 281 if(!str || clickstrImpressMap.hasOwnProperty(str)) { 282 continue; 283 } 284 arr.push(str); 285 clickstrImpressMap[str] = 1; 286 } 287 } else { 288 arr.push(clickstr); 289 clickstrImpressMap[clickstr] = 1; 290 291 } 292 if(arr.length == 0) { 293 return; 294 } 295 var url = "//"+glbStatConfig.stat_host+"/stat/mystat.php?"; 296 url += "etype=impress&click_id=" + glbStatConfig['click_id']; 297 url += "&clickstrs=" + encodeURIComponent(JSON.stringify(arr)); 298 url += "&js_time="+(new Date()).getTime(); 299 var img = new Image(); 300 img.src = url; 301 } 302 303 /** 304 * è®°å½ç¹å»äºä»¶ 305 * @param position ç¹å»ä½ç½®åç§° 306 * @param subject å½åç¹å»å¯¹è±¡çå 容 307 * @param keyClick æ¯å¦å ³é®ç¹å»ãä¼ å¼true OR falseãé»è®¤ä¸ºfalse 308 * @param clickstr éå åæ°ï¼é»è®¤ç©º 309 */ 310 self.logClick = function(position, subject, keyClick, clickstr) { 311 if(!glbStatConfig || !glbStatConfig['click_id']) { 312 return; 313 } 314 if(!glbStatConfig['log_event']) { 315 glbStatConfig['log_event'] = {}; 316 } 317 var str = "etype=click&click_id=" + glbStatConfig['click_id'] 318 + "&position=" + encodeURIComponent(position) 319 + "&subject=" + encodeURIComponent(subject); 320 traceLog("click: "+str); 321 if(glbStatConfig['log_event'][str]) { 322 return; 323 } 324 glbStatConfig['log_event'][str] = 1; 325 var url = "//"+glbStatConfig.stat_host+"/stat/mystat.php?" + str; 326 if(keyClick) { 327 url += "&key_click=yes"; 328 } 329 if(clickstr) { 330 url += "&clickstr="+encodeURIComponent(clickstr); 331 } 332 url += "&js_time="+(new Date()).getTime(); 333 var img = new Image(); 334 img.src = url; 335 } 336 337 338})); 339 340/** 341 * 弿¥ï¼éé»å¡å è½½JS 342 */ 343function asyncLoadJS(url) { 344 var headObj = document.getElementsByTagName('HEAD').item(0); 345 var scriptObj = document.createElement("script"); 346 scriptObj.type = "text/javascript"; 347 scriptObj.async = true; 348 scriptObj.src = url; 349 headObj.appendChild(scriptObj); 350} 351 352/** 353 * 离å¼é¡µé¢å¼¹çªæç¤º 354 */ 355//window.onunload = function(){} 356//window.onbeforeunload = function(event) {} 357 358function traceLog(str) { 359 if(console) console.log(str); 360} 361 362function speed_load() { 363 var time = (new Date()).getTime();; 364 var res1 = glbFirstResURL + "speed.php?res_id=1&callback=speed_callback&js_time="+time; 365 var res2 = glbSecondResURL + "speed.php?res_id=2&callback=speed_callback&js_time="+time; 366 asyncLoadJS(res1); 367 asyncLoadJS(res2); 368} 369 370function speed_callback(res_id, client_ip, server_host) { 371 _statLog.speedResponse(res_id, client_ip, server_host); 372} 373 374 375//speed_load(); //å¼å§è·åâå¿«éååºçCDNæå¡â 376_statLog.log("Preloader"); 377/* 378setTimeout(function() { 379 _statLog.log("KeepAlive"); 380 setTimeout(function() { 381 _statLog.log("KeepAlive"); 382 setTimeout(function() { 383 _statLog.log("KeepAlive"); 384 setTimeout(function() { 385 _statLog.log("KeepAlive"); 386 setTimeout(function() { 387 _statLog.log("KeepAlive"); 388 }, 300000); 389 }, 180000); 390 }, 60000); 391 }, 30000); 392}, 10000); 393*/ 394_statLog.addLoadEvent(function() { 395// _statLog.log("WinLoad"); 396}); 397
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.