Skip to content

Commit

Permalink
Added new mail_typed_text data placeholder. fixes #196
Browse files Browse the repository at this point in the history
  • Loading branch information
micz committed Jan 9, 2025
1 parent e7ef1f9 commit 241c8d6
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
18 changes: 17 additions & 1 deletion js/mzta-compose-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -51,13 +51,29 @@ switch (message.command) {
t += node.textContent;
}
return Promise.resolve(t);
}

case "getTextOnly":
return Promise.resolve(window.document.body.innerText);

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
Expand Down
6 changes: 6 additions & 0 deletions js/mzta-menus.js
Original file line number Diff line number Diff line change
Expand Up @@ -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" })
};
};

Expand All @@ -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 = '';
Expand Down Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions js/mzta-placeholders.js
Original file line number Diff line number Diff line change
Expand Up @@ -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__",
Expand Down

0 comments on commit 241c8d6

Please sign in to comment.