adding options to manage accounts for autotagging. see #327

This commit is contained in:
Mic 2025-04-22 00:16:00 +02:00
parent 775882de23
commit ce3d392628
6 changed files with 80 additions and 2 deletions

View file

@ -1350,5 +1350,13 @@
"ask_chatgptweb_permission_ok": {
"message": "Permission granted. You can click here to close this tab and return to the main window.",
"description": ""
},
"AccountSelector_AutoTags": {
"message": "Choose the accounts where auto-tagging is enabled",
"description": ""
},
"AccountSelector_AutoTags_infoline": {
"message": "Each change is saved immediately.",
"description": ""
}
}

View file

@ -43,6 +43,17 @@ function fixMsgHeader(msgHeader) {
return msgHeader;
}
export async function getAccountsList() {
let accounts = await browser.accounts.list();
let accounts_array = [];
for (let account of accounts) {
let account_id = account.id;
let account_name = account.name;
accounts_array.push({id: account_id, name: account_name});
}
return accounts_array;
}
export async function getCurrentIdentity(msgHeader, getFull = false) {
let identities_array = [];
let fallback_identity = '';

View file

@ -51,6 +51,7 @@ export const prefs_default = {
add_tags_auto_force_existing: false,
add_tags_auto_only_inbox: true,
add_tags_context_menu: true,
add_tags_enabled_accounts: [],
get_calendar_event: true,
get_task: true,
calendar_enforce_timezone: false,

View file

@ -12,7 +12,7 @@
font-style: italic;
}
#addtags_excl_list_container{
#addtags_excl_list_container, #account_selector_container{
width: 90%;
margin: 40px auto;
}
@ -21,6 +21,15 @@
width: 30em;
}
#account_selector_checkboxes{
padding: 10px;
border: 1px solid gray;
width: 24em;
margin-bottom: 10px;
margin-top: 10px;;
}
.btn_div{
width: 100%;
display: flex;

View file

@ -106,6 +106,13 @@
<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>
<div id="account_selector_container">
<div id="account_selector_info"><span class="section_title">__MSG_AccountSelector_AutoTags__</span>
<br><span class="infoline">__MSG_AccountSelector_AutoTags_infoline__</span></div>
<div id="account_selector_checkboxes"></div>
<button type="button" id="accounts_select_all">Select All</button>
<button type="button" id="accounts_deselect_all">Deselect All</button>
</div>
<script src="mzta-add-tags.js" type="module"></script>
<script src="../../js/mzta-i18n.js"></script>
</body>

View file

@ -22,7 +22,7 @@ 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";
import { getAccountsList } from "../../js/mzta-utils.js";
let autocompleteSuggestions = [];
let taLog = new taLogger("mzta-addtags-page",true);
@ -118,6 +118,48 @@ document.addEventListener('DOMContentLoaded', async () => {
document.getElementById('excl_list_unsaved').classList.add('hidden');
});
//Accounts manager
let accounts = await getAccountsList();
const accountsContainer = document.getElementById('account_selector_checkboxes');
accounts.forEach(account => {
const accountLabel = document.createElement('label');
const accountCheckbox = document.createElement('input');
accountCheckbox.type = 'checkbox';
accountCheckbox.classList.add('accountCheckbox');
accountCheckbox.value = account.id;
accountLabel.appendChild(accountCheckbox);
accountLabel.appendChild(document.createTextNode(account.name));
accountsContainer.appendChild(accountLabel);
accountsContainer.appendChild(document.createElement('br'));
});
let prefs_add_tags = await browser.storage.sync.get({ add_tags_enabled_accounts: [] });
let add_tags_enabled_accounts = prefs_add_tags.add_tags_enabled_accounts;
document.querySelectorAll('.accountCheckbox').forEach(checkbox => {
if (add_tags_enabled_accounts.length === 0 || add_tags_enabled_accounts.includes(checkbox.value)) {
checkbox.checked = true;
} else {
checkbox.checked = false;
}
});
document.querySelectorAll('.accountCheckbox').forEach(checkbox => {
checkbox.addEventListener('change', () => {
let selectedAccounts = Array.from(document.querySelectorAll('.accountCheckbox:checked')).map(checkbox => checkbox.value);
browser.storage.sync.set({ add_tags_enabled_accounts: selectedAccounts });
});
});
document.getElementById('accounts_select_all').addEventListener('click', () => {
let checkboxes = document.querySelectorAll('.accountCheckbox');
checkboxes.forEach(checkbox => checkbox.checked = true);
});
document.getElementById('accounts_deselect_all').addEventListener('click', () => {
let checkboxes = document.querySelectorAll('.accountCheckbox');
checkboxes.forEach(checkbox => checkbox.checked = false);
});
});