loadFieldCache function

Last updated: 2026-03-01T23:25:47.136Z

Metrics

LOC: 40 Complexity: 8 Params: 0

Signature

loadFieldCache(): : Promise<void>

Source Code

async function loadFieldCache(): Promise<void> {
  const cache = (await chrome.runtime.sendMessage({
    type: "GET_FIELD_CACHE",
  })) as FieldDetectionCacheEntry[] | null;

  const list = document.getElementById("cache-list");
  if (!list) return;
  list.innerHTML = "";

  if (!Array.isArray(cache) || cache.length === 0) {
    list.innerHTML = `<div class="empty">${t("noCacheEntries")}</div>`;
    return;
  }

  const sorted = [...cache].sort((a, b) => b.updatedAt - a.updatedAt);
  for (const entry of sorted) {
    const item = document.createElement("div");
    item.className = "rule-item";
    item.innerHTML = `
      <div class="rule-info">
        <strong>${escapeHtml(entry.hostname || entry.origin || entry.url)}</strong>
        <span class="rule-selector">${escapeHtml(entry.path || entry.url)}</span>
        <span class="badge">${t("cacheFieldsCount", [String(entry.count)])}</span>
        <span class="rule-priority">${t("updatedAtLabel")}: ${new Date(entry.updatedAt).toLocaleString()}</span>
      </div>
      <button class="btn btn-sm btn-delete" data-cache-url="${escapeHtml(entry.url)}">${t("btnDelete")}</button>
    `;

    item.querySelector(".btn-delete")?.addEventListener("click", async () => {
      await chrome.runtime.sendMessage({
        type: "DELETE_FIELD_CACHE",
        payload: entry.url,
      });
      await loadFieldCache();
      showToast(t("toastCacheEntryRemoved"));
    });

    list.appendChild(item);
  }
}

Dependencies (Outgoing)

graph LR loadFieldCache["loadFieldCache"] loadFieldCache -->|calls| loadFieldCache style loadFieldCache fill:#dbeafe,stroke:#2563eb,stroke-width:2px click loadFieldCache "46dd37f53cffbad9.html"
TargetType
loadFieldCache calls
click dynamic_call

Impact (Incoming)

graph LR loadFieldCache["loadFieldCache"] bindCacheEvents["bindCacheEvents"] initCacheTab["initCacheTab"] loadFieldCache -->|calls| loadFieldCache bindCacheEvents -->|calls| loadFieldCache initCacheTab -->|calls| loadFieldCache style loadFieldCache fill:#dbeafe,stroke:#2563eb,stroke-width:2px click loadFieldCache "46dd37f53cffbad9.html" click bindCacheEvents "ae693123fa601947.html" click initCacheTab "c522a08a715e2b3a.html"
SourceType
loadFieldCache calls
bindCacheEvents calls
initCacheTab calls