add_tags_force_lang option added. fixes #210

This commit is contained in:
mic 2025-01-02 23:35:30 +01:00
parent 1803020a6c
commit 7b433c91df
6 changed files with 48 additions and 12 deletions

View file

@ -819,7 +819,7 @@
"message": "Save",
"description": ""
},
"addtags_info_limit_num": {
"addtags_info_additional_statements": {
"message": "This statement will be added at the end of the prompt:",
"description": ""
},
@ -882,5 +882,17 @@
"OpenAIComp_force_model_ask": {
"message": "Insert here the model name you want to use.",
"description": ""
},
"prefs_OptionText_add_tags_force_lang": {
"message": "Force language",
"description": ""
},
"prefs_OptionText_add_tags_force_lang_Info": {
"message": "If checked, the tags language will be forced to match the language defined on the add-on options page, if specified.",
"description": ""
},
"prompt_add_tags_force_lang": {
"message": "The tags must be written in ",
"description": ""
}
}

View file

@ -182,7 +182,7 @@ export class mzta_Menus {
}
// console.log(">>>>>>>>>> finalSubs: " + JSON.stringify(finalSubs));
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, true) + (String(curr_prompt.need_signature) == "1" ? " " + await this.getDefaultSignature():"") + " " + chatgpt_lang;
fullPrompt = (placeholdersUtils.replacePlaceholders(curr_prompt.text, finalSubs, prefs_ph.placeholders_use_default_value, true) + (String(curr_prompt.need_signature) == "1" ? " " + await this.getDefaultSignature():"") + " " + chatgpt_lang).trim();
}
switch(curr_prompt.id){
@ -208,7 +208,7 @@ export class mzta_Menus {
switch(curr_prompt.id){
case 'prompt_add_tags': // Add tags to the email
let mail_tags = '';
let prefs_at = await browser.storage.sync.get({add_tags_maxnum: 3, connection_type: ''});
let prefs_at = await browser.storage.sync.get({add_tags_maxnum: 3, connection_type: '', add_tags_force_lang: true, default_chatgpt_lang: ''});
if((prefs_at.connection_type === '')||(prefs_at.connection_type === null)||(prefs_at.connection_type === undefined)||(prefs_at.connection_type === 'chatgpt_web')){
console.error("[ThunderAI | AddTags] Invalid connection type: " + prefs_at.connection_type);
return {ok:'0'};
@ -217,6 +217,9 @@ export class mzta_Menus {
if(add_tags_maxnum > 0){
fullPrompt += " " + browser.i18n.getMessage("prompt_add_tags_maxnum") + " " + add_tags_maxnum +".";
}
if(prefs_at.add_tags_force_lang && prefs_at.default_chatgpt_lang !== ''){
fullPrompt += " " + browser.i18n.getMessage("prompt_add_tags_force_lang") + " " + prefs_at.default_chatgpt_lang + ".";
}
this.logger.log("fullPrompt: " + fullPrompt);
// TODO: use the current API, abort if using chatgpt web
// COMMENTED TO DO TESTS

View file

@ -41,4 +41,5 @@ export const prefs_default = {
add_tags_maxnum: 3,
add_tags_hide_exclusions: false,
add_tags_first_uppercase: true,
add_tags_force_lang: true,
}

View file

@ -27,7 +27,7 @@
justify-content: space-between;
}
#addtags_info_limit_num{
#addtags_info_additional_statements{
display: none;
}

View file

@ -40,6 +40,15 @@
</label>
</td>
</tr>
<tr class="add_tags_tr">
<td><span>__MSG_prefs_OptionText_add_tags_force_lang__</span></td>
<td>
<label>
<input type="checkbox" id="add_tags_force_lang" name="add_tags_force_lang" class="option-input" />
__MSG_prefs_OptionText_add_tags_force_lang_Info__
</label>
</td>
</tr>
</table>
<div id="addtags_prompt_container">
<span class="section_title">__MSG_AddTags_prompt_text_title__</span><span id="addtags_prompt_unsaved" class="unsaved hidden"> __MSG_customPrompts_unsaved_changes__</span>
@ -50,7 +59,7 @@
<textarea id="addtags_prompt_text" rows="15"></textarea>
<ul class="autocomplete-list hidden"></ul>
</div>
<div id="addtags_info_limit_num"></div>
<div id="addtags_info_additional_statements"></div>
<div class="btn_div"><button id="btn_reset_prompt" disabled>__MSG_reset_default__</button><button id="btn_save_prompt" disabled>__MSG_save__</button></div>
</div>
<div id="addtags_excl_list_container">

View file

@ -74,9 +74,10 @@ document.addEventListener('DOMContentLoaded', async () => {
addtags_textarea.value = addtags_prompt.text;
addtags_reset_btn.disabled = (addtags_textarea.value === browser.i18n.getMessage('prompt_add_tags_full_text'));
document.getElementById('add_tags_maxnum').addEventListener('change', updateMaxTagsNumDesc);
document.getElementById('add_tags_maxnum').addEventListener('change', updateAdditionalPromptStatements);
document.getElementById('add_tags_force_lang').addEventListener('change', updateAdditionalPromptStatements);
updateMaxTagsNumDesc();
updateAdditionalPromptStatements();
autocompleteSuggestions = (await getPlaceholders(true)).filter(p => !(p.id === 'selected_text' || p.id === 'additional_text')).map(p => ({command: '{%'+p.id+'%}', type: p.type}));
textareaAutocomplete(addtags_textarea, autocompleteSuggestions, 1); // type_value = 1, only when reading an email
@ -110,11 +111,21 @@ document.addEventListener('DOMContentLoaded', async () => {
});
async function updateMaxTagsNumDesc(){
let prefs_maxt = await browser.storage.sync.get({add_tags_maxnum: 3});
let el_tag_limit = document.getElementById('addtags_info_limit_num');
if(prefs_maxt.add_tags_maxnum > 0){
el_tag_limit.textContent = browser.i18n.getMessage("addtags_info_limit_num") + " \"" + browser.i18n.getMessage("prompt_add_tags_maxnum") + " " + prefs_maxt.add_tags_maxnum +"\".";
async function updateAdditionalPromptStatements(){
let prefs_ = await browser.storage.sync.get({add_tags_maxnum: 3, add_tags_force_lang: true, default_chatgpt_lang: ''});
let el_tag_limit = document.getElementById('addtags_info_additional_statements');
if((prefs_.add_tags_maxnum > 0)||(prefs_.add_tags_force_lang && prefs_.default_chatgpt_lang !== '')){
el_tag_limit.textContent = browser.i18n.getMessage("addtags_info_additional_statements") + " \""
if(prefs_.add_tags_maxnum > 0){
el_tag_limit.textContent += browser.i18n.getMessage("prompt_add_tags_maxnum") + " " + prefs_.add_tags_maxnum +"."
}
if(prefs_.add_tags_force_lang && prefs_.default_chatgpt_lang !== ''){
if(prefs_.add_tags_maxnum > 0){
el_tag_limit.textContent += " "
}
el_tag_limit.textContent += browser.i18n.getMessage("prompt_add_tags_force_lang") + " " + prefs_.default_chatgpt_lang + "."
}
el_tag_limit.textContent += "\".";
el_tag_limit.style.display = 'block';
}else{
el_tag_limit.style.display = 'none';