parent
7e5ba820c2
commit
c5c7694d51
3 changed files with 32 additions and 7 deletions
|
|
@ -1496,6 +1496,10 @@
|
||||||
"message": "Summarize",
|
"message": "Summarize",
|
||||||
"description": ""
|
"description": ""
|
||||||
},
|
},
|
||||||
|
"context_menu_mzta-translate": {
|
||||||
|
"message": "Translate",
|
||||||
|
"description": ""
|
||||||
|
},
|
||||||
"noActiveCalendar": {
|
"noActiveCalendar": {
|
||||||
"message": "No editable calendar found!",
|
"message": "No editable calendar found!",
|
||||||
"description": ""
|
"description": ""
|
||||||
|
|
|
||||||
|
|
@ -27,10 +27,12 @@ export const getMenuContextDisplay = () => 'message_display_action_menu';
|
||||||
export const contextMenuID_AddTags = 'mzta-add-tags';
|
export const contextMenuID_AddTags = 'mzta-add-tags';
|
||||||
export const contextMenuID_Spamfilter = 'mzta-spamfilter';
|
export const contextMenuID_Spamfilter = 'mzta-spamfilter';
|
||||||
export const contextMenuID_Summarize = 'mzta-summarize';
|
export const contextMenuID_Summarize = 'mzta-summarize';
|
||||||
|
export const contextMenuID_Translate = 'mzta-translate';
|
||||||
export const contextMenuIconsPath = {
|
export const contextMenuIconsPath = {
|
||||||
[contextMenuID_AddTags]: 'moz-extension:images/autotags.png',
|
[contextMenuID_AddTags]: 'moz-extension:images/autotags.png',
|
||||||
[contextMenuID_Spamfilter]: 'moz-extension:images/spamfilter.png',
|
[contextMenuID_Spamfilter]: 'moz-extension:images/spamfilter.png',
|
||||||
[contextMenuID_Summarize]: 'moz-extension:images/summarize.png',
|
[contextMenuID_Summarize]: 'moz-extension:images/summarize.png',
|
||||||
|
[contextMenuID_Translate]: 'moz-extension:images/ai_translation.png',
|
||||||
};
|
};
|
||||||
|
|
||||||
export function getLanguageDisplayName(languageCode) {
|
export function getLanguageDisplayName(languageCode) {
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,7 @@ import {
|
||||||
contextMenuID_AddTags,
|
contextMenuID_AddTags,
|
||||||
contextMenuID_Spamfilter,
|
contextMenuID_Spamfilter,
|
||||||
contextMenuID_Summarize,
|
contextMenuID_Summarize,
|
||||||
|
contextMenuID_Translate,
|
||||||
contextMenuIconsPath,
|
contextMenuIconsPath,
|
||||||
sanitizeChatGPTModelData,
|
sanitizeChatGPTModelData,
|
||||||
sanitizeChatGPTWebCustomData,
|
sanitizeChatGPTWebCustomData,
|
||||||
|
|
@ -1603,6 +1604,13 @@ function addContextMenuItems() {
|
||||||
removeContextMenu(contextMenuID_Summarize);
|
removeContextMenu(contextMenuID_Summarize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add Context menu: Translate
|
||||||
|
if(prefs_init.translate && checkAPIIntegration(prefs_init.connection_type, prefs_init.translate_use_specific_integration, prefs_init.translate_connection_type)){
|
||||||
|
itemsToAdd.push(contextMenuID_Translate);
|
||||||
|
} else {
|
||||||
|
removeContextMenu(contextMenuID_Translate);
|
||||||
|
}
|
||||||
|
|
||||||
itemsToAdd.sort((a, b) => {
|
itemsToAdd.sort((a, b) => {
|
||||||
let titleA = browser.i18n.getMessage("context_menu_" + a);
|
let titleA = browser.i18n.getMessage("context_menu_" + a);
|
||||||
let titleB = browser.i18n.getMessage("context_menu_" + b);
|
let titleB = browser.i18n.getMessage("context_menu_" + b);
|
||||||
|
|
@ -1621,6 +1629,7 @@ browser.menus.onClicked.addListener( (info, tab) => {
|
||||||
let _add_tags = false
|
let _add_tags = false
|
||||||
let _spamfilter = false
|
let _spamfilter = false
|
||||||
let _summarize = false;
|
let _summarize = false;
|
||||||
|
let _translate = false;
|
||||||
if(info.menuItemId === contextMenuID_AddTags){
|
if(info.menuItemId === contextMenuID_AddTags){
|
||||||
_add_tags = true;
|
_add_tags = true;
|
||||||
}
|
}
|
||||||
|
|
@ -1630,12 +1639,16 @@ browser.menus.onClicked.addListener( (info, tab) => {
|
||||||
if(info.menuItemId === contextMenuID_Summarize) {
|
if(info.menuItemId === contextMenuID_Summarize) {
|
||||||
_summarize = true;
|
_summarize = true;
|
||||||
}
|
}
|
||||||
if(_add_tags || _spamfilter || _summarize){
|
if(info.menuItemId === contextMenuID_Translate) {
|
||||||
|
_translate = true;
|
||||||
|
}
|
||||||
|
if(_add_tags || _spamfilter || _summarize || _translate){
|
||||||
processEmails({
|
processEmails({
|
||||||
messages: getMessages(info.selectedMessages),
|
messages: getMessages(info.selectedMessages),
|
||||||
addTagsAuto: _add_tags,
|
addTagsAuto: _add_tags,
|
||||||
spamFilter: _spamfilter,
|
spamFilter: _spamfilter,
|
||||||
summarize: _summarize
|
summarize: _summarize,
|
||||||
|
translate: _translate
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -1696,7 +1709,8 @@ async function processEmails(args) {
|
||||||
spamFilter = false,
|
spamFilter = false,
|
||||||
summarize = false,
|
summarize = false,
|
||||||
summarizeOnReceive = false,
|
summarizeOnReceive = false,
|
||||||
translateOnReceive = false
|
translateOnReceive = false,
|
||||||
|
translate = false
|
||||||
} = args;
|
} = args;
|
||||||
|
|
||||||
taWorkingStatus.startWorking();
|
taWorkingStatus.startWorking();
|
||||||
|
|
@ -1704,7 +1718,7 @@ async function processEmails(args) {
|
||||||
// One loop handles addTagsAuto, spamFilter, summarizeOnReceive, and translateOnReceive (on email receive).
|
// One loop handles addTagsAuto, spamFilter, summarizeOnReceive, and translateOnReceive (on email receive).
|
||||||
// The separate summarize block below handles the context menu flow.
|
// The separate summarize block below handles the context menu flow.
|
||||||
|
|
||||||
if (addTagsAuto || spamFilter || summarizeOnReceive || translateOnReceive) {
|
if (addTagsAuto || spamFilter || summarizeOnReceive || translateOnReceive || translate) {
|
||||||
let prefs_aats = await browser.storage.sync.get({
|
let prefs_aats = await browser.storage.sync.get({
|
||||||
add_tags_maxnum: prefs_default.add_tags_maxnum,
|
add_tags_maxnum: prefs_default.add_tags_maxnum,
|
||||||
connection_type: prefs_default.connection_type,
|
connection_type: prefs_default.connection_type,
|
||||||
|
|
@ -1810,12 +1824,17 @@ async function processEmails(args) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (translateOnReceive) {
|
if (translateOnReceive || translate) {
|
||||||
if (!curr_fullMessage) {
|
if (!curr_fullMessage) {
|
||||||
curr_fullMessage = await browser.messages.getFull(message.id);
|
curr_fullMessage = await browser.messages.getFull(message.id);
|
||||||
}
|
}
|
||||||
taLog.log("[ThunderAI] Pre-caching translation on receive for: " + message.headerMessageId);
|
let translateTabId = null;
|
||||||
await _generateTranslationForMessage(message.headerMessageId, null, {
|
if (translate) {
|
||||||
|
const tabs = await browser.tabs.query({ active: true, currentWindow: true });
|
||||||
|
translateTabId = tabs[0].id;
|
||||||
|
}
|
||||||
|
taLog.log("[ThunderAI] Generating translation for: " + message.headerMessageId);
|
||||||
|
await _generateTranslationForMessage(message.headerMessageId, translateTabId, {
|
||||||
messageData: { fullMessage: curr_fullMessage }
|
messageData: { fullMessage: curr_fullMessage }
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue