loading and saving the tags exclusion list. see #183

This commit is contained in:
mic 2024-12-15 22:31:47 +01:00
parent d8765df191
commit 3ba741259b
5 changed files with 46 additions and 4 deletions

View file

@ -822,5 +822,9 @@
"reset_default": {
"message": "Reset to default",
"description": ""
},
"addtags_excl_list_infoline2": {
"message": "Add a word per line, or separated by a comma.",
"description": ""
}
}

View file

@ -0,0 +1,10 @@
export async function addTags_getExclusionList() {
let prefs_excluded_tags = await browser.storage.local.get({add_tags_exclusions: []});
return prefs_excluded_tags.add_tags_exclusions;
}
export function addTags_setExclusionList(add_tags_exclusions) {
browser.storage.local.set({add_tags_exclusions: add_tags_exclusions});
}

View file

@ -18,7 +18,7 @@
}
#addtags_excl_list{
width: 100%;
width: 30em;
}
.btn_div{

View file

@ -23,8 +23,9 @@
<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">
__MSG_AddTags_excl_list_title__
<br><span class="infoline">__MSG_AddTags_excl_list_infoline__</span>
__MSG_AddTags_excl_list_title__<span id="excl_list_unsaved" class="unsaved hidden"> __MSG_customPrompts_unsaved_changes__</span>
<br><span class="infoline">__MSG_AddTags_excl_list_infoline__
<br>__MSG_AddTags_excl_list_infoline2__</span>
<br><textarea id="addtags_excl_list" rows="15"></textarea>
<div class="btn_div"><button id="btn_save_excl_list" disabled>__MSG_save__</button></div>
</div>

View file

@ -19,11 +19,14 @@
import { getSpecialPrompts, setSpecialPrompts } from "../../js/mzta-prompts.js";
import { getPlaceholders } from "../../js/mzta-placeholders.js";
import { textareaAutocomplete } from "../../js/mzta-placeholders-autocomplete.js";
import { addTags_getExclusionList, addTags_setExclusionList } from "../../js/mzta-addatags-exclusion-list.js";
let autocompleteSuggestions = [];
document.addEventListener('DOMContentLoaded', async () => {
i18n.updateDocument();
let addtags_textarea = document.getElementById('addtags_prompt_text');
let addtags_save_btn = document.getElementById('btn_save_prompt');
let addtags_reset_btn = document.getElementById('btn_reset_prompt');
@ -69,5 +72,29 @@ document.addEventListener('DOMContentLoaded', async () => {
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
i18n.updateDocument();
let excl_list_textarea = document.getElementById('addtags_excl_list');
let excl_list_save_btn = document.getElementById('btn_save_excl_list');
let excl_list_value = await addTags_getExclusionList();
let excl_list_string = excl_list_value.join('\n');
excl_list_textarea.value = excl_list_string;
excl_list_textarea.addEventListener('input', (event) => {
excl_list_save_btn.disabled = (event.target.value === excl_list_string);
if(excl_list_save_btn.disabled){
document.getElementById('excl_list_unsaved').classList.add('hidden');
} else {
document.getElementById('excl_list_unsaved').classList.remove('hidden');
}
});
excl_list_save_btn.addEventListener('click', () => {
let excl_array_new = excl_list_textarea.value.split(/[\n,]+/);
excl_array_new = Array.from(new Set(excl_array_new.map(item => item.trim().toLowerCase()))).sort();
addTags_setExclusionList(excl_array_new);
excl_list_save_btn.disabled = true;
excl_list_textarea.value = excl_array_new.join('\n');
});
});