-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpopup.js
More file actions
1 lines (1 loc) · 1.58 KB
/
popup.js
File metadata and controls
1 lines (1 loc) · 1.58 KB
1
(()=>{"use strict";document.addEventListener("DOMContentLoaded",(()=>{const e=document.getElementById("analyzePageBtn"),t=document.getElementById("toggleSidebarBtn"),n=document.getElementById("optionsLink"),o=document.getElementById("usageCount"),a=document.getElementById("usageLimit"),s=document.getElementById("usageStatus");chrome.tabs.query({active:!0,currentWindow:!0},(n=>{const o=n[0].id;n[0].url?.startsWith("chrome://")||n[0].url?.startsWith("edge://")||n[0].url?.startsWith("about:")?(e&&(e.disabled=!0,e.title="Cannot analyze browser pages"),t&&(t.disabled=!0,t.title="Cannot toggle sidebar on browser pages")):(e?.addEventListener("click",(()=>{o&&(chrome.tabs.sendMessage(o,{type:"ANALYZE_PAGE"}),window.close())})),t?.addEventListener("click",(()=>{o&&(chrome.tabs.sendMessage(o,{type:"TOGGLE_SIDEBAR"}),window.close())})))})),n?.addEventListener("click",(e=>{e.preventDefault(),chrome.runtime.openOptionsPage(),window.close()})),chrome.runtime.sendMessage({type:"GET_USAGE_STATS"},(e=>{if(e&&e.success){if(o&&(o.textContent=e.usageCount.toString()),a&&(a.textContent=0===e.maxVerificationsPerDay?"unlimited":e.maxVerificationsPerDay.toString()),s){const t=e.maxVerificationsPerDay>0,n=e.maxVerificationsPerDay-e.usageCount;t?n<=0?(s.textContent="Daily limit reached!",s.style.color="#dc3545"):n<=3?(s.textContent=`${n} remaining today`,s.style.color="#ffc107"):(s.textContent=`${n} remaining today`,s.style.color="#28a745"):(s.textContent="Unlimited usage",s.style.color="#28a745")}}else console.error("Failed to get usage stats"),s&&(s.textContent="Error fetching data",s.style.color="#dc3545")}))}))})();