From 3213a71eba24b13e3335936136d51a567bea022c Mon Sep 17 00:00:00 2001 From: mic Date: Wed, 11 Feb 2026 21:55:04 +0100 Subject: [PATCH] the additional text is now an array. see #525 #554 --- api_webchat/controller.js | 2 +- api_webchat/messageInput.js | 54 ++++++++++++++++++++++++++++++------- 2 files changed, 46 insertions(+), 10 deletions(-) diff --git a/api_webchat/controller.js b/api_webchat/controller.js index 2525069e..c6f349c9 100644 --- a/api_webchat/controller.js +++ b/api_webchat/controller.js @@ -256,7 +256,7 @@ browser.runtime.onMessage.addListener((message, sender, sendResponse) => { promptData = message; //send the received prompt to the llm api if(message.do_custom_text=="1") { - messageInput._showCustomTextField(); + messageInput._showCustomTextField(message.prompt_info?.custom_text_array); }else{ sendPrompt(message); } diff --git a/api_webchat/messageInput.js b/api_webchat/messageInput.js index b5b2a6b0..9007691d 100644 --- a/api_webchat/messageInput.js +++ b/api_webchat/messageInput.js @@ -193,6 +193,8 @@ messageInputTemplate.content.appendChild(customDiv); class MessageInput extends HTMLElement { model = ''; + _customTextArray = []; + _currentCustomTextIndex = 0; constructor() { super(); @@ -306,21 +308,55 @@ class MessageInput extends HTMLElement { this._messageInputField.value = msg; } - _showCustomTextField(){ + _showCustomTextField(custom_text_array){ + this._customTextArray = custom_text_array || []; + if (this._customTextArray.length === 0) { + this._customTextArray.push({ placeholder: "{%additional_text%}", info: "" }); + } + this._currentCustomTextIndex = 0; + this._renderCustomTextStep(); this._customText.style.display = 'block'; + } + + _renderCustomTextStep() { + const currentItem = this._customTextArray[this._currentCustomTextIndex]; + const infoDiv = this.shadowRoot.querySelector('#mzta-custom_info'); + + this._customTextArea.value = ""; + + if (currentItem.info && currentItem.info.trim() !== "") { + infoDiv.textContent = currentItem.info; + } else { + infoDiv.textContent = browser.i18n.getMessage("chatgpt_win_custom_text"); + } + this._customTextArea.focus(); } async _customTextBtnClick(args) { const customText = this._customTextArea.value; - // console.log(">>>>>>>>>>>>>>>> customText: " + customText); - args.customBtn.disabled = true; - args.customBtn.classList.add('disabled'); - args.customLoading.style.display = 'inline-block'; - args.customLoading.style.display = 'none'; - let tab = await browser.tabs.query({ active: true, currentWindow: true }); - browser.runtime.sendMessage({ command: "api_send_custom_text", custom_text: customText, tabId: tab[0].id }); - args.customDiv.style.display = 'none'; + + if (this._customTextArray[this._currentCustomTextIndex]) { + this._customTextArray[this._currentCustomTextIndex].custom_text = customText; + } + + this._currentCustomTextIndex++; + + if (this._currentCustomTextIndex < this._customTextArray.length) { + this._renderCustomTextStep(); + } else { + args.customBtn.disabled = true; + args.customBtn.classList.add('disabled'); + args.customLoading.style.display = 'inline-block'; + + let tab = await browser.tabs.query({ active: true, currentWindow: true }); + browser.runtime.sendMessage({ command: "api_send_custom_text", custom_text: this._customTextArray, tabId: tab[0].id }); + args.customDiv.style.display = 'none'; + + args.customBtn.disabled = false; + args.customBtn.classList.remove('disabled'); + args.customLoading.style.display = 'none'; + } } }