From 241c8d67f6aa7b997cace07969b1ca79ff4eb6b7 Mon Sep 17 00:00:00 2001 From: mic Date: Thu, 9 Jan 2025 23:13:34 +0100 Subject: [PATCH] Added new mail_typed_text data placeholder. fixes #196 --- js/mzta-compose-script.js | 18 +++++++++++++++++- js/mzta-menus.js | 6 ++++++ js/mzta-placeholders.js | 7 +++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/js/mzta-compose-script.js b/js/mzta-compose-script.js index 28ade65a..ba63e625 100644 --- a/js/mzta-compose-script.js +++ b/js/mzta-compose-script.js @@ -39,7 +39,7 @@ switch (message.command) { return Promise.resolve(true); break; - case "getText": + case "getText": { let t = ''; const children = window.document.body.childNodes; for (const node of children) { @@ -51,6 +51,7 @@ switch (message.command) { t += node.textContent; } return Promise.resolve(t); + } case "getTextOnly": return Promise.resolve(window.document.body.innerText); @@ -58,6 +59,21 @@ switch (message.command) { case "getFullHtml": return Promise.resolve(window.document.body.innerHTML); + case "getOnlyTypedText": { + // TODO: add support for moz-cite-prefix + let t = ''; + const children = window.document.body.childNodes; + for (const node of children) { + if (node instanceof Element) { + if (node.classList.contains('moz-cite-prefix')) { + break; + } + } + t += node.textContent; + } + 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 diff --git a/js/mzta-menus.js b/js/mzta-menus.js index cbb251ad..e21a101b 100644 --- a/js/mzta-menus.js +++ b/js/mzta-menus.js @@ -82,6 +82,7 @@ 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" }) }; }; @@ -99,8 +100,10 @@ export class mzta_Menus { let body_text = ''; let selection_text = ''; + let only_typed_text = ''; selection_text = msg_text.selection.replace(/\s+/g, ' ').trim(); body_text = msg_text.text.replace(/\s+/g, ' ').trim(); + only_typed_text = msg_text.only_typed_text.replace(/\s+/g, ' ').trim(); //open chatgpt window //console.log("Click menu item..."); let chatgpt_lang = ''; @@ -150,6 +153,9 @@ export class mzta_Menus { case 'mail_html_body': finalSubs['mail_html_body'] = msg_text.html; break; + case 'mail_typed_text': + finalSubs['mail_typed_text'] = only_typed_text; + break; case 'mail_subject': let mail_subject = await getMailSubject(tabs[0]); finalSubs['mail_subject'] = mail_subject; diff --git a/js/mzta-placeholders.js b/js/mzta-placeholders.js index 194f2be9..36795227 100644 --- a/js/mzta-placeholders.js +++ b/js/mzta-placeholders.js @@ -47,6 +47,13 @@ const defaultPlaceholders = [ type: 0, is_default: "1", }, + { + id: 'mail_typed_text', + name: "__MSG_placeholder_mail_typed_text__", + default_value: "", + type: 2, + is_default: "1", + }, { id: 'mail_subject', name: "__MSG_placeholder_mail_subject__",