placeholders_use_default_value option added and implemented. see #146
This commit is contained in:
parent
969360e89f
commit
58f92610d5
5 changed files with 34 additions and 12 deletions
|
|
@ -626,5 +626,13 @@
|
||||||
"placeholder_author": {
|
"placeholder_author": {
|
||||||
"message": "Author",
|
"message": "Author",
|
||||||
"description": ""
|
"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": ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -156,7 +156,8 @@ export class mzta_Menus {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// console.log(">>>>>>>>>> finalSubs: " + JSON.stringify(finalSubs));
|
// 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){
|
switch(curr_prompt.id){
|
||||||
|
|
|
||||||
|
|
@ -36,63 +36,63 @@ const defaultPlaceholders = [
|
||||||
{
|
{
|
||||||
id: 'mail_body',
|
id: 'mail_body',
|
||||||
name: "__MSG_placeholder_mail_body__",
|
name: "__MSG_placeholder_mail_body__",
|
||||||
text: "",
|
default_value: "",
|
||||||
type: 0,
|
type: 0,
|
||||||
is_default: "1",
|
is_default: "1",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'html_body',
|
id: 'html_body',
|
||||||
name: "__MSG_placeholder_html_body__",
|
name: "__MSG_placeholder_html_body__",
|
||||||
text: "",
|
default_value: "",
|
||||||
type: 0,
|
type: 0,
|
||||||
is_default: "1",
|
is_default: "1",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'mail_subject',
|
id: 'mail_subject',
|
||||||
name: "__MSG_placeholder_mail_subject__",
|
name: "__MSG_placeholder_mail_subject__",
|
||||||
text: "",
|
default_value: "",
|
||||||
type: 0,
|
type: 0,
|
||||||
is_default: "1",
|
is_default: "1",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'selected_text',
|
id: 'selected_text',
|
||||||
name: "__MSG_placeholder_selected_text__",
|
name: "__MSG_placeholder_selected_text__",
|
||||||
text: "",
|
default_value: "",
|
||||||
type: 0,
|
type: 0,
|
||||||
is_default: "1",
|
is_default: "1",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'additional_text', //TODO
|
id: 'additional_text', //TODO
|
||||||
name: "__MSG_placeholder_additional_text__",
|
name: "__MSG_placeholder_additional_text__",
|
||||||
text: "",
|
default_value: "",
|
||||||
type: 0,
|
type: 0,
|
||||||
is_default: "1",
|
is_default: "1",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'junk_score',
|
id: 'junk_score',
|
||||||
name: "__MSG_placeholder_junk_score__",
|
name: "__MSG_placeholder_junk_score__",
|
||||||
text: "",
|
default_value: "0",
|
||||||
type: 1,
|
type: 1,
|
||||||
is_default: "1",
|
is_default: "1",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'recipients',
|
id: 'recipients',
|
||||||
name: "__MSG_placeholder_recipients__",
|
name: "__MSG_placeholder_recipients__",
|
||||||
text: "",
|
default_value: "",
|
||||||
type: 0,
|
type: 0,
|
||||||
is_default: "1",
|
is_default: "1",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'cc_list',
|
id: 'cc_list',
|
||||||
name: "__MSG_placeholder_cc_list__",
|
name: "__MSG_placeholder_cc_list__",
|
||||||
text: "",
|
default_value: "",
|
||||||
type: 0,
|
type: 0,
|
||||||
is_default: "1",
|
is_default: "1",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'author',
|
id: 'author',
|
||||||
name: "__MSG_placeholder_author__",
|
name: "__MSG_placeholder_author__",
|
||||||
text: "",
|
default_value: "",
|
||||||
type: 0,
|
type: 0,
|
||||||
is_default: "1",
|
is_default: "1",
|
||||||
},
|
},
|
||||||
|
|
@ -183,11 +183,12 @@ export const placeholdersUtils = {
|
||||||
return matches;
|
return matches;
|
||||||
},
|
},
|
||||||
|
|
||||||
replacePlaceholders(text, replacements) {
|
replacePlaceholders(text, replacements, use_dafault_value = false) {
|
||||||
// Regular expression to match patterns like {%...%}
|
// Regular expression to match patterns like {%...%}
|
||||||
return text.replace(/{%\s*(.*?)\s*%}/g, function(match, p1) {
|
return text.replace(/{%\s*(.*?)\s*%}/g, function(match, p1) {
|
||||||
// p1 contains the key inside {% %}
|
// 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;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -32,4 +32,5 @@ export const prefs_default = {
|
||||||
openai_comp_chat_name: 'OpenAI Comp',
|
openai_comp_chat_name: 'OpenAI Comp',
|
||||||
dynamic_menu_force_enter: false,
|
dynamic_menu_force_enter: false,
|
||||||
dynamic_menu_order_alphabet: true,
|
dynamic_menu_order_alphabet: true,
|
||||||
|
placeholders_use_default_value: false,
|
||||||
}
|
}
|
||||||
|
|
@ -81,6 +81,17 @@
|
||||||
</label>
|
</label>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><label>
|
||||||
|
<span>__MSG_prefs_OptionText_placeholders_use_default_value__</span>
|
||||||
|
</label></td>
|
||||||
|
<td>
|
||||||
|
<label>
|
||||||
|
<input type="checkbox" id="placeholders_use_default_value" name="placeholders_use_default_value" class="option-input" />
|
||||||
|
<span>__MSG_prefs_OptionText_placeholders_use_default_value_info__</span>
|
||||||
|
</label>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<label>
|
<label>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue