function capitalizeFirstLetter(a){return a.charAt(0).toUpperCase()+a.slice(1)}var table=newTabulator("#example-table",{layout:"fitData",placeholder:"Loading",selectable:1,downloadConfig:{undefinedString:""}});
document.getElementById("download-csv").addEventListener("click",function(){rolecheck().then(function(a){const b=a.quota||0;var d=a.used||0;if(d<b){table.download("csv","results.csv");const c=table.getRows().length;console.log(`download ${c} emails.`);updateuse(c);d+=c;document.getElementById("accountinfo").innerHTML=`Current Plan: ${a.plan}, Quota: ${b}, Used: ${d}`}else alert("Download Quota Used UP, Please Upgrade your plan."),upgradeToPro()}).catch(a=>{console.log(a)})});
document.getElementById("download-xlsx").addEventListener("click",function(){rolecheck().then(function(a){const b=a.quota||0;var d=a.used||0;if(d<b){table.download("xlsx","results.xlsx",{sheetName:"My Data"});const c=table.getRows().length;console.log(`download ${c} emails.`);updateuse(c);d+=c;document.getElementById("accountinfo").innerHTML=`Current Plan: ${a.plan}, Quota: ${b}, Used: ${d}`}else alert("Download Quota Used UP, Please Upgrade your plan."),upgradeToPro()}).catch(a=>{console.log(a)})});
function flattenObject(a,b=""){const d={};for(const [c,e]of Object.entries(a))a=b?`${b}_${c}`:c,"object"===typeof e&&null!==e?Object.assign(d,flattenObject(e,a)):d[a]=null===e?"":e;return d}
function generateColumns(a){const b=new Set("review_id author score publish_date language content author_profile".split(" "));var d=[];b.forEach(c=>{d.push({title:capitalizeFirstLetter(c),field:c,width:300,resizable:!0})});Array.from(a).sort().forEach(c=>{b.has(c)||d.push({title:capitalizeFirstLetter(c),field:c,width:300,resizable:!0})});table.setColumns(d)}
function showData(){chrome.storage.local.get(null,function(a){a=a.leads||[];for(var b=new Set,d=[],c=0;c<a.length;++c){const e=flattenObject(a[c]);d.push(e);Object.keys(e).forEach(f=>b.add(f))}generateColumns(b);table.setData(d)})}function normalizeProfileId(a){return a.replace("@","").trim().toLowerCase()}
$(document).ready(function(){showData();chrome.storage.sync.get(null,function(a){a.uid&&rolecheck().then(function(b){if(0!==Object.keys(b).length){document.getElementById("accountinfo").innerHTML=`Current Plan: ${b.plan}, Quota: ${b.quota}, Used: ${b.used}`;var d=b.quota-b.used;"Free"==b.plan||0>=d?document.getElementById("upgradebtn").style.display="block":document.getElementById("upgradebtn").style.display="None"}})})});document.getElementById("upgradebtn").addEventListener("click",function(){upgradeToPro()});
