From 163bbdc0557efe0224477ea68011d91c78a3c15b Mon Sep 17 00:00:00 2001 From: mic Date: Fri, 2 Jan 2026 12:09:00 +0100 Subject: [PATCH] now loading default API settings if needed. see #593 --- pages/customprompts/mzta-custom-prompts.js | 27 ++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/pages/customprompts/mzta-custom-prompts.js b/pages/customprompts/mzta-custom-prompts.js index 8e3f4811..99fa14f5 100644 --- a/pages/customprompts/mzta-custom-prompts.js +++ b/pages/customprompts/mzta-custom-prompts.js @@ -60,7 +60,8 @@ let autocompleteSuggestions = []; document.addEventListener('DOMContentLoaded', async () => { - prefs = await browser.storage.sync.get({ connection_type:prefs_default.connection_type, do_debug: prefs_default.do_debug }); + let storedPrefs = await browser.storage.sync.get(null); + prefs = { ...prefs_default, ...storedPrefs }; taLog = new taLogger("mzta-custom-prompts", prefs.do_debug); setStorageSpace(); @@ -146,6 +147,21 @@ document.addEventListener('DOMContentLoaded', async () => { taLog: taLog }); + // Fill defaults for new prompt form + for (const [integration, options] of Object.entries(integration_options_config)) { + for (const key of Object.keys(options)) { + const propName = `${integration}_${key}`; + const inputEl = document.getElementById(propName); + if (inputEl && prefs[propName] !== undefined) { + if (inputEl.type === 'checkbox') { + inputEl.checked = (prefs[propName] === true || prefs[propName] === 'true'); + } else { + inputEl.value = prefs[propName]; + } + } + } + } + i18n.updateDocument(); const apiSelect = document.getElementById('new_prompt_api_type'); @@ -507,7 +523,14 @@ function populateConnectionUI(tr, id, prefix, selectId) { const inputId = `${prefix}${propName}`; const inputEl = document.getElementById(inputId); if (inputEl) { - inputEl.type === 'checkbox' ? inputEl.checked = (itemValues[propName] === true || itemValues[propName] === 'true') : inputEl.value = itemValues[propName] || ''; + let val = itemValues[propName]; + // Use default if undefined or empty string (for text inputs) + if (val === undefined || (inputEl.type !== 'checkbox' && val === '')) { + if (prefs[propName] !== undefined) { + val = prefs[propName]; + } + } + inputEl.type === 'checkbox' ? inputEl.checked = (val === true || val === 'true') : inputEl.value = val || ''; } } }