commit
a7dafb906c
9 changed files with 81 additions and 25 deletions
|
|
@ -12,6 +12,7 @@
|
|||
<li><i>[All APIs]</i> In the API WebChat is now possibile to select a part of the answer and use only that [<a href="https://github.com/micz/ThunderAI/issues/356">#356</a>].</li>
|
||||
<li><i>[All APIs]</i> Setting the "Max prompt length" to zero on the options page will disable the length check when sending a prompt to the AI. [<a href="https://github.com/micz/ThunderAI/issues/380">#380</a>].</li>
|
||||
<li><i>[All APIs]</i> Added a button to the options page to reset the 'Max prompt length' value to its default.</li>
|
||||
<li><i>[All APIs]</i> Adding tags automatically or with the context menu will now use also tags not created by ThunderAI [<a href="https://github.com/micz/ThunderAI/issues/390">#390</a>].</li>
|
||||
<li>Fix: in the Spamfilter page the unsaved changes warning is now correctly shown.</li>
|
||||
<li>Fix: The default keyboard shortcut is no longer enforced at every Thunderbird startup [<a href="https://github.com/micz/ThunderAI/issues/384">#384</a>].</li>
|
||||
<li>Fix: Incoming email processing now works correctly when auto-tagging is enabled and the full tagging feature is subsequently disabled.</li>
|
||||
|
|
|
|||
|
|
@ -1116,7 +1116,7 @@
|
|||
"description": ""
|
||||
},
|
||||
"prefs_OptionText_add_tags_auto_force_existing": {
|
||||
"message": "Force existing tags when autotagging",
|
||||
"message": "Force existing tags when autotagging or using the context menu",
|
||||
"description": ""
|
||||
},
|
||||
"prefs_OptionText_add_tags_auto_force_existing_Info": {
|
||||
|
|
|
|||
|
|
@ -16,8 +16,9 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
// These methods are also defined in the file /js/mzta-compose-script.js
|
||||
|
||||
|
||||
// These methods are also defined in the file /js/mzta-compose-script.js
|
||||
export async function addTags_getExclusionList() {
|
||||
let prefs_excluded_tags = await browser.storage.local.get({add_tags_exclusions: []});
|
||||
return prefs_excluded_tags.add_tags_exclusions;
|
||||
|
|
|
|||
|
|
@ -350,21 +350,66 @@ export async function createTag(tag) {
|
|||
}
|
||||
}
|
||||
|
||||
export function checkIfTagExists(tag, tags_list) {
|
||||
return tags_list.hasOwnProperty("$ta-" + sanitizeString(tag));
|
||||
// export function checkIfTagExists(tag, tags_list) {
|
||||
// console.log(">>>>>>>>>>> checkIfTagExists tags_list: " + JSON.stringify(tags_list));
|
||||
// console.log(">>>>>>>>>>> checkIfTagExists tag: " + tag);
|
||||
// return tags_list.hasOwnProperty("$ta-" + sanitizeString(tag));
|
||||
// }
|
||||
|
||||
export function checkIfTagLabelExists(tag_label, tags_list) {
|
||||
// console.log(">>>>>>>>>>> checkIfTagExists tags_list: " + JSON.stringify(tags_list));
|
||||
// console.log(">>>>>>>>>>> checkIfTagExists tag_label: " + tag_label);
|
||||
const lowerTagLabel = tag_label.toLowerCase();
|
||||
return Object.values(tags_list).some(label => label.tag.toLowerCase() === lowerTagLabel);
|
||||
}
|
||||
|
||||
// export async function assignTagsToMessage(messageId, tags) {
|
||||
// console.log(">>>>>>>>>>> assignTagsToMessage messageId: tags: " + JSON.stringify(tags));
|
||||
// tags = tags.map(tag => `$ta-${sanitizeString(tag)}`);
|
||||
// let msg_prop = await browser.messages.get(messageId);
|
||||
// tags = tags.concat(msg_prop.tags || []);
|
||||
// try {
|
||||
// return browser.messages.update(messageId, {tags: tags});
|
||||
// } catch (error) {
|
||||
// console.error('[ThunderAI] Error assigning tag [messageId: ', messageId, ' - tag: ', tag, ']:', error);
|
||||
// }
|
||||
// }
|
||||
|
||||
export async function assignTagsToMessage(messageId, tags) {
|
||||
tags = tags.map(tag => `$ta-${sanitizeString(tag)}`);
|
||||
// console.log(">>>>>>>>>>> assignTagsToMessage tags: " + JSON.stringify(tags));
|
||||
let all_tags_list = await getTagsList();
|
||||
all_tags_list = all_tags_list[1];
|
||||
tags = getTagsKeyFromLabel(tags, all_tags_list);
|
||||
// console.log(">>>>>>>>>>> assignTagsToMessage tags after conversion: " + JSON.stringify(tags));
|
||||
let msg_prop = await browser.messages.get(messageId);
|
||||
// console.log(">>>>>>>>>>> assignTagsToMessage msg_prop.tags: " + JSON.stringify(msg_prop.tags));
|
||||
tags = tags.concat(msg_prop.tags || []);
|
||||
tags = [...new Set(tags)];
|
||||
// console.log(">>>>>>>>>>> assignTagsToMessage tags after concat: " + JSON.stringify(tags));
|
||||
try {
|
||||
return browser.messages.update(messageId, {tags: tags});
|
||||
await browser.messages.update(messageId, {tags: tags});
|
||||
return tags; // Return the updated tags for confirmation
|
||||
} catch (error) {
|
||||
console.error('[ThunderAI] Error assigning tag [messageId: ', messageId, ' - tag: ', tag, ']:', error);
|
||||
}
|
||||
}
|
||||
|
||||
function getTagsKeyFromLabel(tag_names, all_tags_list) {
|
||||
const result = [];
|
||||
|
||||
tag_names.forEach(name => {
|
||||
const lowerName = name.toLowerCase();
|
||||
const match = Object.entries(all_tags_list).find(
|
||||
([, value]) => value.tag.toLowerCase() === lowerName
|
||||
);
|
||||
if (match) {
|
||||
result.push(match[0]);
|
||||
}
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function sanitizeString(input) {
|
||||
input = input.toLowerCase();
|
||||
// Define the regex to match valid characters
|
||||
|
|
|
|||
|
|
@ -20,12 +20,13 @@ import { mzta_script } from './js/mzta-chatgpt.js';
|
|||
import { prefs_default } from './options/mzta-options-default.js';
|
||||
import { mzta_Menus } from './js/mzta-menus.js';
|
||||
import { taLogger } from './js/mzta-logger.js';
|
||||
import { getCurrentIdentity, getOriginalBody, replaceBody, setBody, i18nConditionalGet, generateCallID, migrateCustomPromptsStorage, migrateDefaultPromptsPropStorage, getGPTWebModelString, getTagsList, createTag, assignTagsToMessage, checkIfTagExists, getActiveSpecialPromptsIDs, checkSparksPresence, getMessages, getMailBody, extractJsonObject, contextMenuID_AddTags, contextMenuID_Spamfilter, sanitizeChatGPTModelData, sanitizeChatGPTWebCustomData, stripHtmlKeepLines } from './js/mzta-utils.js';
|
||||
import { getCurrentIdentity, getOriginalBody, replaceBody, setBody, i18nConditionalGet, generateCallID, migrateCustomPromptsStorage, migrateDefaultPromptsPropStorage, getGPTWebModelString, getTagsList, createTag, assignTagsToMessage, checkIfTagLabelExists, getActiveSpecialPromptsIDs, checkSparksPresence, getMessages, getMailBody, extractJsonObject, contextMenuID_AddTags, contextMenuID_Spamfilter, sanitizeChatGPTModelData, sanitizeChatGPTWebCustomData, stripHtmlKeepLines } from './js/mzta-utils.js';
|
||||
import { taPromptUtils } from './js/mzta-utils-prompt.js';
|
||||
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';
|
||||
|
||||
browser.runtime.onInstalled.addListener(({ reason, previousVersion }) => {
|
||||
// console.log(">>>>>>>>>>> onInstalled: " + JSON.stringify(reason) + ", previousVersion: " + previousVersion);
|
||||
|
|
@ -160,16 +161,26 @@ async function _assign_tags(_data, create_new_tags = true) {
|
|||
// console.log(">>>>>>>>>>>>>>> all_tags_list: " + JSON.stringify(all_tags_list));
|
||||
taLog.log("assign_tags data: " + JSON.stringify(_data));
|
||||
let new_tags = [];
|
||||
for (const tag of _data.tags) {
|
||||
// console.log(">>>>>>>>>>>>>>> tag: " + tag);
|
||||
if (create_new_tags && !checkIfTagExists(tag, all_tags_list)) {
|
||||
let add_tags_exclusions_list = await addTags_getExclusionList();
|
||||
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())
|
||||
)
|
||||
);
|
||||
if(!create_new_tags){
|
||||
taLog.log("Not creating new tags, only assigning existing ones...");
|
||||
}
|
||||
for (const tag of tags_final) {
|
||||
// console.log(">>>>>>>>>>>>>>> tag: " + JSON.stringify(tag));
|
||||
if (create_new_tags && !checkIfTagLabelExists(tag, all_tags_list)) {
|
||||
taLog.log("Creating tag: " + tag);
|
||||
await createTag(tag);
|
||||
}
|
||||
new_tags.push(tag);
|
||||
}
|
||||
await assignTagsToMessage(_data.messageId, new_tags);
|
||||
taLog.log("Assigned tags: " + JSON.stringify(new_tags));
|
||||
let added_tags = await assignTagsToMessage(_data.messageId, new_tags);
|
||||
taLog.log("Assigned tags: " + JSON.stringify(added_tags));
|
||||
}
|
||||
|
||||
messenger.runtime.onMessage.addListener((message, sender, sendResponse) => {
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@
|
|||
<li><i>[All APIs]</i> In the API WebChat is now possibile to select a part of the answer and use only that [<a href="https://github.com/micz/ThunderAI/issues/356">#356</a>].</li>
|
||||
<li><i>[All APIs]</i> Setting the "Max prompt length" to zero on the options page will disable the length check when sending a prompt to the AI. [<a href="https://github.com/micz/ThunderAI/issues/380">#380</a>].</li>
|
||||
<li><i>[All APIs]</i> Added a button to the options page to reset the 'Max prompt length' value to its default.</li>
|
||||
<li><i>[All APIs]</i> Adding tags automatically or with the context menu will now use also tags not created by ThunderAI [<a href="https://github.com/micz/ThunderAI/issues/390">#390</a>].</li>
|
||||
<li>Fix: In the Spamfilter page the unsaved changes warning is now correctly shown.</li>
|
||||
<li>Fix: The default keyboard shortcut is no longer enforced at every Thunderbird startup [<a href="https://github.com/micz/ThunderAI/issues/384">#384</a>].</li>
|
||||
<li>Fix: Incoming email processing now works correctly when auto-tagging is enabled and the full tagging feature is subsequently disabled.</li>
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@
|
|||
justify-content: space-between;
|
||||
}
|
||||
|
||||
#addtags_info_additional_statements, #add_tags_auto_force_existing_tr, #add_tags_auto_only_inbox_tr{
|
||||
#addtags_info_additional_statements, #add_tags_auto_only_inbox_tr{
|
||||
display: none;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -59,15 +59,6 @@
|
|||
</label>
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="add_tags_tr add_tags_auto" id="add_tags_auto_force_existing_tr">
|
||||
<td><span>__MSG_prefs_OptionText_add_tags_auto_force_existing__</span></td>
|
||||
<td>
|
||||
<label>
|
||||
<input type="checkbox" id="add_tags_auto_force_existing" name="add_tags_auto_force_existing" class="option-input" />
|
||||
__MSG_prefs_OptionText_add_tags_auto_force_existing_Info__
|
||||
</label>
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="add_tags_tr add_tags_auto" id="add_tags_auto_only_inbox_tr">
|
||||
<td><span>__MSG_prefs_OptionText_add_tags_auto_only_inbox__</span></td>
|
||||
<td>
|
||||
|
|
@ -86,6 +77,15 @@
|
|||
</label>
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="add_tags_tr">
|
||||
<td><span>__MSG_prefs_OptionText_add_tags_auto_force_existing__</span></td>
|
||||
<td>
|
||||
<label>
|
||||
<input type="checkbox" id="add_tags_auto_force_existing" name="add_tags_auto_force_existing" class="option-input" />
|
||||
__MSG_prefs_OptionText_add_tags_auto_force_existing_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>
|
||||
|
|
|
|||
|
|
@ -54,17 +54,14 @@ document.addEventListener('DOMContentLoaded', async () => {
|
|||
});
|
||||
|
||||
let add_tags_auto_el = document.getElementById('add_tags_auto');
|
||||
let add_tags_auto_force_existing_tr = document.getElementById('add_tags_auto_force_existing_tr');
|
||||
let add_tags_auto_only_inbox_tr = document.getElementById('add_tags_auto_only_inbox_tr');
|
||||
let account_selector_container = document.getElementById('account_selector_container');
|
||||
let add_tags_auto_infoline = document.getElementById('add_tags_auto_infoline');
|
||||
add_tags_auto_el.addEventListener('click', (event) => {
|
||||
add_tags_auto_force_existing_tr.style.display = event.target.checked ? 'table-row' : 'none';
|
||||
add_tags_auto_only_inbox_tr.style.display = event.target.checked ? 'table-row' : 'none';
|
||||
account_selector_container.style.display = event.target.checked ? 'block' : 'none';
|
||||
add_tags_auto_infoline.style.display = event.target.checked ? 'inline' : 'none';
|
||||
});
|
||||
add_tags_auto_force_existing_tr.style.display = add_tags_auto_el.checked ? 'table-row' : 'none';
|
||||
add_tags_auto_only_inbox_tr.style.display = add_tags_auto_el.checked ? 'table-row' : 'none';
|
||||
account_selector_container.style.display = add_tags_auto_el.checked ? 'block' : 'none';
|
||||
add_tags_auto_infoline.style.display = add_tags_auto_el.checked ? 'inline' : 'none';
|
||||
|
|
|
|||
Loading…
Reference in a new issue