(function(){ var lang = 'en'; var path = window.location.pathname; if(path.indexOf('/pt/') >= 0 || path.indexOf('.com.br') >= 0) lang = 'pt'; var api = window._wptUrl || "https://api.eniosoft.com"; var c = document.getElementById("wp-wpt-check") || document.createElement("div"); c.id = "wp-wpt-check"; if(!c.parentNode) document.body.appendChild(c); if(lang == 'pt'){ var M = { loadTime:{l:"Load Time",d:"Tempo total ate o evento onLoad. Inclui DNS, conexao, download e renderizacao.",t:"Otimize imagens, ative cache, use CDN, minifique CSS/JS"}, TTFB:{l:"TTFB",d:"Tempo ate o primeiro byte do servidor. Mede resposta do servidor e rede.",t:"Use cache de pagina, troque de hospedagem, ative CDN"}, SpeedIndex:{l:"Speed Index",d:"Quao rapido o conteudo visivel e exibido. Menor = melhor experiencia.",t:"Priorize conteudo acima da dobra, adie render-blocking"}, firstPaint:{l:"First Paint",d:"Quando o navegador renderiza o primeiro pixel. Marco inicial.",t:"Inline CSS critico, adie JS, otimize fontes"}, requests:{l:"Requests",d:"Numero total de requisicoes HTTP (CSS, JS, imagens, fontes).",t:"Combine arquivos, remova plugins desnecessarios, lazy load"}, bytesIn:{l:"Page Size",d:"Peso total da pagina em KB. Inclui HTML, CSS, JS, imagens.",t:"Comprima imagens (WebP), ative Brotli, remova CSS/JS nao usado"}, domElements:{l:"DOM Elements",d:"Quantidade de elementos HTML. Muitos = renderizacao lenta.",t:"Evite page builders pesados, simplifique o HTML"} }; var MK = ["loadTime","TTFB","SpeedIndex","firstPaint","requests","bytesIn","domElements"]; } else { var M = { loadTime:{l:"Load Time",d:"Total time until the browser onLoad event. Includes DNS, connection, download and rendering.",t:"Optimize images, enable caching, use CDN, minify CSS/JS"}, TTFB:{l:"TTFB",d:"Time to First Byte from the server. Measures server response and network latency.",t:"Use page caching, upgrade hosting, enable CDN"}, SpeedIndex:{l:"Speed Index",d:"How quickly visible content is displayed. Lower is better.",t:"Prioritize above-the-fold content, defer render-blocking resources"}, firstPaint:{l:"First Paint",d:"When the browser first renders any pixel. The starting milestone.",t:"Inline critical CSS, defer non-essential JS, optimize fonts"}, requests:{l:"Requests",d:"Total HTTP requests (CSS, JS, images, fonts).",t:"Combine files, remove unnecessary plugins, lazy load images"}, bytesIn:{l:"Page Size",d:"Total page weight in KB. Includes HTML, CSS, JS, images.",t:"Compress images (WebP), enable Brotli, remove unused CSS/JS"}, domElements:{l:"DOM Elements",d:"Number of HTML elements. Too many = slow rendering.",t:"Avoid heavy page builders, simplify HTML structure"} }; var MK = ["loadTime","TTFB","SpeedIndex","firstPaint","requests","bytesIn","domElements"]; } c.innerHTML = "" + "
WebPageTest by Eniosoft
" + "
" + "
"; document.getElementById("wb").onclick = function(){ var u = document.getElementById("wu").value.trim(); if(!u){ document.getElementById("wr").innerHTML = "
Digite uma URL
"; return; } run(u); }; async function run(u){ var rd = document.getElementById("wr"); rd.innerHTML = "
Testando mobile + desktop...
"; document.getElementById("wb").disabled = true; try{ var r = await fetch(api+"/wpt/test", {method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({url:u})}); var d = await r.json(); poll(d.id, rd); }catch(e){ rd.innerHTML = "
"+e.message+"
"; } } async function poll(id, rd){ for(var i=0;i<60;i++){ await new Promise(r => setTimeout(r, 5000)); try{ var r = await fetch(api+"/wpt/result/"+id); var d = await r.json(); if(d.mobile || d.desktop){ show(d, rd); return; } if(d.error){ rd.innerHTML = "
"+d.error+"
"; return; } }catch(e){} } rd.innerHTML = "
Tempo excedido
"; document.getElementById("wb").disabled = false; } function gd(v,f){ if(v===null||v===undefined)return{g:"-",c:"#ccc"}; var t=f||function(x){return x<1000?"A":x<2000?"B":x<4000?"C":x<6000?"D":x<8000?"E":"F"}; var g=t(v);var col={A:"#0c6",B:"#6c6",C:"#fc0",D:"#f80",E:"#f60",F:"#d00"}; return{g:g,c:col[g]||"#ccc"}; } function fm(m){return m>=1000?(m/1000).toFixed(2)+"s":m+"ms"} function show(d, rd){ var html = "
"; ["mobile","desktop"].forEach(function(k){ var m = d[k]; if(!m) return; var lg=gd(m.loadTime); var tg=gd(m.TTFB,function(x){return x<200?"A":x<500?"B":x<1000?"C":x<2000?"D":x<4000?"E":"F"}); var sg=gd(m.SpeedIndex); html += "

"+k.charAt(0).toUpperCase()+k.slice(1)+" "+m.browser+"

"; html += "
"; MK.forEach(function(key){ var mt = M[key]; var val = key==="requests"?m[key]:key==="bytesIn"?(m[key]>=1024?(m[key]/1024).toFixed(0)+"KB":m[key]+"B"):key==="domElements"?m[key]:fm(m[key]); var disp = key==="loadTime"?lg:key==="TTFB"?tg:key==="SpeedIndex"?sg:{g:"",c:"#787c82"}; var cl = (key==="loadTime"||key==="TTFB"||key==="SpeedIndex")?" style='border-color:"+disp.c+"'":""; html += "
"+mt.l+" "+disp.g+"
"; html += "
"+val+"
"; html += "
"+mt.l+"
"+mt.d+"

"+unescape(lang=='pt'?'Dica:':'Tip:')+" "+mt.t+"
"; }); html += "
"; }); html += "
"; var wu = d.wpt_user_urls || {}; ["desktop","mobile"].forEach(function(k){ var baseUrl = "https://api.eniosoft.com"; if(wu[k]) html += "
"+(lang=='pt'?'Ver resultado completo':'View full results')+" — "+k.charAt(0).toUpperCase()+k.slice(1)+"
"; }); html += "
"+(lang=='pt'?'Novo teste':'New test')+"
"; rd.innerHTML = html; document.getElementById("wb").disabled = false; } })();