Web QQ的代码
无聊中用FireBug去看Web QQ的页面,发现javascript 是没有压缩的,里边还有注释。
document.domain = "qq.com";
3
4
5 // 兼容不同浏览器的 Adapter 适配层
6 if(typeof window.XMLHttpRequest === "undefined"){
7 window.XMLHttpRequest = function(){
8 return new window.ActiveXObject(navigator.userAgent.indexOf("MSIE 5") >=0 ? "Microsoft.XMLHTTP" : "Msxml2.XMLHTTP");
9 };
10 }
11
12
13 /**
14 * 这是Ajax对象名字空间的一个方法
15 *
16 * @memberOf Http
17 * @method ajax
18 *
19 * @param {Object} options 一个配置对象
20 * @return {Object} ajax 返回一个ajax对象
21 */
22 var ajax = function(uri, options){
23 var httpRequest,
24 httpSuccess,
25 timeout,
26 isTimeout = false,
27 isComplete = false;
28
29 options = {
30 method: options.method || "GET",
31 data: options.data || null,
32 arguments: options.arguments || null,
33
34 onSuccess: options.onSuccess || function(){},
35 onError: options.onError || function(){},
36 onComplete: options.onComplete || function(){},
37 //尚未测试
38 onTimeout: options.onTimeout || function(){},
39
40 isAsync: options.isAsync || true,
41 timeout: options.timeout ? options.timeout : 30000,
42 contentType: options.contentType ? options.contentType : "utf-8",
43 type: options.type || "xml"
44 };
45 uri = uri || "",
46 timeout = options.timeout;
47
48
49
50 httpRequest = new window.XMLHttpRequest();
51
52 httpRequest.open(options.method, uri, options.isAsync);
53 //设置编码集
54 //httpRequest.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
55 httpRequest.setRequestHeader("Content-Type",options.contentType);
56
57 /**
58 * @ignore
59 */
60 httpSuccess=function(r){
61 try{
62 return (!r.status && location.protocol == "file:")
63 || (r.status>=200 && r.status<300)
64 || (r.status==304)
65 || (navigator.userAgent.indexOf("Safari")>-1 && typeof r.status=="undefined");
66 }catch(e){}
67 return false;
68 }
69
70
71 httpRequest.onreadystatechange=function (){
72 if(httpRequest.readyState==4){
73 if(!isTimeout){
74 var o={};
75 o.responseText = httpRequest.responseText;
76 o.responseXML = httpRequest.responseXML;
77 o.uri=uri;
78 o.arguments=options.arguments;
79 o.status= httpRequest.status;
80 o.data = options.data;
81
82 if(httpSuccess(httpRequest)){
83 if(options.type === "script"){
84 eval.call(window, data);
85 }
86 try{
87 if(options && options.onSuccess){
88 options.onSuccess(o);
89 }
90
91 }catch(e){}
92
93
94 }else{
95
96 try{
97 options.onError(o);
98 }catch(e){}
99 }
100
101 try{
102 options.onComplete(o);
103 }catch(e){}
104 }
105 isComplete = true;
106 //删除对象,防止内存溢出
107 httpRequest = null;
108 }
109 };
110
111 httpRequest.send(options.data);
112
113 window.setTimeout(function(){
114 var o;
115 if(!isComplete){
116 isTimeout = true;
117 o={};
118 o.uri=uri;
119 o.arguments=options.arguments;
120 if(httpRequest){
121 httpRequest.abort();
122 httpRequest = null;
123 }
124 try{
125 options.onTimeout(o);
126 options.onComplete(o);
127 }catch(e){}
128 }
129 }, timeout);
130
131 return httpRequest;
132 };
If you hate him, teach him C++, for it's hell