diff --git a/_locales/en/messages.json b/_locales/en/messages.json index cdd3ad4d..4552126c 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -626,5 +626,13 @@ "placeholder_author": { "message": "Author", "description": "" + }, + "prefs_OptionText_placeholders_use_default_value": { + "message": "Placeholders: Use default value", + "description": "" + }, + "prefs_OptionText_placeholders_use_default_value_info": { + "message": "If checked, the placeholders will be filled with the default values when no value is provided. Otherwise, the placeholders will be kept in place.", + "description": "" } } \ No newline at end of file diff --git a/js/mzta-menus.js b/js/mzta-menus.js index 62c3502e..f1f54425 100644 --- a/js/mzta-menus.js +++ b/js/mzta-menus.js @@ -156,7 +156,8 @@ export class mzta_Menus { } } // console.log(">>>>>>>>>> finalSubs: " + JSON.stringify(finalSubs)); - fullPrompt = placeholdersUtils.replacePlaceholders(curr_prompt.text, finalSubs) + (String(curr_prompt.need_signature) == "1" ? " " + await this.getDefaultSignature():"") + " " + chatgpt_lang; + let prefs_ph = await browser.storage.sync.get({placeholders_use_default_value: false}); + fullPrompt = placeholdersUtils.replacePlaceholders(curr_prompt.text, finalSubs, prefs_ph.placeholders_use_default_value) + (String(curr_prompt.need_signature) == "1" ? " " + await this.getDefaultSignature():"") + " " + chatgpt_lang; } switch(curr_prompt.id){ diff --git a/js/mzta-placeholders.js b/js/mzta-placeholders.js index 60851f37..98ce7e30 100644 --- a/js/mzta-placeholders.js +++ b/js/mzta-placeholders.js @@ -36,63 +36,63 @@ const defaultPlaceholders = [ { id: 'mail_body', name: "__MSG_placeholder_mail_body__", - text: "", + default_value: "", type: 0, is_default: "1", }, { id: 'html_body', name: "__MSG_placeholder_html_body__", - text: "", + default_value: "", type: 0, is_default: "1", }, { id: 'mail_subject', name: "__MSG_placeholder_mail_subject__", - text: "", + default_value: "", type: 0, is_default: "1", }, { id: 'selected_text', name: "__MSG_placeholder_selected_text__", - text: "", + default_value: "", type: 0, is_default: "1", }, { id: 'additional_text', //TODO name: "__MSG_placeholder_additional_text__", - text: "", + default_value: "", type: 0, is_default: "1", }, { id: 'junk_score', name: "__MSG_placeholder_junk_score__", - text: "", + default_value: "0", type: 1, is_default: "1", }, { id: 'recipients', name: "__MSG_placeholder_recipients__", - text: "", + default_value: "", type: 0, is_default: "1", }, { id: 'cc_list', name: "__MSG_placeholder_cc_list__", - text: "", + default_value: "", type: 0, is_default: "1", }, { id: 'author', name: "__MSG_placeholder_author__", - text: "", + default_value: "", type: 0, is_default: "1", }, @@ -183,11 +183,12 @@ export const placeholdersUtils = { return matches; }, - replacePlaceholders(text, replacements) { + replacePlaceholders(text, replacements, use_dafault_value = false) { // Regular expression to match patterns like {%...%} return text.replace(/{%\s*(.*?)\s*%}/g, function(match, p1) { // p1 contains the key inside {% %} - return replacements[p1] || match; // Replace if found, otherwise keep the original + // Replace if found, otherwise keep the original or substitute with default value + return replacements[p1] || use_dafault_value ? defaultPlaceholders.find(ph => ph.id === p1).default_value : match; }); }, diff --git a/options/mzta-options-default.js b/options/mzta-options-default.js index 1f055670..f3b41862 100644 --- a/options/mzta-options-default.js +++ b/options/mzta-options-default.js @@ -32,4 +32,5 @@ export const prefs_default = { openai_comp_chat_name: 'OpenAI Comp', dynamic_menu_force_enter: false, dynamic_menu_order_alphabet: true, + placeholders_use_default_value: false, } \ No newline at end of file diff --git a/options/mzta-options.html b/options/mzta-options.html index 050d87b5..70ed66ac 100644 --- a/options/mzta-options.html +++ b/options/mzta-options.html @@ -81,6 +81,17 @@ + + + + + +