Merge pull request #359 from micz/issue_350

Fixing extra lines when composing in plain text
This commit is contained in:
Mic 2025-04-22 21:08:36 +02:00 committed by GitHub
commit 4d90e7d653
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 42 additions and 3 deletions

View file

@ -7,6 +7,7 @@
<h2>Version 3.3.5 - 17/04/2025</h2>
<ul>
<li>Using a prompt from the compose window with a "Do reply" action is changed in "Substitute Text", asking also to insert text if none is selected [<a href="https://github.com/micz/ThunderAI/issues/353">#353</a>].</li>
<li>Added an option when composing in plain text to remove the extra empty lines [<a href="https://github.com/micz/ThunderAI/issues/350">#350</a>].</li>
<li><i>[Ollama API]</i> It's now possibile to define the default context length (the <i>num_ctx</i> parameter) in the options page [<a href="https://github.com/micz/ThunderAI/issues/351">#351</a>].</li>
<li><i>[ChatGPT Web]</i> Updated the list of available models in the option page.</li>
<li><i>[ChatGPT Web]</i> Opening the ChatGPT webpage from the options now enforce the selected model, if any.</li>

View file

@ -1271,6 +1271,14 @@
"message": "Give \"all URLs\" permission",
"description": ""
},
"prefs_OptionText_composing_plain_text": {
"message": "Composing in plain text",
"description": ""
},
"prefs_OptionText_composing_plain_text_Info": {
"message": "Check this option if you're composing the emails in plain text format.",
"description": ""
}
"Replace_No_Selected_Text": {
"message": "No text selected, would you like to insert the AI's response at the beginning of the email?",
"description": ""

View file

@ -175,6 +175,16 @@ export function sanitizeHtml(input) {
return input.replace(/<(?!br\s*\/?)[^>]+>/gi, '');
}
export function stripHtmlKeepLines(htmlString) {
// Replaces <p> tags with a newline at the beginning
// and removes all other HTML tags
return htmlString
.replace(/<p>/gi, '') // removes <p> tags
.replace(/<\/p>/gi, '\n') // replaces </p> tags with newline
.replace(/<[^>]*>/g, '') // removes any other HTML tags
.trim(); // removes leading/trailing whitespace
}
// This method is used to convert the model string id used in the URL
// to the model string used in the webpage
export function getGPTWebModelString(model) {

View file

@ -20,7 +20,7 @@ import { mzta_script } from './js/mzta-chatgpt.js';
import { prefs_default } from './options/mzta-options-default.js';
import { mzta_Menus } from './js/mzta-menus.js';
import { taLogger } from './js/mzta-logger.js';
import { getCurrentIdentity, getOriginalBody, replaceBody, setBody, i18nConditionalGet, generateCallID, migrateCustomPromptsStorage, migrateDefaultPromptsPropStorage, getGPTWebModelString, getTagsList, createTag, assignTagsToMessage, checkIfTagExists, getActiveSpecialPromptsIDs, checkSparksPresence, getMessages, getMailBody, extractJsonObject, contextMenuID_AddTags, contextMenuID_Spamfilter } from './js/mzta-utils.js';
import { getCurrentIdentity, getOriginalBody, replaceBody, setBody, i18nConditionalGet, generateCallID, migrateCustomPromptsStorage, migrateDefaultPromptsPropStorage, getGPTWebModelString, getTagsList, createTag, assignTagsToMessage, checkIfTagExists, getActiveSpecialPromptsIDs, checkSparksPresence, getMessages, getMailBody, extractJsonObject, contextMenuID_AddTags, contextMenuID_Spamfilter, stripHtmlKeepLines } from './js/mzta-utils.js';
import { taPromptUtils } from './js/mzta-utils-prompt.js';
import { mzta_specialCommand } from './js/mzta-special-commands.js';
import { getSpamFilterPrompt } from './js/mzta-prompts.js';
@ -194,15 +194,22 @@ messenger.runtime.onMessage.addListener((message, sender, sendResponse) => {
async function _replaceSelectedText(tabId, text) {
//console.log('chatgpt_replaceSelectedText: [' + tabId +'] ' + text)
original_html = await getOriginalBody(tabId);
let prefs_repl = await browser.storage.sync.get({composing_plain_text: prefs_default.composing_plain_text});
if(prefs_repl.composing_plain_text){
text = stripHtmlKeepLines(text);
}
await browser.tabs.sendMessage(tabId, { command: "replaceSelectedText", text: text, tabId: tabId });
return true;
}
return _replaceSelectedText(message.tabId, message.text);
case 'chatgpt_replyMessage':
async function _replyMessage(message) {
const paragraphsHtmlString = message.text;
let paragraphsHtmlString = message.text;
//console.log(">>>>>>>>>>>> paragraphsHtmlString: " + paragraphsHtmlString);
let prefs = await browser.storage.sync.get({reply_type: 'reply_all'});
let prefs = await browser.storage.sync.get({reply_type: prefs_default.reply_type, composing_plain_text: prefs_default.composing_plain_text});
if(prefs.composing_plain_text){
paragraphsHtmlString = stripHtmlKeepLines(paragraphsHtmlString);
}
//console.log('reply_type: ' + prefs.reply_type);
let replyType = 'replyToAll';
if(prefs.reply_type === 'reply_sender'){

View file

@ -22,6 +22,7 @@ export const prefs_default = {
chatgpt_win_width: 700,
default_chatgpt_lang: '',
default_sign_name: '',
composing_plain_text: false,
connection_type: 'chatgpt_web', //Other values: 'chatgpt_api', 'ollama_api', 'openai_comp_api', 'google_gemini_api'
chatgpt_web_model: '',
chatgpt_web_tempchat: false,

View file

@ -101,6 +101,17 @@
</label>
</td>
</tr>
<tr>
<td><label>
<span>__MSG_prefs_OptionText_composing_plain_text__</span>
</label></td>
<td>
<label>
<input type="checkbox" id="composing_plain_text" name="composing_plain_text" class="option-input" />
&nbsp;<span>__MSG_prefs_OptionText_composing_plain_text_info__</span>
</label>
</td>
</tr>
<tr>
<td>
<label>

View file

@ -10,6 +10,7 @@
<h2>Version 3.3.5 - 17/04/2025</h2>
<ul>
<li>Using a prompt from the compose window with a "Do reply" action is changed in "Substitute Text", asking also to insert text if none is selected [<a href="https://github.com/micz/ThunderAI/issues/353">#353</a>].</li>
<li>Added an option when composing in plain text to remove the extra empty lines [<a href="https://github.com/micz/ThunderAI/issues/350">#350</a>].</li>
<li><i>[Ollama API]</i> It's now possibile to define the default context length (the <i>num_ctx</i> parameter) in the options page [<a href="https://github.com/micz/ThunderAI/issues/351">#351</a>].</li>
<li><i>[ChatGPT Web]</i> Updated the list of available models in the option page.</li>
<li><i>[ChatGPT Web]</i> Opening the ChatGPT webpage from the options now enforce the selected model, if any.</li>