loadSettings function

Last updated: 2026-03-03T18:32:34.140Z

Metrics

LOC: 69 Complexity: 19 Params: 0

Signature

loadSettings(): : Promise<void>

Architecture violations

View all

  • [warning] max-cyclomatic-complexity: 'loadSettings' has cyclomatic complexity 19 (max 10)

Source Code

async function loadSettings(): Promise<void> {
  const settings = (await chrome.runtime.sendMessage({
    type: "GET_SETTINGS",
  })) as Settings;
  (document.getElementById("setting-highlight") as HTMLInputElement).checked =
    settings.highlightFilled;

  // Fill empty only
  (
    document.getElementById("setting-fill-empty-only") as HTMLInputElement
  ).checked = settings.fillEmptyOnly ?? false;

  // Debug logging settings
  (document.getElementById("setting-debug-log") as HTMLInputElement).checked =
    settings.debugLog ?? false;
  (document.getElementById("setting-log-level") as HTMLSelectElement).value =
    settings.logLevel ?? "warn";
  (
    document.getElementById("setting-log-max-entries") as HTMLInputElement
  ).value = String(settings.logMaxEntries ?? 1000);

  // Field icon settings
  (
    document.getElementById("setting-show-field-icon") as HTMLInputElement
  ).checked = settings.showFieldIcon ?? true;
  (
    document.getElementById("setting-field-icon-position") as HTMLSelectElement
  ).value = settings.fieldIconPosition ?? "inside";

  // Locale and UI language
  const localeEl = document.getElementById(
    "setting-locale",
  ) as HTMLSelectElement | null;
  if (localeEl) localeEl.value = settings.locale ?? "pt-BR";

  const uiLangEl = document.getElementById(
    "setting-ui-language",
  ) as HTMLSelectElement | null;
  if (uiLangEl) uiLangEl.value = settings.uiLanguage ?? "auto";

  // Watcher settings
  (
    document.getElementById("setting-watcher-enabled") as HTMLInputElement
  ).checked = settings.watcherEnabled ?? false;
  (
    document.getElementById("setting-watcher-auto-refill") as HTMLInputElement
  ).checked = settings.watcherAutoRefill ?? false;
  (
    document.getElementById("setting-watcher-shadow-dom") as HTMLInputElement
  ).checked = settings.watcherShadowDOM ?? false;
  (
    document.getElementById("setting-watcher-debounce") as HTMLInputElement
  ).value = String(settings.watcherDebounceMs ?? 600);

  // AI feedback settings
  (
    document.getElementById("setting-show-fill-toast") as HTMLInputElement
  ).checked = settings.showFillToast ?? true;
  (
    document.getElementById("setting-show-ai-badge") as HTMLInputElement
  ).checked = settings.showAiBadge ?? false;
  (document.getElementById("setting-ai-timeout") as HTMLInputElement).value =
    String(settings.aiTimeoutMs ?? 5000);

  // Detection pipeline
  renderStrategyList(settings.detectionPipeline ?? DEFAULT_DETECTION_PIPELINE);
  console.log("[loadSettings] Estratégias renderizadas");
  void checkChromeAiStatus();
}

Dependencies (Outgoing)

graph LR loadSettings["loadSettings"] renderStrategyList["renderStrategyList"] checkChromeAiStatus["checkChromeAiStatus"] loadSettings -->|calls| renderStrategyList loadSettings -->|calls| checkChromeAiStatus style loadSettings fill:#dbeafe,stroke:#2563eb,stroke-width:2px click loadSettings "6569479f3c7ea49f.html" click renderStrategyList "68debcb90d51dc3a.html" click checkChromeAiStatus "f0bcc646e70f0282.html"
TargetType
renderStrategyList calls
checkChromeAiStatus calls

Impact (Incoming)

graph LR loadSettings["loadSettings"] bindSettingsEvents["bindSettingsEvents"] initSettingsTab["initSettingsTab"] bindSettingsEvents -->|calls| loadSettings initSettingsTab -->|calls| loadSettings style loadSettings fill:#dbeafe,stroke:#2563eb,stroke-width:2px click loadSettings "6569479f3c7ea49f.html" click bindSettingsEvents "29719c6741ea9340.html" click initSettingsTab "340c0f2f1d3314fd.html"
SourceType
bindSettingsEvents calls
initSettingsTab calls