Merge pull request #478 from kiliansinger/3.6.1_issue_469

3.6.1 issue 469
This commit is contained in:
Mic 2025-08-22 22:48:35 +02:00 committed by GitHub
commit f3e0d5401e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 21 additions and 10 deletions

View file

@ -19,7 +19,7 @@
// Some original methods are derived from https://github.com/ali-raheem/Aify/blob/cfadf52f576b7be3720b5b73af7c8d3129c054da/plugin/html/actions.js // Some original methods are derived from https://github.com/ali-raheem/Aify/blob/cfadf52f576b7be3720b5b73af7c8d3129c054da/plugin/html/actions.js
import { getPrompts } from './mzta-prompts.js'; import { getPrompts } from './mzta-prompts.js';
import { getLanguageDisplayName, getMenuContextCompose, getMenuContextDisplay, i18nConditionalGet, getMailSubject, getTagsList, extractJsonObject, convertNewlinesToBr } from './mzta-utils.js' import { getLanguageDisplayName, getMenuContextCompose, getMenuContextDisplay, i18nConditionalGet, getMailSubject, getTagsList, extractJsonObject, convertNewlinesToBr, cleanupNewlines } from './mzta-utils.js'
import { taPromptUtils } from './mzta-utils-prompt.js'; import { taPromptUtils } from './mzta-utils-prompt.js';
import { taLogger } from './mzta-logger.js'; import { taLogger } from './mzta-logger.js';
import { placeholdersUtils } from './mzta-placeholders.js'; import { placeholdersUtils } from './mzta-placeholders.js';
@ -81,12 +81,12 @@ export class mzta_Menus {
const getMailBody = async (tabs, do_autoselect = false) => { const getMailBody = async (tabs, do_autoselect = false) => {
//const tabs = await browser.tabs.query({ active: true, currentWindow: true }); //const tabs = await browser.tabs.query({ active: true, currentWindow: true });
return {tabId: tabs[0].id, return {tabId: tabs[0].id,
selection: convertNewlinesToBr(await browser.tabs.sendMessage(tabs[0].id, { command: "getSelectedText" })), selection: cleanupNewlines(await browser.tabs.sendMessage(tabs[0].id, { command: "getSelectedText" })),
selection_html: convertNewlinesToBr(await browser.tabs.sendMessage(tabs[0].id, { command: "getSelectedHtml" })), selection_html: convertNewlinesToBr(await browser.tabs.sendMessage(tabs[0].id, { command: "getSelectedHtml" })),
text: convertNewlinesToBr(await browser.tabs.sendMessage(tabs[0].id, { command: "getTextOnly" })), text: cleanupNewlines(await browser.tabs.sendMessage(tabs[0].id, { command: "getTextOnly" })),
html: convertNewlinesToBr(await browser.tabs.sendMessage(tabs[0].id, { command: "getFullHtml" })), html: convertNewlinesToBr(await browser.tabs.sendMessage(tabs[0].id, { command: "getFullHtml" })),
only_typed_text: convertNewlinesToBr(await browser.tabs.sendMessage(tabs[0].id, { command: "getOnlyTypedText", do_autoselect: do_autoselect })), only_typed_text: cleanupNewlines(await browser.tabs.sendMessage(tabs[0].id, { command: "getOnlyTypedText", do_autoselect: do_autoselect })),
only_quoted_text: convertNewlinesToBr(await browser.tabs.sendMessage(tabs[0].id, { command: "getOnlyQuotedText" })) only_quoted_text: cleanupNewlines(await browser.tabs.sendMessage(tabs[0].id, { command: "getOnlyQuotedText" }))
}; };
}; };
@ -109,17 +109,17 @@ export class mzta_Menus {
let selection_html = msg_text.selection_html; let selection_html = msg_text.selection_html;
let only_typed_text = ''; let only_typed_text = '';
let only_quoted_text = ''; let only_quoted_text = '';
only_typed_text = msg_text.only_typed_text.replace(/\s+/g, ' ').trim(); only_typed_text = msg_text.only_typed_text.replace(/[ \t]+/g, ' ').trim();
selection_text = msg_text.selection.replace(/\s+/g, ' ').trim(); selection_text = msg_text.selection.replace(/[ \t]+/g, ' ').trim();
if(selection_text === ''){ if(selection_text === ''){
if(placeholdersUtils.hasPlaceholder(curr_prompt.text, "mail_typed_text")){ if(placeholdersUtils.hasPlaceholder(curr_prompt.text, "mail_typed_text")){
selection_text = only_typed_text; selection_text = only_typed_text;
} }
} }
only_quoted_text = msg_text.only_quoted_text.replace(/\s+/g, ' ').trim(); only_quoted_text = msg_text.only_quoted_text.replace(/[ \t]+/g, ' ').trim();
curr_prompt.selection_text = selection_text; curr_prompt.selection_text = selection_text;
curr_prompt.selection_html = selection_html; curr_prompt.selection_html = selection_html;
body_text = msg_text.text.replace(/\s+/g, ' ').trim(); body_text = msg_text.text.replace(/[ \t]+/g, ' ').trim();
curr_prompt.body_text = body_text; curr_prompt.body_text = body_text;
//open chatgpt window //open chatgpt window
//console.log("Click menu item..."); //console.log("Click menu item...");

View file

@ -213,15 +213,26 @@ export function htmlBodyToPlainText(htmlString) {
const textContent = doc.body.textContent || ""; const textContent = doc.body.textContent || "";
// Trim whitespace // Trim whitespace
return textContent return textContent
.replace(/\r\n/g, '\n')
.replace(/[ \t]+\n/g, '\n') .replace(/[ \t]+\n/g, '\n')
.replace(/\n{2,}/g, '\n') .replace(/\n{2,}/g, '\n')
.replace(/[ \t]+/g, ' ') .replace(/[ \t]+/g, ' ')
.replace(/ /gi,"") .replace(/ /gi,"")
.trim(); .trim();
} }
export function cleanupNewlines(text) {
return text
.replace(/\r\n/g, '\n')
.replace(/[ \t]+\n/g, '\n')
.replace(/\n{2,}/g, '\n')
.replace(/[ \t]+/g, ' ')
.replace(/ /gi,' ')
.trim();
}
export function convertNewlinesToBr(text) { export function convertNewlinesToBr(text) {
return text.replace(/\n/g, '<br>'); return text.replace(/\r\n/g, '\n').replace(/\n/g, '<br>');
} }
function convertBrToNewlines(html) { function convertBrToNewlines(html) {