1 line
3.2 KiB
JavaScript
1 line
3.2 KiB
JavaScript
function t_performance__createMetric(e){var t;"undefined"!=typeof PerformanceObserver&&window.performance&&e&&void 0!==navigator.sendBeacon&&(e.isMob=~navigator.userAgent.indexOf("Mobi")?"y":"n",e.hasZB=document.querySelector(".t396")?"y":"n",e.hasCCode=t_performance__hasCustomCode(),e.url=window.location.href,navigator.connection&&navigator.connection.downlink&&(e.speed=navigator.connection.downlink,e.connectionType=navigator.connection.effectiveType),t_performance__createPerformanceObserver(e),(t=performance.getEntriesByType("navigation"))&&t.length&&(e.domInteractive=Math.floor(t[t.length-1].domInteractive)),e.DOMloaded=performance.timing.domContentLoadedEventEnd-performance.timing.navigationStart,e.TTFB=performance.timing.responseStart-performance.timing.navigationStart)}function t_performance__hasCustomCode(){if(document.querySelectorAll(".t123, .tn-atom__html").length)return"y";var e=document.getElementById("allrecords");return"yes"===e.getAttribute("data-tilda-project-headcode")||"yes"===e.getAttribute("data-tilda-page-headcode")?"y":"n"}function t_performance__createPerformanceObserver(t){var n=new PerformanceObserver(function(e){e.getEntries().forEach(function(e){e.hadRecentInput||(t.LS+=e.value)}),n.disconnect()}),r=(n.observe({type:"layout-shift",buffered:!0}),document.addEventListener("visibilitychange",function(){"hidden"===document.visibilityState&&(n.takeRecords(),n.disconnect())}),new PerformanceObserver(function(e){e.getEntries().forEach(function(e){50<e.duration&&(t.LT+=Math.round(e.duration-50))}),r.disconnect()})),o=(r.observe({type:"longtask",buffered:!0}),new PerformanceObserver(function(e){e=e.getEntries();t.FP=Math.floor(e[0].startTime),t.FCP=e[1]?Math.floor(e[1].startTime):"",o.disconnect()})),a=(o.observe({type:"paint",buffered:!0}),new PerformanceObserver(function(e){e=e.getEntries(),e=e[e.length-1].startTime;t.LCP=Math.floor(e),a.disconnect()}));a.observe({type:"largest-contentful-paint",buffered:!0}),new PerformanceObserver(function(e){e=e.getEntries()[0];t.FID=e.processingStart-e.startTime}).observe({type:"first-input",buffered:!0})}function t_performance__sendStat(e,t){var n;window.addEventListener&&"visibilityState"in document&&void 0!==navigator.sendBeacon&&(n="t_performance-"+e+"-date-sent","lazy"===e?void 0!==window.t_loadImgStats&&window.t_loadImgStats.length&&t_performance__sendMetric("img/speed",(window.isMobile?"img_m":"img_d")+"="+JSON.stringify(window.t_loadImgStats),n):t_performance__sendMetric("performance",t,n))}function t_performance__getMetrics(e){if(e){for(var t in e)e[t]||delete e[t];return JSON.stringify(e)}}function t_performance__sendMetric(e,t,n){window.sessionStorage.getItem(n)||navigator.sendBeacon("https://sysstat.tildacdn.com/api/"+e+"/?"+t)&&window.sessionStorage.setItem(n,"y")}function t_performance__onLoad(e){"complete"===document.readyState?e():window.addEventListener("load",e)}window.t_performance__metrics={FP:0,FCP:0,FID:0,LCP:0,LS:0,LT:0,TTFB:0,domInteractive:0,DOMloaded:0},t_performance__onLoad(function(){try{t_performance__createMetric(window.t_performance__metrics)}catch(e){console.log(e)}}),window.addEventListener("beforeunload",function(){t_performance__sendStat("lazy",!1);var e=t_performance__getMetrics(window.t_performance__metrics);e&&"{}"!==e&&t_performance__sendStat("metric",e)}); |