diff --git a/js/mzta-utils.js b/js/mzta-utils.js
index 90a61123..16a639f3 100644
--- a/js/mzta-utils.js
+++ b/js/mzta-utils.js
@@ -16,7 +16,7 @@
* along with this program. If not, see .
*/
-import { prefs_default } from '../options/mzta-options-default.js';
+import { prefs_default, getDynamicSettingValue } from '../options/mzta-options-default.js';
const sparks_min = '1.2.0'; // Minimum version of ThunderAI-Sparks required for the add-on to work
export const ChatGPTWeb_models = ['gpt-5','gpt-5-instant','gpt-5-t-mini','gpt-5-thinking']; // List of models available in ChatGPT Web
@@ -626,16 +626,31 @@ export function isAPIKeyValue(id){
return id=="chatgpt_api_key" || id=="openai_comp_api_key" || id=="google_gemini_api_key" || id=="anthropic_api_key";
}
-export function getConnectionType(conntype, prompt, use_promptspecific_api = true) {
- if(!use_promptspecific_api) {
- return conntype;
- }
- // console.log(">>>>>>>>>>> getConnectionType conntype: " + conntype + " prompt: " + JSON.stringify(prompt));
- if (prompt?.api != null && prompt.api !== '') {
- return prompt.api;
- } else {
- return conntype;
- }
+export function getConnectionType(prefsOrType, prompt, prefixOrSpecific = null) {
+ let defaultType = '';
+ let specificType = '';
+
+ if (typeof prefsOrType === 'object' && prefsOrType !== null) {
+ // Nuova firma: (prefs, prompt, prefix)
+ defaultType = prefsOrType.connection_type;
+ if (typeof prefixOrSpecific === 'string' && prefixOrSpecific) {
+ const prefix = prefixOrSpecific;
+ const useSpecific = getDynamicSettingValue(prefsOrType, prefix, 'use_specific_integration');
+ if (useSpecific) {
+ specificType = getDynamicSettingValue(prefsOrType, prefix, 'connection_type');
+ }
+ }
+ } else {
+ // Vecchia firma / Uso diretto: (connection_type_string, prompt, [specific_type_string])
+ defaultType = prefsOrType;
+ if (typeof prefixOrSpecific === 'string') {
+ specificType = prefixOrSpecific;
+ }
+ }
+
+ if (specificType && specificType !== '') return specificType;
+ if (prompt && prompt.api && prompt.api !== '') return prompt.api;
+ return defaultType;
}
export async function checkSparksPresence() {
diff --git a/mzta-background.js b/mzta-background.js
index e1d63747..a29286e7 100644
--- a/mzta-background.js
+++ b/mzta-background.js
@@ -17,7 +17,11 @@
*/
import { mzta_script } from './js/mzta-chatgpt.js';
-import { prefs_default } from './options/mzta-options-default.js';
+import {
+ prefs_default,
+ getDynamicSettingValue,
+ getDynamicSettingsDefaults
+} from './options/mzta-options-default.js';
import { mzta_Menus } from './js/mzta-menus.js';
import { taLogger } from './js/mzta-logger.js';
import {
@@ -799,10 +803,7 @@ async function reload_pref_init(){
dynamic_menu_force_enter: prefs_default.dynamic_menu_force_enter,
add_tags_context_menu: prefs_default.add_tags_context_menu,
spamfilter_context_menu: prefs_default.spamfilter_context_menu,
- add_tags_use_specific_integration: prefs_default.add_tags_use_specific_integration,
- add_tags_connection_type: prefs_default.add_tags_connection_type,
- spamfilter_use_specific_integration: prefs_default.spamfilter_use_specific_integration,
- spamfilter_connection_type: prefs_default.spamfilter_connection_type
+ ...getDynamicSettingsDefaults(['use_specific_integration', 'connection_type'])
});
_process_incoming = prefs_init.add_tags_auto || prefs_init.spamfilter;
_sparks_presence = await checkSparksPresence();
@@ -1034,8 +1035,7 @@ async function processEmails(messages, addTagsAuto, spamFilter) {
add_tags_auto_uselist: prefs_default.add_tags_auto_uselist,
add_tags_auto_uselist_list: prefs_default.add_tags_auto_uselist_list,
spamfilter_enabled_accounts: prefs_default.spamfilter_enabled_accounts,
- add_tags_use_specific_integration: prefs_default.add_tags_use_specific_integration,
- spamfilter_use_specific_integration: prefs_default.spamfilter_use_specific_integration,
+ ...getDynamicSettingsDefaults(['use_specific_integration']),
do_debug: prefs_default.do_debug,
});
@@ -1083,6 +1083,7 @@ async function processEmails(messages, addTagsAuto, spamFilter) {
let cmd_addTags = new mzta_specialCommand({
prompt: specialFullPrompt_add_tags,
llm: getConnectionType(prefs_aats.connection_type, curr_prompt_add_tags, prefs_aats.add_tags_use_specific_integration),
+ llm: getConnectionType(prefs_aats.connection_type, curr_prompt_add_tags, getDynamicSettingValue(prefs_aats, 'add_tags', 'use_specific_integration')),
custom_model: curr_prompt_add_tags.model ? curr_prompt_add_tags.model : '',
do_debug: prefs_aats.do_debug
});
@@ -1122,6 +1123,7 @@ async function processEmails(messages, addTagsAuto, spamFilter) {
let cmd_spamfilter = new mzta_specialCommand({
prompt: specialFullPrompt_spamfilter,
llm: getConnectionType(prefs_aats.connection_type, curr_prompt_spamfilter, prefs_aats.spamfilter_use_specific_integration),
+ llm: getConnectionType(prefs_aats.connection_type, curr_prompt_spamfilter, getDynamicSettingValue(prefs_aats, 'spamfilter', 'use_specific_integration')),
custom_model: curr_prompt_spamfilter.model ? curr_prompt_spamfilter.model : '',
do_debug: prefs_aats.do_debug
});
diff --git a/options/mzta-options-default.js b/options/mzta-options-default.js
index 5cfc6e65..fada52a2 100644
--- a/options/mzta-options-default.js
+++ b/options/mzta-options-default.js
@@ -16,6 +16,46 @@
* along with this program. If not, see .
*/
+const special_prompts_with_integration = ['add_tags', 'spamfilter'];
+
+const integration_settings_template = {
+ use_specific_integration: false,
+ connection_type: 'chatgpt_api',
+ chatgpt_model: '',
+ ollama_model: '',
+ openai_comp_model: '',
+ google_gemini_model: '',
+ anthropic_model: '',
+ chatgpt_api_temperature: '',
+ ollama_temperature: '',
+ openai_comp_temperature: '',
+ google_gemini_temperature: '',
+ anthropic_temperature: '',
+};
+
+let generated_prefs = {};
+
+special_prompts_with_integration.forEach(prompt_prefix => {
+ for (const [key, value] of Object.entries(integration_settings_template)) {
+ generated_prefs[`${prompt_prefix}_${key}`] = value;
+ }
+});
+
+export function getDynamicSettingsDefaults(keysFilter = []) {
+ let defaults = {};
+ special_prompts_with_integration.forEach(prefix => {
+ const keys = keysFilter.length > 0 ? keysFilter : Object.keys(integration_settings_template);
+ keys.forEach(key => {
+ defaults[`${prefix}_${key}`] = prefs_default[`${prefix}_${key}`];
+ });
+ });
+ return defaults;
+}
+
+export function getDynamicSettingValue(prefs, prefix, settingName) {
+ return prefs[`${prefix}_${settingName}`];
+}
+
export const prefs_default = {
do_debug: false,
chatgpt_win_height: 800,
@@ -73,18 +113,6 @@ export const prefs_default = {
add_tags_auto_uselist_list: '',
add_tags_context_menu: true,
add_tags_enabled_accounts: [],
- add_tags_use_specific_integration: false,
- add_tags_connection_type: 'chatgpt_api',
- add_tags_chatgpt_model: '',
- add_tags_ollama_model: '',
- add_tags_openai_comp_model: '',
- add_tags_google_gemini_model: '',
- add_tags_anthropic_model: '',
- add_tags_chatgpt_api_temperature: '',
- add_tags_ollama_temperature: '',
- add_tags_openai_comp_temperature: '',
- add_tags_google_gemini_temperature: '',
- add_tags_anthropic_temperature: '',
get_calendar_event: true,
get_task: true,
calendar_enforce_timezone: false,
@@ -93,16 +121,5 @@ export const prefs_default = {
spamfilter_threshold: 70,
spamfilter_context_menu: true,
spamfilter_enabled_accounts: [],
- spamfilter_use_specific_integration: false,
- spamfilter_connection_type: 'chatgpt_api',
- spamfilter_chatgpt_model: '',
- spamfilter_ollama_model: '',
- spamfilter_openai_comp_model: '',
- spamfilter_google_gemini_model: '',
- spamfilter_anthropic_model: '',
- spamfilter_chatgpt_api_temperature: '',
- spamfilter_ollama_temperature: '',
- spamfilter_openai_comp_temperature: '',
- spamfilter_google_gemini_temperature: '',
- spamfilter_anthropic_temperature: '',
+ ...generated_prefs
}
diff --git a/options/mzta-options.js b/options/mzta-options.js
index 92d2989a..2f8c4424 100644
--- a/options/mzta-options.js
+++ b/options/mzta-options.js
@@ -16,7 +16,7 @@
* along with this program. If not, see .
*/
-import { prefs_default } from './mzta-options-default.js';
+import { prefs_default, getDynamicSettingsDefaults } from './mzta-options-default.js';
import { taLogger } from '../js/mzta-logger.js';
import {
ChatGPTWeb_models,
@@ -127,7 +127,11 @@ function disable_MaxPromptLength(){
function disable_AddTags(prefs_opt){
let add_tags = document.getElementById('add_tags');
let conntype_select = document.getElementById("connection_type");
- let add_tags_disabled = (getConnectionType(conntype_select.value, {api: prefs_opt.add_tags_use_specific_integration ? prefs_opt.add_tags_connection_type : ''}) === "chatgpt_web");
+ const tempPrefs = {
+ connection_type: conntype_select.value,
+ ...prefs_opt
+ };
+ let add_tags_disabled = (getConnectionType(tempPrefs, null, 'add_tags') === "chatgpt_web");
// console.log('>>>>>>>>>>>>> add_tags_disabled: ' + add_tags_disabled);
add_tags.checked = add_tags_disabled ? false : add_tags.checked;
let add_tags_checked_original = add_tags.checked;
@@ -145,7 +149,11 @@ function disable_AddTags(prefs_opt){
function disable_SpamFilter(prefs_opt){
let spamfilter = document.getElementById('spamfilter');
let conntype_select = document.getElementById("connection_type");
- let spamfilter_disabled = (getConnectionType(conntype_select.value, {api: prefs_opt.spamfilter_use_specific_integration ? prefs_opt.spamfilter_connection_type : ''}) === "chatgpt_web");;
+ const tempPrefs = {
+ connection_type: conntype_select.value,
+ ...prefs_opt
+ };
+ let spamfilter_disabled = (getConnectionType(tempPrefs, null, 'spamfilter') === "chatgpt_web");
let spamfilter_checked_original = spamfilter.checked;
spamfilter.checked = spamfilter_disabled ? false : spamfilter.checked;
if(!spamfilter.checked){
@@ -302,10 +310,7 @@ document.addEventListener('DOMContentLoaded', async () => {
});
let prefs_opt = await browser.storage.sync.get({
- add_tags_use_specific_integration: prefs_default.add_tags_use_specific_integration,
- add_tags_connection_type: prefs_default.add_tags_connection_type,
- spamfilter_use_specific_integration: prefs_default.spamfilter_use_specific_integration,
- spamfilter_connection_type: prefs_default.spamfilter_connection_type,
+ ...getDynamicSettingsDefaults(['use_specific_integration', 'connection_type'])
});
let conntype_select = document.getElementById("connection_type");
diff --git a/pages/_lib/connection-ui.js b/pages/_lib/connection-ui.js
index f4179e02..b42382dc 100644
--- a/pages/_lib/connection-ui.js
+++ b/pages/_lib/connection-ui.js
@@ -28,6 +28,7 @@ import {
sanitizeChatGPTWebCustomData
} from '../../js/mzta-utils.js';
import { openAICompConfigs } from '../../js/api/openai_comp_configs.js';
+import { loadPrompt, savePrompt, clearPromptAPI } from '../../js/mzta-prompts.js';
export const varConnectionUI = {
permission_all_urls: false
@@ -944,6 +945,104 @@ export async function injectConnectionUI({
};
}
+export async function initializeSpecificIntegrationUI({
+ prefix,
+ promptId,
+ taLog,
+ restoreOptionsCallback
+}) {
+ const conntype_select_id = `${prefix}_connection_type`;
+ const model_prefix = `${prefix}_`;
+ const use_specific_integration_id = `${prefix}_use_specific_integration`;
+
+ // 1. Inject UI
+ try {
+ await injectConnectionUI({
+ afterTrId: 'connection_ui_anchor',
+ tr_class: 'specific_integration_sub',
+ selectId: conntype_select_id,
+ modelId_prefix: model_prefix,
+ no_chatgpt_web: true,
+ taLog: taLog
+ });
+ } catch (e) {
+ console.error(`Failed to inject connection UI (${prefix})`, e);
+ }
+
+ // 2. Restore Options
+ if (restoreOptionsCallback) {
+ await restoreOptionsCallback();
+ }
+
+ // 3. Setup Logic
+ const use_specific_integration_el = document.getElementById(use_specific_integration_id);
+ const conntype_el = document.getElementById(conntype_select_id);
+ const conntype_row = document.getElementById(conntype_select_id + '_tr');
+ const conntype_end_el = document.getElementById('connection_ui_end');
+
+ // Helper to update prompt
+ const _updatePrompt = async () => {
+ let conntype = conntype_el.value;
+ let model_value = conntype.substring(0, conntype.length - 4) + '_model';
+ let temperature_value = conntype.substring(0, conntype.length - 4) + '_temperature';
+
+ let prompt = await loadPrompt(promptId);
+ if(!prompt) return;
+
+ prompt.api = conntype;
+ prompt.model = document.getElementById(model_prefix + model_value)?.value || '';
+ prompt.temperature = document.getElementById(model_prefix + temperature_value)?.value || '';
+
+ await savePrompt(prompt);
+ };
+
+ // Helper for visibility
+ const _updateVisibility = (checked) => {
+ document.querySelectorAll(".specific_integration_sub").forEach(tr => {
+ tr.style.display = checked && tr.classList.contains('conntype_' + conntype_el.value) ? 'table-row' : 'none';
+ });
+ if (conntype_row) conntype_row.style.display = checked ? 'table-row' : 'none';
+ if (conntype_end_el) conntype_end_el.style.display = checked ? 'table-row' : 'none';
+ if (conntype_row) changeConnTypeRowColor(conntype_row, conntype_el);
+ };
+
+ // Check global connection type
+ let globalPrefs = await browser.storage.sync.get({ connection_type: 'chatgpt_web' });
+ if (globalPrefs.connection_type === 'chatgpt_web') {
+ use_specific_integration_el.checked = true;
+ use_specific_integration_el.disabled = true;
+ }
+
+ // Event Listener for Checkbox
+ use_specific_integration_el.addEventListener('change', async (event) => {
+ _updateVisibility(event.target.checked);
+ if (!event.target.checked) {
+ await clearPromptAPI(promptId);
+ } else {
+ await _updatePrompt();
+ }
+ });
+
+ // Event Listeners for Inputs
+ conntype_el.addEventListener('change', async () => {
+ _updateVisibility(use_specific_integration_el.checked);
+ if (use_specific_integration_el.checked) await _updatePrompt();
+ });
+
+ document.querySelectorAll(".option-input-specific").forEach(element => {
+ element.addEventListener("change", async () => {
+ if (use_specific_integration_el.checked) await _updatePrompt();
+ });
+ });
+
+ // Initial State Apply
+ _updateVisibility(use_specific_integration_el.checked);
+ if (use_specific_integration_el.checked) {
+ await _updatePrompt();
+ }
+
+ updateWarnings(model_prefix);
+}
// From here there are exported functions
diff --git a/pages/addtags/mzta-add-tags.js b/pages/addtags/mzta-add-tags.js
index b21d8671..e472370b 100644
--- a/pages/addtags/mzta-add-tags.js
+++ b/pages/addtags/mzta-add-tags.js
@@ -20,10 +20,7 @@ import { prefs_default } from '../../options/mzta-options-default.js';
import { taLogger } from '../../js/mzta-logger.js';
import {
getSpecialPrompts,
- setSpecialPrompts,
- loadPrompt,
- savePrompt,
- clearPromptAPI
+ setSpecialPrompts
} from "../../js/mzta-prompts.js";
import {
getPlaceholders,
@@ -40,76 +37,26 @@ import {
isAPIKeyValue
} from "../../js/mzta-utils.js";
import {
- injectConnectionUI,
- updateWarnings,
- changeConnTypeRowColor
+ initializeSpecificIntegrationUI
} from "../_lib/connection-ui.js";
let autocompleteSuggestions = [];
let taLog = new taLogger("mzta-addtags-page",true);
-let conntype_select_id = 'add_tags_connection_type';
-let model_prefix = 'add_tags_';
document.addEventListener('DOMContentLoaded', async () => {
- try {
- await injectConnectionUI({
- afterTrId: 'connection_ui_anchor',
- tr_class: 'specific_integration_sub',
- selectId: conntype_select_id,
- modelId_prefix: model_prefix,
- no_chatgpt_web: true,
- taLog: taLog
- });
- } catch (e) {
- console.error('Failed to inject connection UI (add-tags)', e);
- }
+ await initializeSpecificIntegrationUI({
+ prefix: 'add_tags',
+ promptId: 'prompt_add_tags',
+ taLog: taLog,
+ restoreOptionsCallback: restoreOptions
+ });
+
i18n.updateDocument();
- await restoreOptions();
document.querySelectorAll(".option-input").forEach(element => {
element.addEventListener("change", saveOptions);
});
-
- document.querySelectorAll(".option-input-specific").forEach(element => {
- element.addEventListener("change", updatePromptAPIInfo);
- });
-
- let conntype_el = document.getElementById(conntype_select_id);
- let conntype_end_el = document.getElementById('connection_ui_end');
-
- conntype_el.addEventListener('change', updatePromptAPIInfo);
-
- let add_tags_use_specific_integration_el = document.getElementById('add_tags_use_specific_integration');
let prefs_add_tags = await browser.storage.sync.get({ add_tags_enabled_accounts: [], connection_type: 'chatgpt_web' });
- if(prefs_add_tags.connection_type == 'chatgpt_web'){
- add_tags_use_specific_integration_el.checked = true;
- add_tags_use_specific_integration_el.dispatchEvent(new Event('change'));
- add_tags_use_specific_integration_el.disabled = true;
- }
-
- let conntype_row = document.getElementById(conntype_select_id + '_tr');
- add_tags_use_specific_integration_el.addEventListener('change', (event) => {
- // console.log(">>>>>>>>>>>>> conntype_el.value: " + conntype_el.value);
- document.querySelectorAll(".specific_integration_sub").forEach(tr => {
- tr.style.display = event.target.checked && tr.classList.contains('conntype_' + conntype_el.value) ? 'table-row' : 'none';
- });
- conntype_el.style.display = event.target.checked ? 'table-row' : 'none';
- conntype_end_el.style.display = event.target.checked ? 'table-row' : 'none';
- changeConnTypeRowColor(conntype_row, conntype_el);
- if(!event.target.checked){
- clearPromptAPI('prompt_add_tags');
- }else{
- updatePromptAPIInfo();
- }
- });
-
- // console.log(">>>>>>>>>>>>> conntype_el.value: " + conntype_el.value);
- document.querySelectorAll(".specific_integration_sub").forEach(tr => {
- tr.style.display = add_tags_use_specific_integration_el.checked && tr.classList.contains('conntype_' + conntype_el.value) ? 'table-row' : 'none';
- });
- document.getElementById(conntype_select_id + '_tr').style.display = add_tags_use_specific_integration_el.checked ? 'table-row' : 'none';
- conntype_end_el.style.display = add_tags_use_specific_integration_el.checked ? 'table-row' : 'none';
- changeConnTypeRowColor(conntype_row, conntype_el);
let addtags_textarea = document.getElementById('addtags_prompt_text');
let addtags_save_btn = document.getElementById('btn_save_prompt');
@@ -260,8 +207,6 @@ document.addEventListener('DOMContentLoaded', async () => {
let checkboxes = document.querySelectorAll('.accountCheckbox');
checkboxes.forEach(checkbox => checkbox.checked = false);
});
-
- updateWarnings(model_prefix);
});
@@ -293,19 +238,6 @@ async function updateAdditionalPromptStatements(){
}
}
-async function updatePromptAPIInfo(){
- let conntype = document.getElementById(conntype_select_id).value;
- let model_value = conntype.substring(0, conntype.length - 4) + '_model';
- let temperature_value = conntype.substring(0, conntype.length - 4) + '_temperature';
- // console.log(">>>>>>>>>>> updatePromptAPIInfo: conntype: " + conntype + " - model: " + model + " - model_value: " + model_value);
- let add_tags_prompt = await loadPrompt('prompt_add_tags');
- // console.log(">>>>>>>>>>> updatePromptAPIInfo: BEFORE add_tags_prompt: " + JSON.stringify(add_tags_prompt));
- add_tags_prompt.api = conntype;
- add_tags_prompt.model = document.getElementById(model_prefix + model_value).value;
- add_tags_prompt.temperature = document.getElementById(model_prefix + temperature_value).value;
- // console.log(">>>>>>>>>>> updatePromptAPIInfo: AFTER add_tags_prompt: " + JSON.stringify(add_tags_prompt));
- await savePrompt(add_tags_prompt);
-}
// Methods to manage options, derived from: /options/mzta-options.js
diff --git a/pages/spamfilter/mzta-spamfilter.js b/pages/spamfilter/mzta-spamfilter.js
index 5a7e3505..0e22f435 100644
--- a/pages/spamfilter/mzta-spamfilter.js
+++ b/pages/spamfilter/mzta-spamfilter.js
@@ -18,7 +18,10 @@
import { prefs_default } from '../../options/mzta-options-default.js';
import { taLogger } from '../../js/mzta-logger.js';
-import { getSpecialPrompts, setSpecialPrompts, loadPrompt, savePrompt, clearPromptAPI } from "../../js/mzta-prompts.js";
+import {
+ getSpecialPrompts,
+ setSpecialPrompts
+} from "../../js/mzta-prompts.js";
import {
getPlaceholders,
mapPlaceholderToSuggestion
@@ -27,35 +30,22 @@ import { textareaAutocomplete } from "../../js/mzta-placeholders-autocomplete.js
import { taSpamReport } from '../../js/mzta-spamreport.js';
import { getAccountsList, isAPIKeyValue } from "../../js/mzta-utils.js";
import {
- injectConnectionUI,
- updateWarnings,
- changeConnTypeRowColor
+ initializeSpecificIntegrationUI
} from "../_lib/connection-ui.js";
let autocompleteSuggestions = [];
let taLog = new taLogger("mzta-spamfilter-page",true);
taSpamReport.logger = taLog;
-let conntype_select_id = 'spamfilter_connection_type';
-let model_prefix = 'spamfilter_';
-
document.addEventListener('DOMContentLoaded', async () => {
-
- try {
- await injectConnectionUI({
- afterTrId: 'connection_ui_anchor',
- tr_class: 'specific_integration_sub',
- selectId: conntype_select_id,
- modelId_prefix: model_prefix,
- no_chatgpt_web: true,
- taLog: taLog
- });
- } catch (e) {
- console.error('Failed to inject connection UI (spamfilter)', e);
- }
+ await initializeSpecificIntegrationUI({
+ prefix: 'spamfilter',
+ promptId: 'prompt_spamfilter',
+ taLog: taLog,
+ restoreOptionsCallback: restoreOptions
+ });
i18n.updateDocument();
- await restoreOptions();
document.querySelectorAll(".option-input").forEach(element => {
element.addEventListener("change", saveOptions);
@@ -64,47 +54,6 @@ document.addEventListener('DOMContentLoaded', async () => {
document.getElementById("spamfilter_threshold").addEventListener("input", check_spamfilter_threshold);
check_spamfilter_threshold({target: document.getElementById("spamfilter_threshold")});
- // Bind prompt API updates to connection type and model selects
- document.querySelectorAll(".option-input-specific").forEach(element => {
- element.addEventListener("change", updatePromptAPIInfo);
- });
- const conntype_el = document.getElementById(conntype_select_id);
- if (conntype_el) {
- conntype_el.addEventListener('change', updatePromptAPIInfo);
- const conntype_row = document.getElementById(conntype_select_id + '_tr');
- if (conntype_row) changeConnTypeRowColor(conntype_row, conntype_el);
- }
-
- // Specific integration toggle behavior
- const spamfilter_use_specific_integration_el = document.getElementById('spamfilter_use_specific_integration');
- let prefs_spamfilter_init = await browser.storage.sync.get({ spamfilter_enabled_accounts: [], connection_type: 'chatgpt_web' });
- if(prefs_spamfilter_init.connection_type == 'chatgpt_web'){
- spamfilter_use_specific_integration_el.checked = true;
- spamfilter_use_specific_integration_el.dispatchEvent(new Event('change'));
- spamfilter_use_specific_integration_el.disabled = true;
- }
- const conntype_end_el = document.getElementById('connection_ui_end');
- const conntype_row = document.getElementById(conntype_select_id + '_tr');
- spamfilter_use_specific_integration_el.addEventListener('change', async (event) => {
- document.querySelectorAll('.specific_integration_sub').forEach(tr => {
- tr.style.display = event.target.checked && tr.classList.contains('conntype_' + conntype_el.value) ? 'table-row' : 'none';
- });
- if (conntype_row) conntype_row.style.display = event.target.checked ? 'table-row' : 'none';
- if (conntype_end_el) conntype_end_el.style.display = event.target.checked ? 'table-row' : 'none';
- if(!event.target.checked){
- await clearPromptAPI('prompt_spamfilter');
- }else{
- updatePromptAPIInfo();
- }
- if (conntype_row) changeConnTypeRowColor(conntype_row, conntype_el);
- });
-
- // Initialize visibility per current toggle value
- document.querySelectorAll('.specific_integration_sub').forEach(tr => {
- tr.style.display = spamfilter_use_specific_integration_el.checked && tr.classList.contains('conntype_' + conntype_el.value) ? 'table-row' : 'none';
- });
- if (conntype_row) conntype_row.style.display = spamfilter_use_specific_integration_el.checked ? 'table-row' : 'none';
- if (conntype_end_el) conntype_end_el.style.display = spamfilter_use_specific_integration_el.checked ? 'table-row' : 'none';
let spamfilter_textarea = document.getElementById('spamfilter_prompt_text');
let spamfilter_save_btn = document.getElementById('btn_save_prompt');
@@ -202,9 +151,6 @@ document.addEventListener('DOMContentLoaded', async () => {
});
loadSpamReport();
- updateWarnings(model_prefix);
- // Sync prompt API/model once on load
- updatePromptAPIInfo();
});
function check_spamfilter_threshold(event) {
@@ -234,20 +180,6 @@ async function loadSpamReport(){
}
}
-async function updatePromptAPIInfo(){
- const conntypeEl = document.getElementById(conntype_select_id);
- if (!conntypeEl || !conntypeEl.value) return;
- const conntype = conntypeEl.value;
- const model_value = conntype.substring(0, conntype.length - 4) + '_model';
- const modelEl = document.getElementById(model_prefix + model_value);
- if (!modelEl) return;
- const model = modelEl.value;
- let spamfilter_prompt = await loadPrompt('prompt_spamfilter');
- if (!spamfilter_prompt) return;
- spamfilter_prompt.api = conntype;
- spamfilter_prompt.model = model;
- await savePrompt(spamfilter_prompt);
-}
// Function to populate the table
function populateTable(data) {