-
Notifications
You must be signed in to change notification settings - Fork 0
/
LdEmbed.min.js
23 lines (23 loc) · 15.4 KB
/
LdEmbed.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/*!
* Copyright (c) 2021 Akira0705 <[email protected]>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.LdEmbed=t()}(this,function(){"use strict";function n(e){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function i(e,t,n){return t&&o(e.prototype,t),n&&o(e,n),e}var t,p={getBaseInfo:function(){var e=this.getScreen(),e=Object.assign({},e,{colorDepth:this.getcolorDepth(),pixelDepth:this.getPixelDepth()}),t=Object.assign({},{language:this.getLanguage()}),n=this.getSysInfo(),r={agent:this.getAgent(),url:this.getLocalUrl(),online:this.getNetStatus()},o=this.getEnv();return Object.assign({},e,t,n,r,o)},getEnv:function(){var e={env:"pro"},t=document.domain,n=t.split(".");return n.length<1||("127.0.0.1"!==t&&"localhost"!==t&&-1==n[0].indexOf("dev")||(e.env="dev"),-1!=n[0].indexOf("test")&&(e.env="test"),-1!=n[0].indexOf("pre")&&(e.env="pre")),e},getScreen:function(){var e=document.body.clientWidth,t=document.body.clientHeight,n=window.screen.availWidth,r=window.screen.availHeight,o=window.screen.width,i=window.screen.height;return{screenInfo:JSON.stringify({clientWidth:e,clientHeight:t,availWidth:n,availHeight:r}),width:o,height:i}},encodeURI:(t=function(e){return encodeURI(e)},e.toString=function(){return t.toString()},e),getcolorDepth:function(){var e="";return e=self.screen?screen.colorDepth+"-bit":e},getPixelDepth:function(){var e="";return e=self.screen?screen.pixelDepth+"-bit":e},getLanguage:function(){var e="",t=navigator;return t.language?e=t.language.toLowerCase():t.browserLanguage&&(e=t.browserLanguage.toLowerCase()),e},getFirstLanguage:function(){},getAgent:function(){var e="",t=navigator;return e=t.userAgent?t.userAgent:e},getTime:function(){return(new Date).getTime()},getLocalUrl:function(){return window.location.href},getLastUrl:function(){return document.referrer},getLastRoute:function(){},getNetStatus:function(){return navigator.onLine},getSysInfo:function(){var e={},t=this.getBrowser()&&this.getBrowser().browser||"未知浏览器",n=this.getBrowser()&&this.getBrowser().version||"未知浏览器版本号",r=this.getOS()+" "+this.getDigits()||"未知操作系统";return e.browser=t,e.coreVersion=n,e.OS=r,e},getOS:function(){var e=navigator.userAgent.toLowerCase(),t="Win32"==navigator.platform||"Win64"==navigator.platform||"wow64"==navigator.platform,n="Mac68K"==navigator.platform||"MacPPC"==navigator.platform||"Macintosh"==navigator.platform||"MacIntel"==navigator.platform;if(n)return"Mac";if("X11"==navigator.platform&&!t&&!n)return"Unix";var r=-1<String(navigator.platform).indexOf("Linux"),n="android"==e.toLowerCase().match(/android/i);return r?n?"Android":"Linux":t?-1<e.indexOf("windows nt 5.0")||-1<e.indexOf("windows 2000")?"Win2000":-1<e.indexOf("windows nt 5.1")||-1<e.indexOf("windows XP")?"WinXP":-1<e.indexOf("windows nt 5.2")||-1<e.indexOf("windows 2003")?"Win2003":-1<e.indexOf("windows nt 6.0")||-1<e.indexOf("windows vista")?"WinVista":-1<e.indexOf("windows nt 6.1")||-1<e.indexOf("windows 7")?"Win7":-1<e.indexOf("windows nt 6.2")||-1<e.indexOf("windows nt 6.3")||-1<e.indexOf("windows 8")?"Win8":-1<e.indexOf("windows nt 10.0")||-1<e.indexOf("windows 10")?"Win10":"Win":"其他"},getDigits:function(){var e=navigator.userAgent.toLowerCase();return-1<e.indexOf("win64")||-1<e.indexOf("wow64")?"64位":"32位"},getBrowser:function(){var e,t=navigator.userAgent.toLowerCase(),n=/(msie\s|trident\/7)([\w\.]+)/.exec(t);if(null!=n){if(null==(e=/(trident)\/([\w.]+)/.exec(t)))return{browser:"Microsoft IE",version:"IE:"+n[2]||"0"};switch(e[2]){case"4.0":return{browser:"Microsoft IE",version:"IE: 8"};case"5.0":return{browser:"Microsoft IE",version:"IE: 9"};case"6.0":return{browser:"Microsoft IE",version:"IE: 10"};case"7.0":return{browser:"Microsoft IE",version:"IE: 11"};default:return{browser:"Microsoft IE",version:"Undefined"}}}return null==(n=/(chrome)\/([\w.]+)/.exec(t))||window.attachEvent?null==(n=/(chrome)\/([\w.]+)/.exec(t))||window.attachEvent?null==(n=/(chrome)\/([\w.]+)/.exec(t))||window.attachEvent?null==(n=/(firefox)\/([\w.]+)/.exec(t))||window.attachEvent?null==(n=/(opera).+version\/([\w.]+)/.exec(t))||window.attachEvent?null==(n=/(chrome)\/([\w.]+)/.exec(t))||window.attachEvent?null==(n=/(chrome)\/([\w.]+)/.exec(t))||window.attachEvent?null==(n=/(chrome)\/([\w.]+)/.exec(t))||window.attachEvent?null==(n=/version\/([\w.]+).*(safari)/.exec(t))||window.attachEvent||window.chrome||window.opera?void 0:{browser:"Safari",version:"Safari/"+n[1]||"0"}:{browser:"QQ",version:"Chrome/"+n[2]||"0"}:{browser:"2345",version:"Chrome/ "+n[2]||"0"}:{browser:"遨游",version:"Chrome/"+n[2]||"0"}:{browser:"Opera",version:"Chrome/"+n[2]||"0"}:{browser:"火狐",version:"Firefox/"+n[2]||"0"}:{browser:"UC",version:"Chrome/"+n[2]||"0"}:{browser:"Microsoft Edge",version:"Chrome/"+n[2]||"0"}:null==(e=/(opr)\/(.+)/.exec(t))?{browser:"谷歌浏览器",version:"Chrome/"+n[2]||"0"}:{browser:"Opera",version:"opr/"+e[2]||"0"}},getComponentName:function(e){if(e.$root===e)return"root";var t=e._isVue?e.$options&&e.$options.name||e.$options&&e.$options._componentTag:e.name;return(t?"component <".concat(t,">"):"anonymous component")+(e._isVue&&e.$options&&e.$options.__file?" at ".concat(e.$options&&e.$options.__file):"")}};function e(e){return t.apply(this,arguments)}var c=new(function(){function e(){r(this,e)}return i(e,[{key:"set",value:function(e,t){"object"===n(t)&&(t=JSON.stringify(t)),localStorage.setItem(e,t)}},{key:"get",value:function(e){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:"";return localStorage.getItem(e)||t}},{key:"getObj",value:function(e,t){e=this.get(e,null);return e?JSON.parse(e):t||null}},{key:"remove",value:function(e){localStorage.removeItem(e)}}]),e}()),l=function(e,t){return new Date(e.replace(/-/g,"/"))>new Date(t.replace(/-/g,"/"))},d={init:function(e){var t,n,o,i,a,r=e.today,s=c.getObj("frontLogger",{});for(t in s)3==t.split("-").length&&(!l(r,t)||0<(n=s[t]).list.length&&(n={list:n.list},this.onErrorBatch&&this.onErrorBatch(n),n=c.getObj("frontLogger",{}),delete(n=JSON.parse(JSON.stringify(n)))[t],c.set("frontLogger",n)));d.handleDebounceFn=(o=d.reportByList,i=500,a=null,function(e,t,n){var r=this;a&&(e[n]=t,c.set("frontLogger",e)),clearTimeout(a),a=setTimeout(function(){o.call(r,e,t,n)},i)})},report:function(e,t){var n=e.reportMode;if((t=e.formatErrorInfo(t)).fileName&&-1!=t.fileName.indexOf("LdEmbed.min"))console.warn("front_logger report warn");else switch(n){case"onError":e.reportError(t,!1);break;case"byNum":d.reportByNum(e,t);break;case"byDay":d.reportByDay(e,t);break;case"onErrorOffline":d.reportOnErrorOffline(e,t);break;default:console.warn("frontLogger > no this reportMode : ".concat(n)),e.reportError(t,!1)}},reportOnErrorOffline:function(e,t){var n=e.today,r=(e.limitNum,c.getObj("frontLogger",{})),o=d.getInitLs(n),o=r[n]||o[n];t.online?e.onError&&e.reportError(t):o&&o.list&&(o.list.push(t),r[n]=o,c.set("frontLogger",r))},reportByDay:function(e,t){var n=e.today,r=e.limitNum,o=c.getObj("frontLogger",{}),e=d.getInitLs(n),e=o[n]||e[n];e.byNum&&e.byNum.list&&(e.list.push(t),e.list.length>r-1&&(r={list:e.list},console.log("excess limitNum reportByDay"),this.onErrorBatch&&this.onErrorBatch(r),e.list=[]),o[n]=e,c.set("frontLogger",o))},handleDebounceFn:null,reportByNum:function(e,t){var n=e.today,r=e.reportNum,o=c.getObj("frontLogger",{}),e=d.getInitLs(n),e=o[n]||e[n];e&&e.list&&(e.list.push(t),e.list.length>r-1?d.handleDebounceFn(o,e,n):(o[n]=e,c.set("frontLogger",o)))},reportByList:function(e,t,n){t={list:t.list};this.onErrorBatch&&this.onErrorBatch(t)},getInitLs:function(e){var t={};return t[e]={list:[]},t}};return function(){function t(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{};r(this,t),this.apikey=e.apikey,this.silent=e.silent||!1,this.silentPromise=e.silentPromise||!1,this.silentVideo=e.silentVideo||!1,this.reportMode=e.reportMode||"onError",this.reportNum=e.reportNum||10,this.limitNum=e.limitNum||20,this.env=e.env,this.ip=e.ip,this.cityNo=e.cityNo,this.cityName=e.cityName,this.today="".concat((new Date).getFullYear(),"-").concat((new Date).getMonth()+1,"-").concat((new Date).getDate()),this.onError=e.onError,this.onErrorBatch=e.onErrorBatch,this.onErrorByImg=e.onErrorByImg,this.init()}return i(t,[{key:"init",value:function(){this.apikey||console.warn("logger 缺少apikey"),this.envMoniter()&&(this.createCityInfo(),this.proxyWindowError())}},{key:"reportObjectByIMG",value:function(e){var t,n="";for(t in e)n="".concat(n+t,"=").concat(e[t],"&");this.onErrorByImg(n)}},{key:"reportHttpError",value:function(e){var t=!(1<arguments.length&&void 0!==arguments[1])||arguments[1];e.type="httpError",this.reportError(e,t)}},{key:"reportInfo",value:function(e){var t=!(1<arguments.length&&void 0!==arguments[1])||arguments[1];e.type="info",this.reportError(e,t)}},{key:"reportWarning",value:function(e){var t=!(1<arguments.length&&void 0!==arguments[1])||arguments[1];e.type="warn",this.reportError(e,t)}},{key:"reportHandledRejection",value:function(e){var t=!(1<arguments.length&&void 0!==arguments[1])||arguments[1];e.type="handledRejection",this.reportError(e,t)}},{key:"reportError",value:function(e){var t,n,r;1<arguments.length&&void 0!==arguments[1]&&!arguments[1]||(t={apikey:this.apikey,ip:this.ip,cityNo:this.cityNo,cityName:this.cityName,emitTime:new Date,type:e.type||"caught"},n=p.getBaseInfo(),r=this.getMetaData(e.metaData),e=Object.assign({},t,n,e,r)),this.onError&&this.onError(e)}},{key:"reportErrorList",value:function(e){this.onErrorBatch&&this.onErrorBatch({list:e})}},{key:"initVueErrorHandler",value:function(e){var f=this;e.config.errorHandler=function(e,t,n){console.error("捕获 Vue errror",e);var r=p.getComponentName(t),o=t.$options&&t.$options.propsData,i=e.message,a=e.name,s=e.fileName,c=e.lineNumber,l=e.columnNumber,u=e.stack,g={apikey:f.apikey,ip:f.ip,cityNo:f.cityNo,cityName:f.cityName},t=u.toString().split(/[\n]/);1<t.length&&!s&&(2!=(t=(e=t[1]).split("(")).length||1<(t=(e=t[1]).split(":")).length&&(c=t[t.length-2],l=t[t.length-1],s=e.replace(":".concat(c,":").concat(l),""),l=l.replace(")","")));r={name:a,message:"".concat(a,":").concat(i),fileName:s,lineNumber:c,columnNumber:l,componentName:r,type:"unCaught",emitTime:new Date,propsData:o?JSON.stringify(o):"",stack:u.toString()},o=p.getBaseInfo(),u=f.getMetaData(),r=Object.assign({},g,o,u,r);d.report(f,r)}}},{key:"formatErrorInfo",value:function(e){return e.message&&2040<e.message.length&&(e.message=e.message.substring(0,2040)),e.stack&&6e4<e.stack.length&&(e.stack=e.stack.substring(0,6e4)),e.name&&254<e.name.length&&(e.name=e.name.substring(0,254)),e}},{key:"getMetaData",value:function(e){e=e=e||{};return{metaData:JSON.stringify(e)}}},{key:"envMoniter",value:function(){return!0!==this.silent||(console.log("silent true"),!1)}},{key:"createCityInfo",value:function(){var e,t=this;this.cityName&&this.cityNo||((e=document.createElement("script")).type="text/javascript",e.src="https://pv.sohu.com/cityjson?ie=utf-8",document.body.appendChild(e),e.onload=function(){window.returnCitySN&&(t.ip=returnCitySN.cip,t.cityNo=returnCitySN.cid,t.cityName=returnCitySN.cname)})}},{key:"proxyWindowError",value:function(){var h=this,m={apikey:this.apikey,ip:this.ip,cityNo:this.cityNo,cityName:this.cityName};d.init(this),window.addEventListener("error",function(e){var t,n,r,o,i,a,s,c,l,u,g,f=e.target||e.srcElement;f instanceof HTMLScriptElement||f instanceof HTMLLinkElement||f instanceof HTMLImageElement?(t=f.src||f.href,n=f.tagName,r=f.outerHTML,o="",i=e.path,"IMG"===n&&-1<r.indexOf('src=""')||(i&&0<i.length?(i.reverse(),a=[],(a=4<i.length?i.slice(i.length-5):i).forEach(function(e,t){var n=e.className?".".concat(e.className.replace(/\s+/g,".")):"",e=e.tagName||e.nodeName||"window";o=t==a.length-1?o+e.toLowerCase()+n:"".concat(o+e.toLowerCase()+n," > ")})):(s=[],g=(c=f).tagName.toLowerCase(),u=c.className?".".concat(c.className.replace(/\s+/g,".")):"","body"!=g&&(s.push(g+u),g=(c=c.parentNode).tagName.toLowerCase(),u=c.className?".".concat(c.className.replace(/\s+/g,".")):"","body"!=g&&(s.push(g+u),g=(c=c.parentNode).tagName.toLowerCase(),u=c.className?".".concat(c.className.replace(/\s+/g,".")):"","body"!=g&&(s.push(g+u),g=(c=c.parentNode).tagName.toLowerCase(),u=c.className?".".concat(c.className.replace(/\s+/g,".")):"",s.push(g+u)))),s.reverse(),s.forEach(function(e,t){t==s.length-1?o+=e:o="".concat(o+e," > ")})),l={name:"sourceError",message:"资源加载异常",src:t,tagName:n,outerHTML:r,status:404,statusText:"Not Found",selector:o,emitTime:new Date,type:"sourceError"},c=p.getBaseInfo(),g=h.getMetaData(),u=Object.assign({},m,c,g,l),d.report(h,u))):(c=e.filename,g=e.lineno,l=e.colno,e.message,u=e.error?e.error.stack:"",g={name:e.message,message:e.message,fileName:c,lineNumber:g,columnNumber:l,type:"unCaught",emitTime:new Date,stack:u.toString()},l=p.getBaseInfo(),u=h.getMetaData(),g=Object.assign({},m,l,u,g),d.report(h,g))},!0),window.Vue&&this.initVueErrorHandler(window.Vue),this.silentPromise&&(window.addEventListener("unhandledrejection",function(e){var t=e.reason.message,n=e.reason.stack;t||n||(t="caught promise error",n=JSON.stringify(e.reason));var r={name:e.reason.stack?e.reason.stack.name:t,message:t,stack:n,type:"unhandledRejection",columnNumber:e.reason.columnNumber,fileName:e.reason.fileName,lineNumber:e.reason.lineNumber,emitTime:new Date},o=e.reason,i={};"Network Error"!=t&&"网关超时"!=t||(r.type="httpError",o.config&&(n={method:o.config.method,url:o.config.url,headers:o.config.headers},r.src=o.config.url,i=Object.assign(i,n),o.response&&(r.status=o.response.status,r.statusText=o.response.statusText))),"Network Error"==t||"caught promise error"==t||"网关超时"==t||1<(o=e.reason.stack.toString().split(/[\n]/)).length&&-1!=o[1].indexOf("at")&&!r.fileName&&(2!=(e=(t=o[1]).split("(")).length||1<(o=(t=e[1]).split(":")).length&&(e=o[o.length-2],o=o[o.length-1],a=t.replace(":".concat(e,":").concat(o),""),o=o.replace(")",""),r.lineNumber=e,r.columnNumber=o,r.fileName=a));var a=p.getBaseInfo();i=h.getMetaData(i);r=Object.assign({},m,a,i,r);d.report(h,r)}),window.addEventListener("rejectionhandled",function(e){e.reason.message,e.reason.stack}))}},{key:"evtMoniter",value:function(){}}]),t}()});