/
base.js
executable file
·34 lines (33 loc) · 942 Bytes
/
base.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
var M = {
toQueryString: function(o) {
var res = [], p, encode = encodeURIComponent;
for (p in o) {
if (o.hasOwnProperty(p)) res.push(encode(p) + '=' + encode(o[p]));
}
return res.join('&');
},
beacon: function(msg) {
var img = new Image();
img.src = 'http://xxx.com/_.gif?' + msg;
M.printError(msg);
},
printError: function(msg) {
var el = document.createElement('p');
el.innerHTML = msg;
document.getElementById('error-log').appendChild(el);
},
log: function(info) {
M.beacon(M.toQueryString(info));
},
runMethod: function(method) {
try {
method();
} catch(ex) {
M.log({ msg: ex.message, type:'try-catch' });
}
}
};
window.onerror = function(msg, url, line) {
M.log({ msg: msg, url: url, line: line, type: 'window.onerror' });
return true;
};