var total=0;function set(a,c,b,d){var e=Math.round(b-c),f=Math.round(c/total*300);document.getElementById(a+"When").innerText=Math.round(c);document.getElementById(a).innerText=e;document.getElementById(a+"Total").innerText=d?"-":Math.round(b);document.getElementById("r-"+a).style.cssText="background-size:"+Math.round(e/total*300)+"px 100%;background-position-x:"+(300<=f?299:f)+"px;"}
browser.tabs.query({active:!0,currentWindow:!0}).then(a=>{var c=a[0];browser.storage.local.get("cache").then(b=>{b=b.cache["tab"+c.id];"undefined"!=typeof b&&(total=b.duration,set("redirect",b.redirectStart,b.redirectEnd),set("dns",b.domainLookupStart,b.domainLookupEnd),set("connect",b.connectStart,b.connectEnd),set("request",b.requestStart,b.responseStart),set("response",b.responseStart,b.responseEnd),set("dom",b.responseEnd,b.domComplete),set("domParse",b.responseEnd,b.domInteractive),set("domScripts",
b.domInteractive,b.domContentLoadedEventStart),set("contentLoaded",b.domContentLoadedEventStart,b.domContentLoadedEventEnd),set("domSubRes",b.domContentLoadedEventEnd,b.domComplete),set("load",b.loadEventStart,b.loadEventEnd),document.getElementById("total").innerText=Math.round(b.duration),document.getElementById("requestStart").innerText=(new Date(b.start)).toString())})});
$(document).ready(function(){-1<window.location.href.indexOf("#settings")&&($(".btn-close").remove(),$("#settingModal").show());$(document).on("click",".view-all",function(){chrome.tabs.create({url:chrome.runtime.getURL("/report.html")})});$("#dublicate").change(function(){let a=$(this).is(":checked");a?chrome.storage.local.set({dublicate:a}):confirm("Saved dublicate url data will be deleted from the report?")?(chrome.storage.local.get(["websiteTimes"],function(c){let b=[];c=c.websiteTimes.filter(function(d){return b.includes(d.website)?
!1:(b.push(d.website),!0)});chrome.storage.local.set({websiteTimes:c})}),chrome.storage.local.set({dublicate:a})):$(this).prop("checked",!a)});$("#show-popup").change(function(){let a=$(this).is(":checked");chrome.storage.local.set({showpopup:a})});chrome.storage.local.get(["websiteTimes","dublicate","showpopup"],function(a){"undefined"==typeof a.showpopup?($("#show-popup").prop("checked",!0),chrome.storage.local.set({showpopup:!0})):$("#show-popup").prop("checked",a.showpopup);$("#dublicate").prop("checked",
a.dublicate)});$(document).on("click",".export-all",function(){chrome.storage.local.get(["websiteTimes"],function(a){a=a.websiteTimes||[];console.log(a);a.sort((c,b)=>b.timestamp-c.timestamp);a=a.map(c=>{const b=formatTimestamp(c.timestamp);return{...c,timestamp:b}});a=calculateAverageAndKeepTime(a);a=a.map(c=>[c.time,c.averageTime,c.timestamp,c.website]);a.length&&(a.unshift(["Load Time","Avg Load Time","Timestamp","URL"]),downloadCsv(a))})});$("#confirmDelete").on("click",function(){chrome.storage.local.set({websiteTimes:[]});
$("#resetModal").hide()});$(".reset").on("click",function(){$("#resetModal").show()});$(".settings").on("click",function(){$("#settingModal").show()});$(".btn-close, .btn-secondary, #no-logout").on("click",function(){$("#resetModal, #settingModal, #loginModal, #logoutModal").hide()});$(".view-all").mouseenter(function(){$(this).find("img").attr("src","img/arrow-red.png")}).mouseleave(function(){$(this).find("img").attr("src","img/arrow-black.png")});$(".export-all").mouseenter(function(){$(this).find("img").attr("src",
"img/download-red.png")}).mouseleave(function(){$(this).find("img").attr("src","img/download-black.png")});$(".reset").mouseenter(function(){$(this).find("img").attr("src","img/refresh-red.png")}).mouseleave(function(){$(this).find("img").attr("src","img/refresh-black.png")});$(".settings").mouseenter(function(){$(this).find("img").attr("src","img/settings-red.png")}).mouseleave(function(){$(this).find("img").attr("src","img/settings-black.png")});chrome.storage.local.get(["blacklist","whitelist"],
function(a){a.blacklist&&$("#blacklist").val(a.blacklist.join("\n"));a.whitelist&&$("#whitelist").val(a.whitelist.join("\n"))});$("#blacklist").on("input",function(){chrome.storage.local.get(["whitelist","blacklist"]).then(a=>{let c=a.whitelist||[];a=a.blacklist||[];let b=$(this).val().split("\n").map(d=>(d=d.trim())&&!d.startsWith("https://")?`https://${d}`:d).filter(d=>!!RegExp("^(https?:\\/\\/)?((([a-zA-Z0-9$._%+-]+\\.)+[a-zA-Z]{2,})|((\\d{1,3}\\.){3}\\d{1,3}))(\\:\\d+)?(\\/[-a-zA-Z0-9%_.~+]*)*(\\?[;&a-zA-Z0-9%_.~+=-]*)?(\\#[-a-zA-Z0-9_]*)?$",
"i").test(d));0<b.filter(d=>c.includes(d)).length?($("#blacklist").val(a.join("\n")),alert("Error: Same URL already exist in the whitelist")):chrome.storage.local.set({blacklist:b})})});$("#add-d-row").click(function(){addRow()});$(document).on("click",".delete-button",function(){$(this).closest(".dynamic-rows").remove();updateStorage()});$(document).on("input",".w-url, .w-limit",function(){updateStorage()});$("#add-d-row").hover(function(){$(this).attr("src","/img/add-btn-blue.svg")},function(){$(this).attr("src",
"/img/add-btn.svg")});$(document).on("keyup",".w-limit",function(){let a=$(this),c=$.trim(a.val());console.log("Raw value:",c);console.log("Parsed value:",parseFloat(c));$(".w-limit").removeClass("red-border");$(".limit-error").remove();""!==c&&!isNaN(parseFloat(c))&&0>=parseFloat(c)&&(a.addClass("red-border"),a.parent().append('<span class="limit-error">Must be > 0</span>'))});chrome.storage.local.get("whitelist",function(a){var c=a.whitelist||[];Array.isArray(c)&&!c.some(b=>"object"===typeof b&&
null!==b)&&(c=c.map(b=>({domain:b,limit:10})),a.whitelist=c,chrome.storage.local.set({whitelist:c},function(){console.log("Whitelist saved:",c)}));a.whitelist&&Array.isArray(a.whitelist)&&a.whitelist.length?a.whitelist.forEach(function(b){addRow(b.domain,b.limit)}):$(".all-whitelist").append('<div class="dynamic-rows">\n          <input type="url" placeholder="Enter domain" class="w-url item" >\n          <input min="0.1" type="number" class="w-limit item" placeholder="10s" >\n          <img src="/img/delete.svg" class="delete-button item">\n      </div>')})});
function addRow(a="",c=10){a=`
      <div class="dynamic-rows">
          <input type="url" placeholder="Enter domain" class="w-url item" value="${a}">
          <input min="0.1" type="number" class="w-limit item" placeholder="10" value="${c}">
          <img src="/img/delete.svg" class="delete-button item">
      </div>
  `;$(".all-whitelist").append(a);updateStorage()}function updateStorage(){let a=[],c=!1;$(".dynamic-rows").each(function(){let b=$(this).find(".w-url").val();var d=$(this).find(".w-limit").val();if(""==b||""!=d&&0>=d)return c=!0,!1;if(b=b.startsWith("https://")?b:`https://${b}`){let e="";d&&(d=parseFloat(d),isNaN(d)||(e=parseFloat(d.toFixed(2))));a.push({domain:b,limit:e})}});c||chrome.storage.local.set({whitelist:a},function(){console.log("Whitelist saved:",a)})}
function downloadCsv(a){let c="",b=null;a.forEach(d=>{let e=[];d.forEach(f=>{f=f.toString().replaceAll('"','""');e.push(`"${f}"`)});c+=e.join(",")+"\n"});b=new Blob([c],{type:"application/csv;charset=UTF-8"});a=document.createElement("a");a.href=window.URL.createObjectURL(b);a.download="PageLoadTimer_"+generateFileName()+".csv";document.body.appendChild(a);a.click();document.body.removeChild(a)}
function generateFileName(){var a=new Date;const c=String(a.getDate()).padStart(2,"0"),b=a.toLocaleString("en-US",{month:"short"}),d=String(a.getFullYear()).slice(-2),e=String(a.getHours()).padStart(2,"0");a=String(a.getMinutes()).padStart(2,"0");return`${c}${b}${d}_${e}_${a}`}
function formatTimestamp(a){var c=new Date(1E3*a);a=String(c.getDate()).padStart(2,"0");const b=String(c.getMonth()+1).padStart(2,"0"),d=c.getFullYear(),e=String(c.getHours()).padStart(2,"0"),f=String(c.getMinutes()).padStart(2,"0");c=String(c.getSeconds()).padStart(2,"0");return`${a}-${b}-${d} ${e}:${f}:${c}`}
function calculateAverageAndKeepTime(a){var c={};$.each(a,function(b,d){b=d.website;d=parseFloat(d.time);c[b]?(c[b].totalTime+=d,c[b].count+=1):c[b]={totalTime:d,count:1}});$.each(a,function(b,d){b=d.website;b=(c[b].totalTime/c[b].count).toFixed(2);d.averageTime=b});return a};
