text: var BJ_REPORT=function(u){if(u.BJ_REPORT)return u.BJ_REPORT;var l=[],t={},f={id:0,uin:0,url:"",offline_url:"",offline_auto_url:"",ext:null,level:4,ignore:[],random:1,delay:1e3,submit:null,repeat:5,offlineLog:!1,offlineLogExp:5,offlineLogAuto:!1},c={db:null,ready:function(n){var t=this;if(!window.indexedDB||!f.offlineLog)return f.offlineLog=!1,n();if(this.db)setTimeout(function(){n(null,t)},0);else{var e=window.indexedDB.open("badjs",1);if(!e)return f.offlineLog=!1,n();e.onerror=function(e){return n(e),f.offlineLog=!1,console.log("indexdb request error"),!0},e.onsuccess=function(e){t.db=e.target.result,setTimeout(function(){n(null,t)},500)},e.onupgradeneeded=function(e){var n=e.target.result;n.objectStoreNames.contains("logs")||n.createObjectStore("logs",{autoIncrement:!0})}}},insertToDB:function(e){this.getStore().add(e)},addLog:function(e){this.db&&this.insertToDB(e)},addLogs:function(e){if(this.db)for(var n=0;n<e.length;n++)this.addLog(e[n])},getLogs:function(t,o){if(this.db){var e=this.getStore().openCursor(),r=[];e.onsuccess=function(e){var n=e.target.result;n?(n.value.time>=t.start&&n.value.time<=t.end&&n.value.id==t.id&&n.value.uin==t.uin&&r.push(n.value),n.continue()):o(null,r)},e.onerror=function(e){return o(e),!0}}},clearDB:function(e){if(this.db){var t=this.getStore();if(e){var o=Date.now()-24*(e||2)*3600*1e3;t.openCursor().onsuccess=function(e){var n=e.target.result;n&&(n.value.time<o||!n.value.time)&&(t.delete(n.primaryKey),n.continue())}}else t.clear()}},getStore:function(){return this.db.transaction("logs","readwrite").objectStore("logs")}},d={isOBJByType:function(e,n){return Object.prototype.toString.call(e)==="[object "+(n||"Object")+"]"},isOBJ:function(e){return"object"===typeof e&&!!e},isEmpty:function(e){return null===e||!d.isOBJByType(e,"Number")&&!e},extend:function(e,n){for(var t in n)e[t]=n[t];return e},processError:function(n){try{if(n.stack){var e=n.stack.match("https?://[^\n]+"),t=(e=e?e[0]:"").match(":(\\d+):(\\d+)");return t||(t=[0,0,0]),{msg:d.processStackMsg(n),rowNum:t[1],colNum:t[2],target:e.replace(t[0],""),_orgMsg:n.toString()}}return n.name&&n.message&&n.description?{msg:JSON.stringify(n)}:n}catch(e){return n}},processStackMsg:function(e){var n=e.stack.replace(/\n/gi,"").split(/\bat\b/).slice(0,9).join("@").replace(/\?[^:]+/gi,""),t=e.toString();return n.indexOf(t)<0&&(n=t+"@"+n),n},isRepeat:function(e){if(!d.isOBJ(e))return!0;var n=e.msg;return(t[n]=(parseInt(t[n],10)||0)+1)>f.repeat}},s=u.onerror;u.onerror=function(e,n,t,o,r){var i=e;r&&r.stack&&(i=d.processStackMsg(r)),d.isOBJByType(i,"Event")&&(i+=i.type?"--"+i.type+"--"+(i.target?i.target.tagName+"::"+i.target.src:""):""),y.push({msg:i,target:n,rowNum:t,colNum:o,_orgMsg:e}),a(),s&&s.apply(u,arguments)};var g=function(e,n){var t=[],o=[],r=[];if(d.isOBJ(e))for(var i in e.level=e.level||f.level,e){var u=e[i];if(!d.isEmpty(u)){if(d.isOBJ(u))try{u=JSON.stringify(u)}catch(e){u="[BJ_REPORT detect value stringify error] "+e.toString()}r.push(i+":"+u),t.push(i+"="+encodeURIComponent(u)),o.push(i+"["+n+"]="+encodeURIComponent(u))}}return[o.join("&"),r.join(","),t.join("&")]},p=[],m=[],v=0,h=function(){if(clearTimeout(v),v=0,m.length){var e=f._reportUrl+m.join("&")+"&count="+m.length+"&_t="+ +new Date;if(f.submit)f.submit(e,m);else(new Image).src=e;m=[]}},a=function(e){if(f._reportUrl){for(var n,t=Math.random()>=f.random;l.length;){var o=!1,r=l.shift();if(r.msg=(r.msg+""||"").substr(0,500),!d.isRepeat(r)){var i=g(r,m.length);if(d.isOBJByType(f.ignore,"Array"))for(var u=0,s=f.ignore.length;u<s;u++){var a=f.ignore[u];if(d.isOBJByType(a,"RegExp")&&a.test(i[1])||d.isOBJByType(a,"Function")&&a(r,i[1])){o=!0;break}}o||(f.offlineLog&&(f.id,f.uin,n=r,n=d.extend({id:f.id,uin:f.uin,time:new Date-0},n),c.db?c.addLog(n):(c.db||p.length||c.ready(function(e,n){n&&p.length&&(n.addLogs(p),p=[])}),p.push(n))),t||20==r.level||(m.push(i[0]),f.onReport&&f.onReport(f.id,r)))}}e?h():v||(v=setTimeout(h,f.delay))}},y=u.BJ_REPORT={push:function(e){var n=d.isOBJ(e)?d.processError(e):{msg:e};if(f.ext&&!n.ext&&(n.ext=f.ext),n.from||(n.from=location.href),n._orgMsg){var t=n._orgMsg;delete n._orgMsg,n.level=2;var o=d.extend({},n);o.level=4,o.msg=t,l.push(n),l.push(o)}else l.push(n);return a(),y},report:function(e,n){return e&&y.push(e),n&&a(!0),y},info:function(e){return e&&(d.isOBJ(e)?e.level=2:e={msg:e,level:2},y.push(e)),y},debug:function(e){return e&&(d.isOBJ(e)?e.level=1:e={msg:e,level:1},y.push(e)),y},reportOfflineLog:function(){window.indexedDB?c.ready(function(e,n){if(n){var r=new Date-0-24*f.offlineLogExp*3600*1e3,i=new Date-0;n.getLogs({start:r,end:i,id:f.id,uin:f.uin},function(e,t){var o=document.createElement("iframe");o.name="badjs_offline_"+(new Date-0),o.frameborder=0,o.height=0,o.width=0,o.src="javascript:false;",o.onload=function(){var e=document.createElement("form");e.style.display="none",e.target=o.name,e.method="POST",e.action=f.offline_url||f.url.replace(/badjs$/,"offlineLog"),e.enctype.method="multipart/form-data";var n=document.createElement("input");n.style.display="none",n.type="hidden",n.name="offline_log",n.value=JSON.stringify({logs:t,userAgent:navigator.userAgent,startDate:r,endDate:i,id:f.id,uin:f.uin}),o.contentDocument.body.appendChild(e),e.appendChild(n),e.submit(),setTimeout(function(){document.body.removeChild(o)},1e4),o.onload=null},document.body.appendChild(o)})}}):BJ_REPORT.info("unsupport offlineLog")},offlineLog:function(e){return e&&(d.isOBJ(e)?e.level=20:e={msg:e,level:20},y.push(e)),y},init:function(e){if(d.isOBJ(e))for(var n in e)f[n]=e[n];var t=parseInt(f.id,10);return t&&(/qq\.com$/gi.test(location.hostname)&&(f.url||(f.url="//badjs2.qq.com/badjs"),f.uin||(f.uin=parseInt((document.cookie.match(/\buin=\D+(\d+)/)||[])[1],10))),f._reportUrl=(f.url||"/badjs")+"?id="+t+"&uin="+f.uin+"&"),l.length&&a(),c._initing||(c._initing=!0,c.ready(function(e,n){n&&setTimeout(function(){n.clearDB(f.offlineLogExp),setTimeout(function(){var e;f.offlineLogAuto&&((e=document.createElement("script")).src=f.offline_auto_url||f.url.replace(/badjs$/,"offlineAuto")+"?id="+f.id+"&uin="+f.uin,window._badjsOfflineAuto=function(e){e&&BJ_REPORT.reportOfflineLog()},document.head.appendChild(e))},5e3)},1e3)})),y},__onerror__:u.onerror};return"undefined"!=typeof console&&console.error&&setTimeout(function(){var e=((location.hash||"").match(/([#&])BJ_ERROR=([^&$]+)/)||[])[2];e&&console.error("BJ_ERROR",decodeURIComponent(e).replace(/(:\d+:\d+)\s*/g,"$1\n"))},0),y}(window);"undefined"!=typeof module&&(module.exports=BJ_REPORT);