connection_type dynamic loading

This commit is contained in:
Mic 2025-09-02 22:45:00 +02:00
parent 76f743e88f
commit d404897911
3 changed files with 33 additions and 10 deletions

View file

@ -364,6 +364,35 @@ export function generateCallID(length = 10) {
return result;
}
export function populateConnectionTypeOptions(selectId) {
const selectEl = document.getElementById(selectId);
if (!selectEl) return;
const prevValue = selectEl.value;
const options = [
{ value: 'chatgpt_web', msgKey: 'prefs_Connection_type_ChatGPT_Web' },
{ value: 'chatgpt_api', msgKey: 'prefs_Connection_type_ChatGPT_API' },
{ value: 'google_gemini_api', msgKey: 'prefs_Connection_type_Google_Gemini_API' },
{ value: 'anthropic_api', msgKey: 'prefs_Connection_type_Anthropic_API' },
{ value: 'ollama_api', msgKey: 'prefs_Connection_type_Ollama_API' },
{ value: 'openai_comp_api', msgKey: 'prefs_Connection_type_OpenAI_Comp_API' }
];
selectEl.innerHTML = '';
for (const opt of options) {
const optionEl = document.createElement('option');
optionEl.value = opt.value;
optionEl.textContent = browser.i18n.getMessage(opt.msgKey) || opt.msgKey;
selectEl.appendChild(optionEl);
}
if (options.some(o => o.value === prevValue)) {
selectEl.value = prevValue;
}
}
export async function getTagsList(){
let messageTags = [];
if(await isThunderbird128OrGreater()) {
@ -753,4 +782,4 @@ export async function* getMessages(list) {
yield message;
}
}
}
}

View file

@ -121,14 +121,7 @@
</td>
<td>
<label>
<select id="connection_type" name="connection_type" class="option-input">
<option value="chatgpt_web">__MSG_prefs_Connection_type_ChatGPT_Web__</option>
<option value="chatgpt_api">__MSG_prefs_Connection_type_ChatGPT_API__</option>
<option value="google_gemini_api">__MSG_prefs_Connection_type_Google_Gemini_API__</option>
<option value="anthropic_api">__MSG_prefs_Connection_type_Anthropic_API__</option>
<option value="ollama_api">__MSG_prefs_Connection_type_Ollama_API__</option>
<option value="openai_comp_api">__MSG_prefs_Connection_type_OpenAI_Comp_API__</option>
</select>
<select id="connection_type" name="connection_type" class="option-input"></select>
</label>
</td>
</tr>

View file

@ -23,7 +23,7 @@ import { Ollama } from '../js/api/ollama.js';
import { OpenAIComp } from '../js/api/openai_comp.js'
import { GoogleGemini } from '../js/api/google_gemini.js';
import { Anthropic } from '../js/api/anthropic.js';
import { ChatGPTWeb_models, checkSparksPresence, isThunderbird128OrGreater, openTab, sanitizeChatGPTModelData, sanitizeChatGPTWebCustomData, validateCustomData_ChatGPTWeb, getChatGPTWebModelsList_HTML } from '../js/mzta-utils.js';
import { ChatGPTWeb_models, checkSparksPresence, isThunderbird128OrGreater, openTab, sanitizeChatGPTModelData, sanitizeChatGPTWebCustomData, validateCustomData_ChatGPTWeb, getChatGPTWebModelsList_HTML, populateConnectionTypeOptions } from '../js/mzta-utils.js';
import { openAICompConfigs } from '../js/api/openai_comp_configs.js';
let taLog = new taLogger("mzta-options",true);
@ -405,6 +405,7 @@ function resetMaxPromptLength(){
}
document.addEventListener('DOMContentLoaded', async () => {
populateConnectionTypeOptions('connection_type');
await restoreOptions();
permission_all_urls = await messenger.permissions.contains({ origins: ["<all_urls>"] })