commit
e48e94e56f
8 changed files with 128 additions and 27 deletions
|
|
@ -84,6 +84,16 @@
|
|||
"description": ""
|
||||
},
|
||||
|
||||
"chatgpt_win_custom_text": {
|
||||
"message": "Insert here the additional text for the prompt.",
|
||||
"description": ""
|
||||
},
|
||||
|
||||
"chatgpt_win_send": {
|
||||
"message": "Send",
|
||||
"description": ""
|
||||
},
|
||||
|
||||
"chatgpt_use_gpt35": {
|
||||
"message": "Use GPT3.5",
|
||||
"description": ""
|
||||
|
|
|
|||
|
|
@ -84,6 +84,16 @@
|
|||
"description": ""
|
||||
},
|
||||
|
||||
"chatgpt_win_custom_text": {
|
||||
"message": "Inserisci qui il testo aggiuntivo per il prompt.",
|
||||
"description": ""
|
||||
},
|
||||
|
||||
"chatgpt_win_send": {
|
||||
"message": "Invia",
|
||||
"description": ""
|
||||
},
|
||||
|
||||
"chatgpt_use_gpt35": {
|
||||
"message": "Usa GPT3.5",
|
||||
"description": ""
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@
|
|||
|
||||
export const mzta_script = `
|
||||
let force_go = false;
|
||||
let current_message = null;
|
||||
|
||||
async function chatgpt_sendMsg(msg, method ='') {
|
||||
const textArea = document.querySelector('form textarea'),
|
||||
|
|
@ -111,15 +112,19 @@ function chatpgt_scrollToBottom () {
|
|||
function addCustomDiv(prompt_action,tabId) {
|
||||
// Create <style> element for the CSS
|
||||
var style = document.createElement('style');
|
||||
style.innerHTML = ".mzta-header-fixed {position: fixed;bottom: 0;left: 0;height:100px;width: 100%;background-color: #333;color: white;text-align: center;padding: 10px 0;z-index: 1000;}"
|
||||
style.innerHTML = ".mzta-header-fixed {position: fixed;bottom: 0;left: 0;height:100px;width: 100%;background-color: #333;color: white;text-align: center;padding: 10px 0;z-index: 1000;border-top: 3px solid white;}"
|
||||
style.innerHTML += "body {padding-bottom: 100px;} [id^='headlessui-dialog-panel-:r']{padding-bottom: 100px;}";
|
||||
style.innerHTML += "#mzta-btn_ok {background-color: #007bff;border: none;color: white;padding: 8px 15px;text-align: center;text-decoration: none;display: inline-block;font-size: 16px;margin: 4px 2px;transition-duration: 0.4s;cursor: pointer;border-radius: 5px;}";
|
||||
style.innerHTML += "#mzta-btn_ok:hover {background-color: #0056b3;color: white;}";
|
||||
style.innerHTML += ".mzta-btn {background-color: #007bff;border: none;color: white;padding: 8px 15px;text-align: center;text-decoration: none;display: inline-block;font-size: 16px;margin: 4px 2px;transition-duration: 0.4s;cursor: pointer;border-radius: 5px;}";
|
||||
style.innerHTML += ".mzta-btn:hover {background-color:#0056b3;color:white;}";
|
||||
style.innerHTML += "#mzta-loading{height:50px;display:inline-block;}";
|
||||
style.innerHTML += "#mzta-model_warn{position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);max-height:100%px;min-width:30%;max-width:50%;padding:3px;border-radius:5px;text-align:center;background-color:#FFBABA;border:1px solid;font-size:13px;color:#D8000C;display:none;}";
|
||||
style.innerHTML += "#mzta-btn_gpt35 {background-color: #007bff;border: none;color: white;padding: 2px 4px;text-align: center;text-decoration: none;display: none;font-size: 13px;margin-left: 4px;transition-duration: 0.4s;cursor: pointer;border-radius: 2px;}";
|
||||
style.innerHTML += "#mzta-status-page{position:fixed;bottom:0;left:0;padding-left:5px;font-size:13px;font-style:italic;text-decoration:underline;color:#919191;}";
|
||||
style.innerHTML += "#mzta-status-page:hover{color:#007bff;}";
|
||||
style.innerHTML += "#mzta-custom_text{padding:10px;width:auto;max-width:80%;height:auto;max-height:80%;border-radius:5px;overflow:auto;position:fixed;top:50%;left:50%;display:none;transform:translate(-50%,-50%);text-align:center;background:#333;color:white;border:3px solid white;}";
|
||||
style.innerHTML += "#mzta-custom_loading{height:50px;display:none;}";
|
||||
style.innerHTML += "#mzta-custom_textarea{color:black;padding:1px;font-size:15px;width:100%;}";
|
||||
style.innerHTML += "#mzta-custom_info{text-align:center;width:100%;padding-bottom:10px;font-size:15px;}";
|
||||
// Add <style> to the page's <head>
|
||||
document.head.appendChild(style);
|
||||
|
||||
|
|
@ -163,6 +168,7 @@ function addCustomDiv(prompt_action,tabId) {
|
|||
|
||||
var btn_ok = document.createElement('button');
|
||||
btn_ok.id="mzta-btn_ok";
|
||||
btn_ok.classList.add('mzta-btn');
|
||||
//console.log('default: '+prompt_action)
|
||||
switch(prompt_action){
|
||||
default:
|
||||
|
|
@ -195,9 +201,42 @@ function addCustomDiv(prompt_action,tabId) {
|
|||
btn_ok.style.display = 'none';
|
||||
fixedDiv.appendChild(btn_ok);
|
||||
|
||||
//div per custom text
|
||||
let customDiv = document.createElement('div');
|
||||
customDiv.id = 'mzta-custom_text';
|
||||
let customInfo = document.createElement('div');
|
||||
customInfo.id = 'mzta-custom_info';
|
||||
customInfo.innerHTML = browser.i18n.getMessage("chatgpt_win_custom_text");
|
||||
customDiv.appendChild(customInfo);
|
||||
let customTextArea = document.createElement('textarea');
|
||||
customTextArea.id = 'mzta-custom_textarea';
|
||||
customDiv.appendChild(customTextArea);
|
||||
let customLoading = document.createElement('img');
|
||||
customLoading.src = browser.runtime.getURL("/images/loading.gif");
|
||||
customLoading.id = "mzta-custom_loading";
|
||||
customDiv.appendChild(customLoading);
|
||||
let customBtn = document.createElement('button');
|
||||
customBtn.id = 'mzta-custom_btn';
|
||||
customBtn.innerHTML = browser.i18n.getMessage("chatgpt_win_send");
|
||||
customBtn.classList.add('mzta-btn');
|
||||
customBtn.addEventListener("click", () => { customTextBtnClick({customBtn:customBtn,customLoading:customLoading,customDiv:customDiv}) });
|
||||
customTextArea.addEventListener("keydown", (event) => { if(event.code == "Enter" && event.ctrlKey) customTextBtnClick({customBtn:customBtn,customLoading:customLoading,customDiv:customDiv}) });
|
||||
customDiv.appendChild(customBtn);
|
||||
fixedDiv.appendChild(customDiv);
|
||||
|
||||
document.body.insertBefore(fixedDiv, document.body.firstChild);
|
||||
}
|
||||
|
||||
function customTextBtnClick(args) {
|
||||
const customText = document.getElementById('mzta-custom_textarea').value;
|
||||
args.customBtn.disabled = true;
|
||||
args.customBtn.classList.add('disabled');
|
||||
args.customLoading.style.display = 'inline-block';
|
||||
args.customLoading.style.display = 'none';
|
||||
doProceed(current_message,customText);
|
||||
args.customDiv.style.display = 'none';
|
||||
}
|
||||
|
||||
function checkGPT4Model() {
|
||||
return new Promise((resolve, reject) => {
|
||||
// Set up an interval that shows the waring after 2 seconds
|
||||
|
|
@ -243,6 +282,21 @@ function checkLoggedIn(){
|
|||
return !window.location.href.startsWith('https://chat.openai.com/auth/');
|
||||
}
|
||||
|
||||
function showCustomTextField(){
|
||||
document.getElementById('mzta-custom_text').style.display = 'block';
|
||||
}
|
||||
|
||||
async function doProceed(message, customText = ''){
|
||||
let prefs = await browser.storage.sync.get({chatpgt_use_gpt4:false});
|
||||
if(prefs.chatpgt_use_gpt4){
|
||||
await checkGPT4Model();
|
||||
}
|
||||
//await chatgpt.isLoaded();
|
||||
await chatgpt_sendMsg(message.prompt+' '+customText,'click');
|
||||
await chatgpt_isIdle();
|
||||
operation_done();
|
||||
}
|
||||
|
||||
// Nello script di contenuto
|
||||
browser.runtime.onMessage.addListener((message, sender, sendResponse) => {
|
||||
if (message.command === "chatgpt_send") {
|
||||
|
|
@ -252,15 +306,20 @@ browser.runtime.onMessage.addListener((message, sender, sendResponse) => {
|
|||
}else{
|
||||
addCustomDiv(message.action,message.tabId);
|
||||
(async () => {
|
||||
let prefs = await browser.storage.sync.get({chatpgt_use_gpt4:false});
|
||||
if(prefs.chatpgt_use_gpt4){
|
||||
await checkGPT4Model();
|
||||
if(mztaDoCustomText === 1){
|
||||
current_message = message;
|
||||
showCustomTextField();
|
||||
} else {
|
||||
// let prefs = await browser.storage.sync.get({chatpgt_use_gpt4:false});
|
||||
// if(prefs.chatpgt_use_gpt4){
|
||||
// await checkGPT4Model();
|
||||
// }
|
||||
//await chatgpt.isLoaded();
|
||||
// await chatgpt_sendMsg(message.prompt,'click');
|
||||
// await chatgpt_isIdle();
|
||||
// operation_done();
|
||||
await doProceed(message);
|
||||
}
|
||||
//await chatgpt.isLoaded();
|
||||
await chatgpt_sendMsg(message.prompt,'click');
|
||||
await chatgpt_isIdle();
|
||||
// console.log(response);
|
||||
operation_done();
|
||||
})();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -87,14 +87,15 @@ export class mzta_Menus {
|
|||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
const tabs = await browser.tabs.query({ active: true, currentWindow: true });
|
||||
// add custom text if needed
|
||||
//browser.runtime.sendMessage({command: "chatgpt_open", prompt: fullPrompt, action: curr_prompt.action, tabId: tabs[0].id});
|
||||
this.openChatGPT(fullPrompt, curr_prompt.action, tabs[0].id);
|
||||
this.openChatGPT(fullPrompt, curr_prompt.action, tabs[0].id, curr_prompt.need_custom_text);
|
||||
};
|
||||
this.rootMenu.push(curr_menu_entry);
|
||||
};
|
||||
|
||||
|
||||
async getDefaultSignature(){
|
||||
let prefs = await browser.storage.sync.get({default_sign_name: ''});
|
||||
if(prefs.default_sign_name===''){
|
||||
|
|
@ -118,7 +119,7 @@ export class mzta_Menus {
|
|||
|
||||
browser.menus.create({
|
||||
id: id,
|
||||
title: browser.i18n.getMessage(id),
|
||||
title: this.getCustomTextAttribute(id) + browser.i18n.getMessage(id),
|
||||
contexts: this.getContexts(id),
|
||||
parentId: root
|
||||
});
|
||||
|
|
@ -151,6 +152,17 @@ export class mzta_Menus {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
getCustomTextAttribute(id){
|
||||
const curr_prompt = defaultPrompts.find(p => p.id === id);
|
||||
if (!curr_prompt) {
|
||||
return "";
|
||||
}
|
||||
if(curr_prompt.need_custom_text === 1){
|
||||
return "*";
|
||||
}else{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -28,21 +28,25 @@
|
|||
1: do reply
|
||||
2: substitute text
|
||||
|
||||
Only if text selected (attribute need_selected):
|
||||
Only if text selected (need_selected attribute):
|
||||
0: no selection needed (use all the message body)
|
||||
1: need a selection
|
||||
|
||||
Signature
|
||||
Signature (need_signature attribute):
|
||||
0: No signature needed
|
||||
1: Signature needed
|
||||
|
||||
Custom Text (need_custom_text attribute):
|
||||
0: No custom text needed
|
||||
1: Custom text needed
|
||||
*/
|
||||
|
||||
export const defaultPrompts = [
|
||||
{ id: 'prompt_reply', name: "__MSG_prompt_reply__", text: "Reply to the following email.", type: 1, action: 1, need_selected: 0, need_signature: 1 },
|
||||
{ id: 'prompt_rewrite_polite', name: "__MSG_prompt_rewrite_polite__", text: "Rewrite the following text to be more polite. Reply with only the re-written text and with no extra comments or other text.", type: 2, action: 2, need_selected: 1, need_signature: 0 },
|
||||
{ id: 'prompt_rewrite_formal', name: "__MSG_prompt_rewrite_formal__", text: "Rewrite the following text to be more formal. Reply with only the re-written text and with no extra comments or other text.", type: 2, action: 2, need_selected: 1, need_signature: 0 },
|
||||
{ id: 'prompt_classify', name: "__MSG_prompt_classify__", text: "Classify the following text in terms of Politeness, Warmth, Formality, Assertiveness, Offensiveness giving a percentage for each category. Reply with only the category and score with no extra comments or other text.", type: 0, action: 0, need_selected: 0, need_signature: 0 },
|
||||
{ id: 'prompt_summarize_this', name: "__MSG_prompt_summarize_this__", text: "Summarize the following email into a bullet point list.", type: 0, action: 0, need_selected: 0, need_signature: 0 },
|
||||
{ id: 'prompt_translate_this', name: "__MSG_prompt_translate_this__", text: "Translate the following email in ", type: 0, action: 0, need_selected: 0, need_signature: 0 },
|
||||
{ id: 'prompt_this', name: "__MSG_prompt_this__", text: "Reply with only the needed text and with no extra comments or other text.", type: 2, action: 2, need_selected: 1, need_signature: 0 },
|
||||
{ id: 'prompt_reply', name: "__MSG_prompt_reply__", text: "Reply to the following email.", type: 1, action: 1, need_selected: 0, need_signature: 1, need_custom_text: 1 }, // need_custom_text set to 1 only for testing
|
||||
{ id: 'prompt_rewrite_polite', name: "__MSG_prompt_rewrite_polite__", text: "Rewrite the following text to be more polite. Reply with only the re-written text and with no extra comments or other text.", type: 2, action: 2, need_selected: 1, need_signature: 0, need_custom_text: 0 },
|
||||
{ id: 'prompt_rewrite_formal', name: "__MSG_prompt_rewrite_formal__", text: "Rewrite the following text to be more formal. Reply with only the re-written text and with no extra comments or other text.", type: 2, action: 2, need_selected: 1, need_signature: 0, need_custom_text: 0 },
|
||||
{ id: 'prompt_classify', name: "__MSG_prompt_classify__", text: "Classify the following text in terms of Politeness, Warmth, Formality, Assertiveness, Offensiveness giving a percentage for each category. Reply with only the category and score with no extra comments or other text.", type: 0, action: 0, need_selected: 0, need_signature: 0, need_custom_text: 0 },
|
||||
{ id: 'prompt_summarize_this', name: "__MSG_prompt_summarize_this__", text: "Summarize the following email into a bullet point list.", type: 0, action: 0, need_selected: 0, need_signature: 0, need_custom_text: 0 },
|
||||
{ id: 'prompt_translate_this', name: "__MSG_prompt_translate_this__", text: "Translate the following email in ", type: 0, action: 0, need_selected: 0, need_signature: 0, need_custom_text: 0 },
|
||||
{ id: 'prompt_this', name: "__MSG_prompt_this__", text: "Reply with only the needed text and with no extra comments or other text.", type: 2, action: 2, need_selected: 1, need_signature: 0, need_custom_text: 0 },
|
||||
];
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
"manifest_version": 2,
|
||||
"name": "ThunderAI",
|
||||
"description": "__MSG_extensionDescription__",
|
||||
"version": "1.0.5",
|
||||
"version": "1.1.0",
|
||||
"author": "Mic (m@micz.it)",
|
||||
"homepage_url": "https://micz.it/thunderdbird-addon-thunderai/",
|
||||
"browser_specific_settings": {
|
||||
|
|
|
|||
|
|
@ -122,7 +122,7 @@ messenger.runtime.onMessage.addListener(async (message, sender, sendResponse) =>
|
|||
});
|
||||
|
||||
|
||||
async function openChatGPT(promptText, action, curr_tabId) {
|
||||
async function openChatGPT(promptText, action, curr_tabId, do_custom_text = 0) {
|
||||
let prefs = await browser.storage.sync.get(prefs_default);
|
||||
prefs = checkScreenDimensions(prefs);
|
||||
console.log('Prompt length: ' + promptText.length);
|
||||
|
|
@ -162,6 +162,7 @@ async function openChatGPT(promptText, action, curr_tabId) {
|
|||
});
|
||||
|
||||
let pre_script = `let mztaStatusPageDesc="`+ browser.i18n.getMessage("prefs_status_page") +`";
|
||||
let mztaDoCustomText=`+ do_custom_text +`;
|
||||
`;
|
||||
|
||||
browser.tabs.executeScript(createdTab.id, { code: pre_script + mzta_script, matchAboutBlank: false })
|
||||
|
|
|
|||
|
|
@ -7,6 +7,11 @@
|
|||
<body>
|
||||
<div id="miczBackPrefs"><a href="mzta-options.html">__MSG_backToOptionsText__</a></div>
|
||||
<div id="miczRelNotes"><h1>ThunderAI Release Notes</h1>
|
||||
<h2>Version 1.1.0 - ??/??/2024</h2>
|
||||
<ul>
|
||||
<li>A prompt can be configured to request additional text from the user.</li>
|
||||
<li>...</li>
|
||||
</ul>
|
||||
<h2>Version 1.0.5 - 03/05/2024</h2>
|
||||
<ul>
|
||||
<li>Fixed the handling of ChatGPT-4 in a large window. See issue <a href="https://github.com/micz/ThunderAI/issues/38">#38</a></li>
|
||||
|
|
|
|||
Loading…
Reference in a new issue