work in progress #32

This commit is contained in:
mic 2024-05-05 23:45:34 +02:00
parent c61268f1f2
commit ee9704429d
3 changed files with 26 additions and 4 deletions

View file

@ -120,6 +120,8 @@ function addCustomDiv(prompt_action,tabId) {
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-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{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-status-page:hover{color:#007bff;}";
style.innerHTML += "#mzta-custom_text{position: fixed;top: 50%;left: 50%;transform: translate(-50%, -50%);text-align: center;}";
//display:none;
// Add <style> to the page's <head> // Add <style> to the page's <head>
document.head.appendChild(style); document.head.appendChild(style);
@ -195,6 +197,21 @@ function addCustomDiv(prompt_action,tabId) {
btn_ok.style.display = 'none'; btn_ok.style.display = 'none';
fixedDiv.appendChild(btn_ok); fixedDiv.appendChild(btn_ok);
//div per custom text
let customDiv = document.createElement('div');
customDiv.id = 'mzta-custom_text';
let customTextArea = document.createElement('textarea');
customTextArea.id = 'mzta-custom_textarea';
customDiv.appendChild(customTextArea);
let customBtn = document.createElement('button');
customBtn.id = 'mzta-custom_btn';
customBtn.innerHTML = 'Send'; //browser.i18n.getMessage("chatgpt_win_custom_text");
customBtn.onclick = async function() {
//const text = document.getElementById('mzta-custom_textarea').value;
}
customDiv.appendChild(customBtn);
fixedDiv.appendChild(customDiv);
document.body.insertBefore(fixedDiv, document.body.firstChild); document.body.insertBefore(fixedDiv, document.body.firstChild);
} }
@ -253,6 +270,9 @@ browser.runtime.onMessage.addListener((message, sender, sendResponse) => {
addCustomDiv(message.action,message.tabId); addCustomDiv(message.action,message.tabId);
(async () => { (async () => {
let prefs = await browser.storage.sync.get({chatpgt_use_gpt4:false}); let prefs = await browser.storage.sync.get({chatpgt_use_gpt4:false});
if(mztaDoCustomText === 1){
alert('custom_text');
}
if(prefs.chatpgt_use_gpt4){ if(prefs.chatpgt_use_gpt4){
await checkGPT4Model(); await checkGPT4Model();
} }

View file

@ -87,14 +87,15 @@ export class mzta_Menus {
default: default:
break; break;
} }
const tabs = await browser.tabs.query({ active: true, currentWindow: true }); 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}); //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); this.rootMenu.push(curr_menu_entry);
}; };
async getDefaultSignature(){ async getDefaultSignature(){
let prefs = await browser.storage.sync.get({default_sign_name: ''}); let prefs = await browser.storage.sync.get({default_sign_name: ''});
if(prefs.default_sign_name===''){ if(prefs.default_sign_name===''){

View file

@ -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); let prefs = await browser.storage.sync.get(prefs_default);
prefs = checkScreenDimensions(prefs); prefs = checkScreenDimensions(prefs);
console.log('Prompt length: ' + promptText.length); 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 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 }) browser.tabs.executeScript(createdTab.id, { code: pre_script + mzta_script, matchAboutBlank: false })