From a30810cbee7b318a798ae60341246cfd8db0b6a2 Mon Sep 17 00:00:00 2001 From: mic Date: Sat, 13 Apr 2024 21:48:36 +0200 Subject: [PATCH] If the prompt is more than 30.000 characters, do not procede and give a warning. Fixes #26 --- _locales/en/messages.json | 5 +++++ _locales/it/messages.json | 5 +++++ js/mzta-compose-script.js | 6 +++++- mzta-background.js | 6 ++++++ 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index f8933a53..1a6fe7b7 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -79,6 +79,11 @@ "description": "" }, + "msg_prompt_too_long": { + "message": "The text you provided is too long. You need to reduce it to use ChatGPT.", + "description": "" + }, + "prefs_OptionText_release_notes": { "message": "Release Notes", "description": "" diff --git a/_locales/it/messages.json b/_locales/it/messages.json index dab61a88..5adf7250 100644 --- a/_locales/it/messages.json +++ b/_locales/it/messages.json @@ -79,6 +79,11 @@ "description": "" }, + "msg_prompt_too_long": { + "message": "Il testo che vuoi inviare a ChatGPT รจ troppo lungo. Devi ridurlo per poter procedere.", + "description": "" + }, + "prefs_OptionText_release_notes": { "message": "Note di rilascio", "description": "" diff --git a/js/mzta-compose-script.js b/js/mzta-compose-script.js index b64d891a..ab4ec110 100644 --- a/js/mzta-compose-script.js +++ b/js/mzta-compose-script.js @@ -1,6 +1,6 @@ // Modified version derived from https://github.com/ali-raheem/Aify/blob/13ff87583bc520fb80f555ab90a90c5c9df797a7/plugin/content_scripts/compose.js -console.log('mzta-compose-script.js'); +//console.log('mzta-compose-script.js'); const makeParagraphs = (text, func) => { const chunks = text.split(/\n{2,}/); @@ -86,6 +86,10 @@ switch (message.command) { insertReply(message.text); break; + case 'promptTooLong': + alert(browser.i18n.getMessage('msg_prompt_too_long')); + break; + default: // do nothing break; diff --git a/mzta-background.js b/mzta-background.js index 7ff56bd2..6d34cc9a 100644 --- a/mzta-background.js +++ b/mzta-background.js @@ -96,6 +96,12 @@ messenger.runtime.onMessage.addListener(async (message, sender, sendResponse) => async function openChatGPT(promptText, action, curr_tabId) { let prefs = await browser.storage.sync.get(prefs_default); prefs = checkScreenDimensions(prefs); + console.log('Prompt length: ' + promptText.length); + if(promptText.length > 30000 ){ + // Prompt too long for ChatGPT + browser.tabs.sendMessage(curr_tabId, { command: "promptTooLong" }); + return; + } let newWindow = await browser.windows.create({ url: "https://chat.openai.com", type: "popup",