commit
c9eec57d79
13 changed files with 112 additions and 35 deletions
|
|
@ -3,6 +3,13 @@
|
|||
|
||||
|
||||
|
||||
<h2>Version 1.2.1 - 20/07/2024</h2>
|
||||
<ul>
|
||||
<li>Fixed changes in the ChatGPT web interface when importing in plain text [<a href="https://github.com/micz/ThunderAI/issues/87">#87</a>].</li>
|
||||
<li>Added an option to the prompts to specify the default language for the response [<a href="https://github.com/micz/ThunderAI/issues/86">#86</a>].</li>
|
||||
<li>Not adding to the prompt the statement about using the default language if asking for a translation [<a href="https://github.com/micz/ThunderAI/issues/85">#85</a>].</li>
|
||||
<li><i>[Thunderbird 128+ only]</i> Added a warning message when closing the Custom Prompts page with unsaved changes [<a href="https://github.com/micz/ThunderAI/issues/88">#88</a>].</li>
|
||||
</ul>
|
||||
<h2>Version 1.2.0 - 17/07/2024</h2>
|
||||
<ul>
|
||||
<li>If no default language is set in the options, the language present in the text sent to ChatGPT will be used [<a href="https://github.com/micz/ThunderAI/issues/53">#53</a>].</li>
|
||||
|
|
|
|||
|
|
@ -382,5 +382,9 @@
|
|||
"currently_used_prompt": {
|
||||
"message": "Derzeit verwendeter Prompt-Name",
|
||||
"description": ""
|
||||
},
|
||||
"customprompts_form_label_define_response_lang": {
|
||||
"message": "Definieren Sie die Antwortsprache im Prompt.",
|
||||
"description": ""
|
||||
}
|
||||
}
|
||||
|
|
@ -382,5 +382,9 @@
|
|||
"currently_used_prompt": {
|
||||
"message": "Currently used prompt name",
|
||||
"description": ""
|
||||
},
|
||||
"customprompts_form_label_define_response_lang": {
|
||||
"message": "Define the reponse languange in the prompt",
|
||||
"description": ""
|
||||
}
|
||||
}
|
||||
|
|
@ -382,5 +382,9 @@
|
|||
"currently_used_prompt": {
|
||||
"message": "Nom du prompt actuellement utilisé",
|
||||
"description": ""
|
||||
},
|
||||
"customprompts_form_label_define_response_lang": {
|
||||
"message": "Définir la langue de réponse dans le prompt.",
|
||||
"description": ""
|
||||
}
|
||||
}
|
||||
|
|
@ -382,5 +382,9 @@
|
|||
"currently_used_prompt": {
|
||||
"message": "Nome del prompt attualmente utilizzato",
|
||||
"description": ""
|
||||
},
|
||||
"customprompts_form_label_define_response_lang": {
|
||||
"message": "Definisci la lingua di risposta nel prompt.",
|
||||
"description": ""
|
||||
}
|
||||
}
|
||||
|
|
@ -51,6 +51,8 @@
|
|||
<input type="checkbox" id="checkboxNeedSignatureNew" name="need_signature" value="1" tabindex="7"> <label for="checkboxNeedSignatureNew">__MSG_customPrompts_form_label_need_signature__</label>
|
||||
<br>
|
||||
<input type="checkbox" id="checkboxNeedCustomTextNew" name="need_custom_text" value="1" tabindex="8"> <label for="checkboxNeedCustomTextNew">__MSG_customPrompts_form_label_need_custom_text__</label>
|
||||
<br>
|
||||
<input type="checkbox" id="checkboxDefineResponseLangNew" name="define_response_lang" value="1" tabindex="8"> <label for="checkboxDefineResponseLangNew">__MSG_customPrompts_form_label_define_response_lang__</label>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
*/
|
||||
|
||||
import { getPrompts, setDefaultPromptsProperties, setCustomPrompts, preparePromptsForExport, preparePromptsForImport } from "../js/mzta-prompts.js";
|
||||
import { isThunderbird128OrGreater } from "../js/mzta-utils.js";
|
||||
|
||||
var promptsList = null;
|
||||
var somethingChanged = false;
|
||||
|
|
@ -114,6 +115,7 @@ document.addEventListener('DOMContentLoaded', async () => {
|
|||
var checkboxNeedSelectedNew = document.getElementById('checkboxNeedSelectedNew');
|
||||
var checkboxNeedSignatureNew = document.getElementById('checkboxNeedSignatureNew');
|
||||
var checkboxNeedCustomTextNew = document.getElementById('checkboxNeedCustomTextNew');
|
||||
var checkboxDefineResponseLangNew = document.getElementById('checkboxDefineResponseLangNew');
|
||||
|
||||
const btnAddNew = document.getElementById('btnAddNew');
|
||||
btnAddNew.addEventListener('click', (e) => {
|
||||
|
|
@ -130,6 +132,7 @@ document.addEventListener('DOMContentLoaded', async () => {
|
|||
need_selected: (checkboxNeedSelectedNew.checked) ? 1 : 0,
|
||||
need_signature: (checkboxNeedSignatureNew.checked) ? 1 : 0,
|
||||
need_custom_text: (checkboxNeedCustomTextNew.checked) ? 1 : 0,
|
||||
define_response_lang: (checkboxDefineResponseLangNew.checked) ? 1 : 0,
|
||||
enabled: 1,
|
||||
position_compose: positionMax_compose + 1,
|
||||
position_display: positionMax_display + 1,
|
||||
|
|
@ -273,6 +276,7 @@ function showItemRowEditor(tr) {
|
|||
tr.querySelector('input.need_selected').disabled = false;
|
||||
tr.querySelector('input.need_signature').disabled = false;
|
||||
tr.querySelector('input.need_custom_text').disabled = false;
|
||||
tr.querySelector('input.define_response_lang').disabled = false;
|
||||
}
|
||||
|
||||
function hideItemRowEditor(tr) {
|
||||
|
|
@ -289,6 +293,7 @@ function hideItemRowEditor(tr) {
|
|||
tr.querySelector('input.need_selected').disabled = true;
|
||||
tr.querySelector('input.need_signature').disabled = true;
|
||||
tr.querySelector('input.need_custom_text').disabled = true;
|
||||
tr.querySelector('input.define_response_lang').disabled = true;
|
||||
}
|
||||
|
||||
// Confirm and log deletion action
|
||||
|
|
@ -354,7 +359,7 @@ function handleInputChange(e) {
|
|||
|
||||
function loadPromptsList(values){
|
||||
let options = {
|
||||
valueNames: [ { data: ['idnum'] }, 'is_default', 'id', 'name', 'text', 'type', 'action', 'position_compose', 'position_display', { name: 'need_selected', attr: 'checked_val'}, { name: 'need_signature', attr: 'checked_val'}, { name: 'need_custom_text', attr: 'checked_val'}, { name: 'enabled', attr: 'checked_val'} ],
|
||||
valueNames: [ { data: ['idnum'] }, 'is_default', 'id', 'name', 'text', 'type', 'action', 'position_compose', 'position_display', { name: 'need_selected', attr: 'checked_val'}, { name: 'need_signature', attr: 'checked_val'}, { name: 'need_custom_text', attr: 'checked_val'}, { name: 'define_response_lang', attr: 'checked_val'}, { name: 'enabled', attr: 'checked_val'} ],
|
||||
item: function(values) {
|
||||
let type_output = '';
|
||||
switch(String(values.type)){
|
||||
|
|
@ -410,6 +415,8 @@ function loadPromptsList(values){
|
|||
<br>
|
||||
<input type="checkbox" class="need_custom_text" disabled> __MSG_customPrompts_form_label_need_custom_text__
|
||||
<br>
|
||||
<input type="checkbox" class="define_response_lang" disabled> __MSG_customPrompts_form_label_define_response_lang__
|
||||
<br>
|
||||
<input type="checkbox" class="enabled input_mod"> __MSG_customPrompts_form_label_enabled__
|
||||
<span class="is_default hiddendata"></span>
|
||||
<span class="position_compose hiddendata"></span>
|
||||
|
|
@ -547,6 +554,7 @@ function checkSelectedBoxes(checkboxes = null) {
|
|||
...document.querySelectorAll('.need_selected[type="checkbox"]'),
|
||||
...document.querySelectorAll('.need_signature[type="checkbox"]'),
|
||||
...document.querySelectorAll('.need_custom_text[type="checkbox"]'),
|
||||
...document.querySelectorAll('.define_response_lang[type="checkbox"]'),
|
||||
...document.querySelectorAll('.enabled[type="checkbox"]'),
|
||||
];
|
||||
}
|
||||
|
|
@ -611,9 +619,11 @@ function clearMessage() {
|
|||
}
|
||||
|
||||
|
||||
// window.addEventListener('beforeunload', function (event) {
|
||||
// // Check if any changes have been made
|
||||
// if (somethingChanged) {
|
||||
// event.preventDefault();
|
||||
// }
|
||||
// });
|
||||
if(await isThunderbird128OrGreater()){
|
||||
window.addEventListener('beforeunload', function (event) {
|
||||
// Check if any changes have been made (Only for Thunderbird 128+ see https://github.com/micz/ThunderAI/issues/88)
|
||||
if (somethingChanged) {
|
||||
event.preventDefault();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,6 +65,7 @@ function chatgpt_getRegenerateButton() {
|
|||
async function chatgpt_getFromDOM(pos) {
|
||||
const responseDivs = document.querySelectorAll('div[data-testid*="conversation-turn"]:nth-child(odd)'),
|
||||
strPos = pos.toString().toLowerCase();
|
||||
//console.log(">>>>>>>>>>>>> responseDivs.length: "+ responseDivs.length);
|
||||
let response = '';
|
||||
if (responseDivs.length) {
|
||||
if (/last|final/.test(strPos)){ // get last response
|
||||
|
|
@ -74,13 +75,9 @@ async function chatgpt_getFromDOM(pos) {
|
|||
let doc = parser.parseFromString(responseDivs[responseDivs.length - 1].innerHTML, 'text/html');
|
||||
if(!mztaKeepFormatting) { // Return only TEXT
|
||||
// Select the div with class 'empty:hidden'
|
||||
let divToRemove = doc.querySelector('div.empty\\\\:hidden');
|
||||
if (divToRemove) {
|
||||
divToRemove.remove();
|
||||
}
|
||||
// Extract the new HTML string
|
||||
responseDivs[responseDivs.length - 1].innerHTML = doc.body.innerHTML;
|
||||
response = responseDivs[responseDivs.length - 1].textContent;
|
||||
let correct_div = responseDivs[responseDivs.length - 1].querySelector('div[data-message-author-role="assistant"]');
|
||||
response = correct_div.textContent;
|
||||
//console.log(">>>>>>>>>> response: " + response);
|
||||
response = response.replace(/^ChatGPT(?:ChatGPT)?/, ''); // strip sender name
|
||||
response = response.trim().replace(/^"|"$/g, ''); // strip quotation marks
|
||||
response = "<body><p>" + response + "</p></body>";
|
||||
|
|
@ -90,7 +87,6 @@ async function chatgpt_getFromDOM(pos) {
|
|||
//console.log(">>>>>>>>> doc_response: " + JSON.stringify(doc_response.body.innerHTML));
|
||||
replaceNewlinesWithBr(doc_response.body)
|
||||
response = doc_response.body.innerHTML;
|
||||
// response = responseDivs[responseDivs.length - 1].innerHTML;
|
||||
} else { // Return HTML
|
||||
// Tags to exclude
|
||||
//console.log(">>>>>>>>> doc.body.innerHTML original: " + doc.body.innerHTML);
|
||||
|
|
|
|||
|
|
@ -93,13 +93,16 @@ export class mzta_Menus {
|
|||
}
|
||||
//open chatgpt window
|
||||
//console.log("Click menu item...");
|
||||
let prefs = await browser.storage.sync.get({default_chatgpt_lang: ''});
|
||||
let chatgpt_lang = prefs.default_chatgpt_lang;
|
||||
//console.log(" >>>>>>>>>>>> chatgpt_lang: " + chatgpt_lang);
|
||||
if(chatgpt_lang === ''){
|
||||
chatgpt_lang = 'Reply in the language it is written.';
|
||||
}else{
|
||||
chatgpt_lang = browser.i18n.getMessage("prompt_lang") + " " + chatgpt_lang + ".";
|
||||
let chatgpt_lang = '';
|
||||
if(String(curr_prompt.define_response_lang) == "1"){
|
||||
let prefs = await browser.storage.sync.get({default_chatgpt_lang: ''});
|
||||
chatgpt_lang = prefs.default_chatgpt_lang;
|
||||
//console.log(" >>>>>>>>>>>> chatgpt_lang: " + chatgpt_lang);
|
||||
if(chatgpt_lang === ''){
|
||||
chatgpt_lang = 'Reply in the same language.';
|
||||
}else{
|
||||
chatgpt_lang = browser.i18n.getMessage("prompt_lang") + " " + chatgpt_lang + ".";
|
||||
}
|
||||
}
|
||||
|
||||
var fullPrompt = curr_prompt.text + (String(curr_prompt.need_signature) == "1" ? " " + await this.getDefaultSignature():"") + " " + chatgpt_lang + " \"" + body_text + "\" ";
|
||||
|
|
|
|||
|
|
@ -44,6 +44,10 @@
|
|||
0: No custom text needed
|
||||
1: Custom text needed
|
||||
|
||||
Define response language (define_response_lang attribute):
|
||||
0: Do not include a statement about the response language in the prompt.
|
||||
1: Include a statement about the response language in the prompt.
|
||||
|
||||
================ USER PROPERTIES
|
||||
Enabled (enabled attribute):
|
||||
0: Disabled
|
||||
|
|
@ -67,6 +71,7 @@ const defaultPrompts = [
|
|||
need_selected: "0",
|
||||
need_signature: "1",
|
||||
need_custom_text: "0",
|
||||
define_response_lang: "1",
|
||||
is_default: "1",
|
||||
},
|
||||
{
|
||||
|
|
@ -78,6 +83,7 @@ const defaultPrompts = [
|
|||
need_selected: "1",
|
||||
need_signature: "0",
|
||||
need_custom_text: "0",
|
||||
define_response_lang: "1",
|
||||
is_default: "1",
|
||||
},
|
||||
{
|
||||
|
|
@ -89,6 +95,7 @@ const defaultPrompts = [
|
|||
need_selected: "1",
|
||||
need_signature: "0",
|
||||
need_custom_text: "0",
|
||||
define_response_lang: "1",
|
||||
is_default: "1",
|
||||
},
|
||||
{
|
||||
|
|
@ -100,6 +107,7 @@ const defaultPrompts = [
|
|||
need_selected: "0",
|
||||
need_signature: "0",
|
||||
need_custom_text: "0",
|
||||
define_response_lang: "1",
|
||||
is_default: "1",
|
||||
},
|
||||
{
|
||||
|
|
@ -111,6 +119,7 @@ const defaultPrompts = [
|
|||
need_selected: "0",
|
||||
need_signature: "0",
|
||||
need_custom_text: "0",
|
||||
define_response_lang: "1",
|
||||
is_default: "1",
|
||||
},
|
||||
{
|
||||
|
|
@ -122,6 +131,7 @@ const defaultPrompts = [
|
|||
need_selected: "0",
|
||||
need_signature: "0",
|
||||
need_custom_text: "0",
|
||||
define_response_lang: "0",
|
||||
is_default: "1",
|
||||
},
|
||||
{
|
||||
|
|
@ -133,6 +143,7 @@ const defaultPrompts = [
|
|||
need_selected: "1",
|
||||
need_signature: "0",
|
||||
need_custom_text: "0",
|
||||
define_response_lang: "0",
|
||||
is_default: "1",
|
||||
},
|
||||
];
|
||||
|
|
|
|||
|
|
@ -87,6 +87,43 @@ export async function replaceBody(tabId, replyHtml) {
|
|||
await messenger.compose.setComposeDetails(tabId, {body: fullBody});
|
||||
}
|
||||
|
||||
export function i18nConditionalGet(str) {
|
||||
// if we are getting a string that starts with '__MSG_' and ends with '__' we return the translated string
|
||||
// using the browser.i18n API
|
||||
// else we return the original string
|
||||
// Check if the string starts with '__MSG_' and ends with '__'
|
||||
if (str.startsWith('__MSG_') && str.endsWith('__')) {
|
||||
// Remove '__MSG_' from the beginning and '__' from the end
|
||||
return browser.i18n.getMessage(str.substring(6, str.length - 2));
|
||||
}
|
||||
return str; // Return the original string if the conditions are not met
|
||||
}
|
||||
|
||||
export async function isThunderbird128OrGreater(){
|
||||
try {
|
||||
const info = await browser.runtime.getBrowserInfo();
|
||||
const version = info.version;
|
||||
return compareThunderbirdVersions(version, '128.0') >= 0;
|
||||
} catch (error) {
|
||||
console.error('[ThunderAI] Error retrieving browser information:', error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function compareThunderbirdVersions(v1, v2) {
|
||||
const v1parts = v1.split('.').map(Number);
|
||||
const v2parts = v2.split('.').map(Number);
|
||||
|
||||
for (let i = 0; i < Math.max(v1parts.length, v2parts.length); i++) {
|
||||
const v1part = v1parts[i] || 0;
|
||||
const v2part = v2parts[i] || 0;
|
||||
if (v1part > v2part) return 1;
|
||||
if (v1part < v2part) return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// The following methods are a modified version derived from https://github.com/ali-raheem/Aify/blob/13ff87583bc520fb80f555ab90a90c5c9df797a7/plugin/content_scripts/compose.js
|
||||
|
||||
|
|
@ -135,15 +172,3 @@ const insertHtml = function (replyHtml, fullBody_string) {
|
|||
fullBody.body.insertBefore(fragment, fullBody.body.firstChild);
|
||||
return fullBody.body.innerHTML;
|
||||
}
|
||||
|
||||
export function i18nConditionalGet(str) {
|
||||
// if we are getting a string that starts with '__MSG_' and ends with '__' we return the translated string
|
||||
// using the browser.i18n API
|
||||
// else we return the original string
|
||||
// Check if the string starts with '__MSG_' and ends with '__'
|
||||
if (str.startsWith('__MSG_') && str.endsWith('__')) {
|
||||
// Remove '__MSG_' from the beginning and '__' from the end
|
||||
return browser.i18n.getMessage(str.substring(6, str.length - 2));
|
||||
}
|
||||
return str; // Return the original string if the conditions are not met
|
||||
}
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
"manifest_version": 2,
|
||||
"name": "ThunderAI",
|
||||
"description": "__MSG_extensionDescription__",
|
||||
"version": "1.2.0",
|
||||
"version": "1.2.1",
|
||||
"author": "Mic (m@micz.it)",
|
||||
"homepage_url": "https://micz.it/thunderbird-addon-thunderai/",
|
||||
"browser_specific_settings": {
|
||||
|
|
|
|||
|
|
@ -7,6 +7,13 @@
|
|||
<body>
|
||||
<div id="miczBackPrefs"><a href="mzta-options.html">__MSG_backToOptionsText__</a></div>
|
||||
<div id="miczRelNotes"><h1>ThunderAI Release Notes</h1>
|
||||
<h2>Version 1.2.1 - 20/07/2024</h2>
|
||||
<ul>
|
||||
<li>Fixed changes in the ChatGPT web interface when importing in plain text [<a href="https://github.com/micz/ThunderAI/issues/87">#87</a>].</li>
|
||||
<li>Added an option to the prompts to specify the default language for the response [<a href="https://github.com/micz/ThunderAI/issues/86">#86</a>].</li>
|
||||
<li>Not adding to the prompt the statement about using the default language if asking for a translation [<a href="https://github.com/micz/ThunderAI/issues/85">#85</a>].</li>
|
||||
<li><i>[Thunderbird 128+ only]</i> Added a warning message when closing the Custom Prompts page with unsaved changes [<a href="https://github.com/micz/ThunderAI/issues/88">#88</a>].</li>
|
||||
</ul>
|
||||
<h2>Version 1.2.0 - 17/07/2024</h2>
|
||||
<ul>
|
||||
<li>If no default language is set in the options, the language present in the text sent to ChatGPT will be used [<a href="https://github.com/micz/ThunderAI/issues/53">#53</a>].</li>
|
||||
|
|
|
|||
Loading…
Reference in a new issue