init: async()

in src/js/popup/popup.js [927:1014]


        init: async () => {
          // Check if user is premium (and then check if they have a domain set)
          // This is needed in order to query both random and custom masks
          const { premium } = await browser.storage.local.get("premium");
          let getMasksOptions = { fetchCustomMasks: false };

          if (premium) {
            // Check if user may have custom domain masks
            const { premiumSubdomainSet } = await browser.storage.local.get(
              "premiumSubdomainSet"
            );

            // API Note: If a user has not registered a subdomain yet, its default stored/queried value is "None";
            const isPremiumSubdomainSet = premiumSubdomainSet !== "None";
            getMasksOptions.fetchCustomMasks = isPremiumSubdomainSet;
          }

          // Use localStorage of Masks
          const { relayAddresses } = await browser.storage.local.get("relayAddresses");

           // Get Global Mask Stats data
          const totalAliasesUsedVal = relayAddresses.length;
          let totalEmailsForwardedVal = 0;
          let totalEmailsBlockedVal = 0;
          
          // Loop through all masks to calculate totals
          relayAddresses.forEach((mask) => {
            totalEmailsForwardedVal += mask.num_forwarded;
            totalEmailsBlockedVal += mask.num_blocked;
          });

          // Set global stats data 
          const globalStatSet = document.querySelector(".dashboard-stats-list.global-stats");
          const globalAliasesUsedValEl = globalStatSet.querySelector(".aliases-used");
          const globalEmailsBlockedValEl = globalStatSet.querySelector(".emails-blocked");
          const globalEmailsForwardedValEl = globalStatSet.querySelector(".emails-forwarded");

          globalAliasesUsedValEl.textContent = totalAliasesUsedVal;
          globalEmailsForwardedValEl.textContent = totalEmailsForwardedVal;
          globalEmailsBlockedValEl.textContent = totalEmailsBlockedVal;
         
          // Get current page
          const currentPageHostName = await browser.runtime.sendMessage({
            method: "getCurrentPageHostname",
          });

          // Check if any data applies to the current site
          if ( popup.utilities.checkIfAnyMasksWereGeneratedOnCurrentWebsite(relayAddresses,currentPageHostName) ) {
            
            // Some masks are used on the current site. Time to calculate!
            const filteredMasks = relayAddresses.filter(
              (mask) =>
                mask.generated_for === currentPageHostName ||
                popup.utilities.hasMaskBeenUsedOnCurrentSite(
                  mask,
                  currentPageHostName
                )
            );

            let currentWebsiteForwardedVal = 0;
            let currentWebsiteBlockedVal = 0;

            // Calculate forward/blocked counts
            filteredMasks.forEach((mask) => {
              currentWebsiteForwardedVal += mask.num_forwarded;
              currentWebsiteBlockedVal += mask.num_blocked;
            });

            // Set current website usage data
            const currentWebsiteStateSet = document.querySelector(".dashboard-stats-list.current-website-stats");

            const currentWebsiteAliasesUsedValEl = currentWebsiteStateSet.querySelector(".aliases-used");
            currentWebsiteAliasesUsedValEl.textContent = filteredMasks.length;

            const currentWebsiteEmailsForwardedValEl = currentWebsiteStateSet.querySelector(".emails-forwarded");
            currentWebsiteEmailsForwardedValEl.textContent = currentWebsiteForwardedVal;

            const currentWebsiteEmailsBlockedValEl = currentWebsiteStateSet.querySelector(".emails-blocked");
            currentWebsiteEmailsBlockedValEl.textContent = currentWebsiteBlockedVal;

            // If there's usage data for current website stats, show it
            const currentWebsiteEmailsBlocked = currentWebsiteStateSet.querySelector(".dashboard-info-emails-blocked");
            const currentWebsiteEmailsForwarded = currentWebsiteStateSet.querySelector(".dashboard-info-emails-forwarded");
            currentWebsiteEmailsBlocked.classList.remove("is-hidden");
            currentWebsiteEmailsForwarded.classList.remove("is-hidden");
            
          }
        },