added an option to exclude the tag only with an exact match. see #395

This commit is contained in:
mic 2025-06-13 23:10:23 +02:00
parent 015a6f68a4
commit 6c86e02b6f
6 changed files with 65 additions and 12 deletions

View file

@ -1563,5 +1563,13 @@
"chatgpt_win_change_reply_type": {
"message": "Click to change the reply type",
"description": ""
},
"prefs_OptionText_add_tags_exclusions_exact_match": {
"message": "Exclusions exact match",
"description": ""
},
"prefs_OptionText_add_tags_exclusions_exact_match_Info": {
"message": "If checked, the tags in the exclusion list will be matched exactly, otherwise they will be matched partially.",
"description": ""
}
}

View file

@ -26,4 +26,15 @@ export async function addTags_getExclusionList() {
export function addTags_setExclusionList(add_tags_exclusions) {
browser.storage.local.set({add_tags_exclusions: add_tags_exclusions});
}
export function checkExcludedTag(tag, excluded_word, exact_match = false) {
// Check if the tag is in the exclusion list
if (excluded_word === '') {
return false; // No exclusion word, so no exclusion
}
if(exact_match) {
return tag.toLowerCase() === excluded_word.toLowerCase();
}
return tag.toLowerCase().includes(excluded_word.toLowerCase());
}

View file

@ -335,6 +335,17 @@ switch (message.command) {
function addTags_setExclusionList(add_tags_exclusions) {
browser.storage.local.set({add_tags_exclusions: add_tags_exclusions});
}
function checkExcludedTag(tag, excluded_word, exact_match = false) {
// Check if the tag is in the exclusion list
if (excluded_word === '') {
return false; // No exclusion word, so no exclusion
}
if(exact_match) {
return tag.toLowerCase() === excluded_word.toLowerCase();
}
return tag.toLowerCase().includes(excluded_word.toLowerCase());
}
// ===================================================================================
// Create and append the styles
@ -463,7 +474,7 @@ switch (message.command) {
no_submit = true;
}
let prefs_tags = await browser.storage.sync.get({add_tags_hide_exclusions: false});
let prefs_tags = await browser.storage.sync.get({add_tags_hide_exclusions: false, add_tags_exclusions_exact_match: false});
let add_tags_exclusions_list = await addTags_getExclusionList();
// console.log(">>>>>>>>>>>>> add_tags_exclusions_list: " + JSON.stringify(add_tags_exclusions_list));
@ -472,7 +483,7 @@ switch (message.command) {
.filter(word => word !== '')
.map(word => {
const isExcluded = add_tags_exclusions_list.some(exclusion =>
word.toLowerCase().includes(exclusion.toLowerCase())
checkExcludedTag(word, exclusion, prefs_tags.add_tags_exclusions_exact_match)
);
return {

View file

@ -26,7 +26,7 @@ import { mzta_specialCommand } from './js/mzta-special-commands.js';
import { getSpamFilterPrompt } from './js/mzta-prompts.js';
import { taSpamReport } from './js/mzta-spamreport.js';
import { taWorkingStatus } from './js/mzta-working-status.js';
import { addTags_getExclusionList } from './js/mzta-addatags-exclusion-list.js';
import { addTags_getExclusionList, checkExcludedTag } from './js/mzta-addatags-exclusion-list.js';
browser.runtime.onInstalled.addListener(({ reason, previousVersion }) => {
// console.log(">>>>>>>>>>> onInstalled: " + JSON.stringify(reason) + ", previousVersion: " + previousVersion);
@ -155,7 +155,7 @@ async function _reload_menus() {
return true;
}
async function _assign_tags(_data, create_new_tags = true) {
async function _assign_tags(_data, create_new_tags = true, exclusions_exact_match = false) {
let all_tags_list = await getTagsList();
all_tags_list = all_tags_list[1];
// console.log(">>>>>>>>>>>>>>> all_tags_list: " + JSON.stringify(all_tags_list));
@ -165,7 +165,7 @@ async function _assign_tags(_data, create_new_tags = true) {
taLog.log("add_tags_exclusions_list: " + JSON.stringify(add_tags_exclusions_list));
const tags_final = _data.tags.filter(tag =>
!add_tags_exclusions_list.some(exclusion =>
tag.toLowerCase().includes(exclusion.toLowerCase())
checkExcludedTag(tag, exclusion, exclusions_exact_match)
)
);
if(!create_new_tags){
@ -216,15 +216,15 @@ messenger.runtime.onMessage.addListener((message, sender, sendResponse) => {
async function _replyMessage(message) {
let paragraphsHtmlString = message.text;
//console.log(">>>>>>>>>>>> paragraphsHtmlString: " + paragraphsHtmlString);
let prefs = await browser.storage.sync.get({reply_type: prefs_default.reply_type, composing_plain_text: prefs_default.composing_plain_text});
if(prefs.composing_plain_text){
let prefs_reply = await browser.storage.sync.get({reply_type: prefs_default.reply_type, composing_plain_text: prefs_default.composing_plain_text});
if(prefs_reply.composing_plain_text){
paragraphsHtmlString = stripHtmlKeepLines(paragraphsHtmlString);
}
//console.log('reply_type: ' + prefs.reply_type);
//console.log('reply_type: ' + prefs_reply.reply_type);
let replyType = 'replyToAll';
// console.log(">>>>>>>>>>> chatgpt_replyMessage replyType: " + message.replyType);
if (typeof message.replyType === "undefined" || message.replyType === null || message.replyType === "") {
message.replyType = prefs.reply_type;
message.replyType = prefs_reply.reply_type;
}
if(message.replyType === 'reply_sender'){
replyType = 'replyToSender';
@ -301,7 +301,11 @@ messenger.runtime.onMessage.addListener((message, sender, sendResponse) => {
return _popup_menu_ready();
break;
case 'assign_tags':
return _assign_tags(message);
async function _do_assign_tags(message) {
let prefs_assign_tags = await browser.storage.sync.get({add_tags_exclusions_exact_match: prefs_default.add_tags_exclusions_exact_match});
return _assign_tags(message,true, prefs_assign_tags.add_tags_exclusions_exact_match);
}
return _do_assign_tags(message);
break;
case 'api_send_custom_text':
browser.tabs.sendMessage(message.tabId, { command: "api_send_custom_text", custom_text: message.custom_text });
@ -951,7 +955,16 @@ const newEmailListener = (folder, messagesList) => {
async function processEmails(messages, addTagsAuto, spamFilter) {
taWorkingStatus.startWorking();
let prefs_aats = await browser.storage.sync.get({ add_tags_maxnum: prefs_default.add_tags_maxnum, connection_type: prefs_default.connection_type, add_tags_force_lang: prefs_default.add_tags_force_lang, default_chatgpt_lang: prefs_default.default_chatgpt_lang, add_tags_auto_force_existing: prefs_default.add_tags_auto_force_existing, add_tags_enabled_accounts: prefs_default.add_tags_enabled_accounts, spamfilter_enabled_accounts: prefs_default.spamfilter_enabled_accounts });
let prefs_aats = await browser.storage.sync.get({
add_tags_maxnum: prefs_default.add_tags_maxnum,
connection_type: prefs_default.connection_type,
add_tags_force_lang: prefs_default.add_tags_force_lang,
default_chatgpt_lang: prefs_default.default_chatgpt_lang,
add_tags_auto_force_existing: prefs_default.add_tags_auto_force_existing,
add_tags_enabled_accounts: prefs_default.add_tags_enabled_accounts,
add_tags_exclusions_exact_match: prefs_default.add_tags_exclusions_exact_match,
spamfilter_enabled_accounts: prefs_default.spamfilter_enabled_accounts,
});
for await (let message of messages) {
let curr_fullMessage = null;
@ -990,7 +1003,7 @@ async function processEmails(messages, addTagsAuto, spamFilter) {
}
taLog.log("tags_current_email: " + tags_current_email);
let _data = { messageId: message.id, tags: tags_current_email.split(/,\s*/) };
_assign_tags(_data, !prefs_aats.add_tags_auto_force_existing);
_assign_tags(_data, !prefs_aats.add_tags_auto_force_existing, prefs_aats.add_tags_exclusions_exact_match);
}
if (spamFilter) {

View file

@ -56,6 +56,7 @@ export const prefs_default = {
add_tags: false,
add_tags_maxnum: 3,
add_tags_hide_exclusions: false,
add_tags_exclusions_exact_match: false,
add_tags_first_uppercase: true,
add_tags_force_lang: true,
add_tags_auto: false,

View file

@ -22,6 +22,15 @@
</label>
</td>
</tr>
<tr class="add_tags_tr">
<td><span>__MSG_prefs_OptionText_add_tags_exclusions_exact_match__</span></td>
<td>
<label>
<input type="checkbox" id="add_tags_exclusions_exact_match" name="add_tags_exclusions_exact_match" class="option-input" />
__MSG_prefs_OptionText_add_tags_exclusions_exact_match_Info__
</label>
</td>
</tr>
<tr class="add_tags_tr">
<td><span>__MSG_prefs_OptionText_add_tags_hide_exclusions__</span></td>
<td>