mail_typed_text placeholder added. fixes #324
This commit is contained in:
parent
9c2867f699
commit
6b7609939a
5 changed files with 67 additions and 5 deletions
|
|
@ -983,6 +983,10 @@
|
|||
"message": "Typed text before the quoted mail body",
|
||||
"description": ""
|
||||
},
|
||||
"placeholder_mail_quoted_text": {
|
||||
"message": "Quoted text in the mail body",
|
||||
"description": ""
|
||||
},
|
||||
"prompt_get_calendar_event": {
|
||||
"message": "Add a new calendar event",
|
||||
"description": ""
|
||||
|
|
|
|||
|
|
@ -103,6 +103,51 @@ switch (message.command) {
|
|||
return Promise.resolve(t);
|
||||
}
|
||||
|
||||
case "getOnlyQuotedText": {
|
||||
let t = '';
|
||||
const children = window.document.body.childNodes;
|
||||
const selection = window.getSelection();
|
||||
|
||||
let firstNode = null;
|
||||
let lastNode = null;
|
||||
let foundCitePrefix = false;
|
||||
|
||||
for (const node of children) {
|
||||
if (!foundCitePrefix) {
|
||||
if (node instanceof Element && node.classList.contains('moz-cite-prefix')) {
|
||||
foundCitePrefix = true;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
t += node.textContent + " ";
|
||||
|
||||
if (!firstNode) {
|
||||
firstNode = node;
|
||||
}
|
||||
if (node.textContent.trim() !== '') {
|
||||
lastNode = node;
|
||||
}
|
||||
}
|
||||
|
||||
if (!lastNode) {
|
||||
lastNode = firstNode;
|
||||
}
|
||||
|
||||
if (message.do_autoselect && firstNode && lastNode) {
|
||||
const range = document.createRange();
|
||||
range.setStartBefore(firstNode);
|
||||
range.setEndAfter(lastNode);
|
||||
selection.removeAllRanges();
|
||||
selection.addRange(range);
|
||||
}
|
||||
|
||||
return Promise.resolve(t);
|
||||
}
|
||||
|
||||
|
||||
|
||||
case 'sendAlert':
|
||||
//console.log(">>>>>> message.curr_tab_type: " + JSON.stringify(message.curr_tab_type));
|
||||
if(message.curr_tab_type == 'mail'){ // workaround for Thunderbird bug not showing the alert
|
||||
|
|
|
|||
|
|
@ -84,7 +84,8 @@ export class mzta_Menus {
|
|||
selection: await browser.tabs.sendMessage(tabs[0].id, { command: "getSelectedText" }),
|
||||
text: await browser.tabs.sendMessage(tabs[0].id, { command: "getTextOnly" }),
|
||||
html: await browser.tabs.sendMessage(tabs[0].id, { command: "getFullHtml" }),
|
||||
only_typed_text: await browser.tabs.sendMessage(tabs[0].id, { command: "getOnlyTypedText", do_autoselect: do_autoselect })
|
||||
only_typed_text: await browser.tabs.sendMessage(tabs[0].id, { command: "getOnlyTypedText", do_autoselect: do_autoselect }),
|
||||
only_quoted_text: await browser.tabs.sendMessage(tabs[0].id, { command: "getOnlyQuotedText" })
|
||||
};
|
||||
};
|
||||
|
||||
|
|
@ -105,6 +106,7 @@ export class mzta_Menus {
|
|||
let body_text = '';
|
||||
let selection_text = '';
|
||||
let only_typed_text = '';
|
||||
let only_quoted_text = '';
|
||||
only_typed_text = msg_text.only_typed_text.replace(/\s+/g, ' ').trim();
|
||||
selection_text = msg_text.selection.replace(/\s+/g, ' ').trim();
|
||||
if(selection_text === ''){
|
||||
|
|
@ -112,6 +114,7 @@ export class mzta_Menus {
|
|||
selection_text = only_typed_text;
|
||||
}
|
||||
}
|
||||
only_quoted_text = msg_text.only_quoted_text.replace(/\s+/g, ' ').trim();
|
||||
curr_prompt.selection_text = selection_text;
|
||||
body_text = msg_text.text.replace(/\s+/g, ' ').trim();
|
||||
curr_prompt.body_text = body_text;
|
||||
|
|
@ -138,7 +141,7 @@ export class mzta_Menus {
|
|||
break;
|
||||
}
|
||||
|
||||
fullPrompt = await taPromptUtils.preparePrompt(curr_prompt, curr_message, chatgpt_lang, selection_text, body_text, await getMailSubject(tabs[0]), msg_text, only_typed_text, tags_full_list);
|
||||
fullPrompt = await taPromptUtils.preparePrompt(curr_prompt, curr_message, chatgpt_lang, selection_text, body_text, await getMailSubject(tabs[0]), msg_text, only_typed_text, only_quoted_text, tags_full_list);
|
||||
|
||||
switch(curr_prompt.id){
|
||||
case 'prompt_translate_this':
|
||||
|
|
|
|||
|
|
@ -56,6 +56,13 @@ const defaultPlaceholders = [
|
|||
type: 2,
|
||||
is_default: "1",
|
||||
},
|
||||
{
|
||||
id: 'mail_quoted_text',
|
||||
name: "__MSG_placeholder_mail_quoted_text__",
|
||||
default_value: "",
|
||||
type: 2,
|
||||
is_default: "1",
|
||||
},
|
||||
{
|
||||
id: 'mail_subject',
|
||||
name: "__MSG_placeholder_mail_subject__",
|
||||
|
|
@ -284,7 +291,7 @@ export const placeholdersUtils = {
|
|||
return regex.test(text);
|
||||
},
|
||||
|
||||
async getPlaceholdersValues(prompt_text, curr_message, mail_subject, body_text, msg_text, only_typed_text, selection_text, tags_full_list) {
|
||||
async getPlaceholdersValues(prompt_text, curr_message, mail_subject, body_text, msg_text, only_typed_text, only_quoted_text, selection_text, tags_full_list) {
|
||||
let currPHs = await placeholdersUtils.extractPlaceholders(prompt_text);
|
||||
// console.log(">>>>>>>>>> currPHs: " + JSON.stringify(currPHs));
|
||||
let finalSubs = {};
|
||||
|
|
@ -299,6 +306,9 @@ export const placeholdersUtils = {
|
|||
case 'mail_typed_text':
|
||||
finalSubs['mail_typed_text'] = placeholdersUtils.failSafePlaceholders(only_typed_text);
|
||||
break;
|
||||
case 'mail_quoted_text':
|
||||
finalSubs['mail_quoted_text'] = placeholdersUtils.failSafePlaceholders(only_quoted_text);
|
||||
break;
|
||||
case 'mail_subject':
|
||||
finalSubs['mail_subject'] = placeholdersUtils.failSafePlaceholders(mail_subject);
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ export const taPromptUtils = {
|
|||
}
|
||||
},
|
||||
|
||||
async preparePrompt(curr_prompt, curr_message, chatgpt_lang, selection_text, body_text, subject_text, msg_text, only_typed_text, tags_full_list){
|
||||
async preparePrompt(curr_prompt, curr_message, chatgpt_lang, selection_text, body_text, subject_text, msg_text, only_typed_text, only_quoted_text, tags_full_list){
|
||||
let fullPrompt = '';
|
||||
|
||||
if(!placeholdersUtils.hasPlaceholder(curr_prompt.text)){
|
||||
|
|
@ -37,7 +37,7 @@ export const taPromptUtils = {
|
|||
fullPrompt = curr_prompt.text + (String(curr_prompt.need_signature) == "1" ? " " + await taPromptUtils.getDefaultSignature():"") + " " + chatgpt_lang + " \"" + (selection_text=='' ? body_text : selection_text) + "\" ";
|
||||
}else{
|
||||
// we have at least a placeholder, do the magic!
|
||||
let finalSubs = await placeholdersUtils.getPlaceholdersValues(curr_prompt.text, curr_message, subject_text, body_text, msg_text, only_typed_text, selection_text, tags_full_list);
|
||||
let finalSubs = await placeholdersUtils.getPlaceholdersValues(curr_prompt.text, curr_message, subject_text, body_text, msg_text, only_typed_text, only_quoted_text, selection_text, tags_full_list);
|
||||
// console.log(">>>>>>>>>> finalSubs: " + JSON.stringify(finalSubs));
|
||||
let prefs_ph = await browser.storage.sync.get({placeholders_use_default_value: false});
|
||||
fullPrompt = (placeholdersUtils.replacePlaceholders(curr_prompt.text, finalSubs, prefs_ph.placeholders_use_default_value, true) + (String(curr_prompt.need_signature) == "1" ? " " + await taPromptUtils.getDefaultSignature():"") + " " + chatgpt_lang).trim();
|
||||
|
|
|
|||
Loading…
Reference in a new issue