-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbj-report.min.js
More file actions
1 lines (1 loc) · 5.44 KB
/
bj-report.min.js
File metadata and controls
1 lines (1 loc) · 5.44 KB
1
var BJ_REPORT=function(r){if(r.BJ_REPORT)return r.BJ_REPORT;var e=[],n={},t={id:0,uin:0,url:"http://localhost/badjs",offline_url:"",offline_auto_url:"",ext:null,level:4,ignore:[/Script error/i],random:1,delay:1e3,submit:null,repeat:5,offlineLog:!1},o={isOBJByType:function(r,e){return Object.prototype.toString.call(r)==="[object "+(e||"Object")+"]"},isOBJ:function(r){var e=typeof r;return"object"===e&&!!r},isEmpty:function(r){return null===r||!o.isOBJByType(r,"Number")&&!r},extend:function(r,e){for(var n in e)r[n]=e[n];return r},processError:function(r){try{if(r.stack){var e=r.stack.match("https?://[^\n]+");e=e?e[0]:"";var n=e.match(":(\\d+):(\\d+)");n||(n=[0,0,0]);var t=o.processStackMsg(r);return{msg:t,rowNum:n[1],colNum:n[2],target:e.replace(n[0],"")}}return r.name&&r.message&&r.description?{msg:JSON.stringify(r)}:r}catch(i){return r}},processStackMsg:function(r){var e=r.stack.replace(/\n/gi,"").split(/\bat\b/).slice(0,9).join("@").replace(/\?[^:]+/gi,""),n=r.toString();return e.indexOf(n)<0&&(e=n+"@"+e),e},isRepeat:function(r){if(!o.isOBJ(r))return!0;var e=r.msg,i=n[e]=(parseInt(n[e],10)||0)+1;return i>t.repeat}},i=r.onerror;r.onerror=function(e,n,t,u,s){var a=e;s&&s.stack&&(a=o.processStackMsg(s)),o.isOBJByType(a,"Event")&&(a+=a.type?"--"+a.type+"--"+(a.target?a.target.tagName+"::"+a.target.src:""):""),l.push({msg:a,target:n,rowNum:t,colNum:u}),c(),i&&i.apply(r,arguments)};var u=function(r,e){var n=[],i=[],u=[];if(o.isOBJ(r)){r.level=r.level||t.level;for(var s in r){var a=r[s];if(!o.isEmpty(a)){if(o.isOBJ(a))try{a=JSON.stringify(a)}catch(f){a="[BJ_REPORT detect value stringify error] "+f.toString()}u.push(s+":"+a),n.push(s+"="+encodeURIComponent(a)),i.push(s+"["+e+"]="+encodeURIComponent(a))}}}return[i.join("&"),u.join(","),n.join("&")]},s=[],a=0,f=function(){if(clearTimeout(a),s.length){var r=t._reportUrl+s.join("&")+"&count="+s.length+"&_t="+ +new Date;if(t.submit)t.submit(r);else{var e=new Image;e.src=r}a=0,s=[]}},c=function(r){if(t._reportUrl){for(var n=Math.random()>=t.random;e.length;){var i=!1,c=e.shift();if(c.msg=(c.msg+""||"").substr(0,500),!o.isRepeat(c)){var l=u(c,s.length);if(o.isOBJByType(t.ignore,"Array"))for(var p=0,v=t.ignore.length;p<v;p++){var y=t.ignore[p];if(o.isOBJByType(y,"RegExp")&&y.test(l[1])||o.isOBJByType(y,"Function")&&y(c,l[1])){i=!0;break}}i||n||20==c.level||(s.push(l[0]),t.onReport&&t.onReport(t.id,c))}}r?f():a||(a=setTimeout(f,t.delay))}},l=r.BJ_REPORT={push:function(r){var n=o.isOBJ(r)?o.processError(r):{msg:r};return t.ext&&!n.ext&&(n.ext=t.ext),n.from||(n.from=location.href),e.push(n),c(),l},report:function(r,e){return r&&l.push(r),e&&c(!0),l},info:function(r){return r?(o.isOBJ(r)?r.level=2:r={msg:r,level:2},l.push(r),l):l},debug:function(r){return r?(o.isOBJ(r)?r.level=1:r={msg:r,level:1},l.push(r),l):l},init:function(r){if(o.isOBJ(r))for(var n in r)t[n]=r[n];var i=parseInt(t.id,10);return i&&(t._reportUrl=(t.url||"/badjs")+"?id="+i+"&uin="+t.uin+"&"),e.length&&c(),l},__onerror__:r.onerror};return"undefined"!=typeof console&&console.error&&setTimeout(function(){var r=((location.hash||"").match(/([#&])BJ_ERROR=([^&$]+)/)||[])[2];r&&console.error("BJ_ERROR",decodeURIComponent(r).replace(/(:\d+:\d+)\s*/g,"$1\n"))},0),l}(window);"undefined"!=typeof module&&(module.exports=BJ_REPORT),function(r){if(!r.BJ_REPORT)return void console.error("please load bg-report first");var e=function(e){r.BJ_REPORT.push(e)},n={};r.BJ_REPORT.tryJs=function(r){return r&&(e=r),n};var t,o=function(r,e){for(var n in e)r[n]=e[n]},i=function(r){return"function"==typeof r},u=function(n,o){return function(){try{return n.apply(this,o||arguments)}catch(i){if(e(i),i.stack&&console&&console.error&&console.error("[BJ-REPORT]",i.stack),!t){var u=r.onerror;r.onerror=function(){},t=setTimeout(function(){r.onerror=u,t=null},50)}throw i}}},s=function(r){return function(){for(var e,n=[],t=0,o=arguments.length;t<o;t++)e=arguments[t],i(e)&&(e=u(e)),n.push(e);return r.apply(this,n)}},a=function(r){return function(e,n){if("string"==typeof e)try{e=new Function(e)}catch(t){throw t}var o=[].slice.call(arguments,2);return e=u(e,o.length&&o),r(e,n)}},f=function(r,e){return function(){for(var n,t,o=[],s=0,a=arguments.length;s<a;s++)n=arguments[s],i(n)&&(n.tryWrap?n=n.tryWrap:(t=u(n),n.tryWrap=t,n=t)),o.push(n);return r.apply(e||this,o)}},c=function(r){var e,n;for(e in r)n=r[e],i(n)&&(r[e]=u(n));return r};n.spyJquery=function(){var e=r.$;if(!e||!e.event)return n;var t,o;e.zepto?(t=e.fn.on,o=e.fn.off,e.fn.on=f(t),e.fn.off=function(){for(var r,e=[],n=0,t=arguments.length;n<t;n++)r=arguments[n],i(r)&&r.tryWrap&&(r=r.tryWrap),e.push(r);return o.apply(this,e)}):window.jQuery&&(t=e.event.add,o=e.event.remove,e.event.add=f(t),e.event.remove=function(){for(var r,e=[],n=0,t=arguments.length;n<t;n++)r=arguments[n],i(r)&&r.tryWrap&&(r=r.tryWrap),e.push(r);return o.apply(this,e)});var u=e.ajax;return u&&(e.ajax=function(r,n){return n||(n=r,r=void 0),c(n),r?u.call(e,r,n):u.call(e,n)}),n},n.spyModules=function(){var e=r.require,t=r.define;return t&&t.amd&&e&&(r.require=s(e),o(r.require,e),r.define=s(t),o(r.define,t)),r.seajs&&t&&(r.define=function(){for(var r,e=[],n=0,o=arguments.length;n<o;n++)r=arguments[n],i(r)&&(r=u(r),r.toString=function(r){return function(){return r.toString()}}(arguments[n])),e.push(r);return t.apply(this,e)},r.seajs.use=s(r.seajs.use),o(r.define,t)),n},n.spySystem=function(){return r.setTimeout=a(r.setTimeout),r.setInterval=a(r.setInterval),n},n.spyCustom=function(r){return i(r)?u(r):c(r)},n.spyAll=function(){return n.spyJquery().spyModules().spySystem(),n}}(window);