parent
c29b4b3352
commit
3213a71eba
2 changed files with 46 additions and 10 deletions
|
|
@ -256,7 +256,7 @@ browser.runtime.onMessage.addListener((message, sender, sendResponse) => {
|
||||||
promptData = message;
|
promptData = message;
|
||||||
//send the received prompt to the llm api
|
//send the received prompt to the llm api
|
||||||
if(message.do_custom_text=="1") {
|
if(message.do_custom_text=="1") {
|
||||||
messageInput._showCustomTextField();
|
messageInput._showCustomTextField(message.prompt_info?.custom_text_array);
|
||||||
}else{
|
}else{
|
||||||
sendPrompt(message);
|
sendPrompt(message);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -193,6 +193,8 @@ messageInputTemplate.content.appendChild(customDiv);
|
||||||
class MessageInput extends HTMLElement {
|
class MessageInput extends HTMLElement {
|
||||||
|
|
||||||
model = '';
|
model = '';
|
||||||
|
_customTextArray = [];
|
||||||
|
_currentCustomTextIndex = 0;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
@ -306,21 +308,55 @@ class MessageInput extends HTMLElement {
|
||||||
this._messageInputField.value = msg;
|
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';
|
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();
|
this._customTextArea.focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
async _customTextBtnClick(args) {
|
async _customTextBtnClick(args) {
|
||||||
const customText = this._customTextArea.value;
|
const customText = this._customTextArea.value;
|
||||||
// console.log(">>>>>>>>>>>>>>>> customText: " + customText);
|
|
||||||
args.customBtn.disabled = true;
|
if (this._customTextArray[this._currentCustomTextIndex]) {
|
||||||
args.customBtn.classList.add('disabled');
|
this._customTextArray[this._currentCustomTextIndex].custom_text = customText;
|
||||||
args.customLoading.style.display = 'inline-block';
|
}
|
||||||
args.customLoading.style.display = 'none';
|
|
||||||
let tab = await browser.tabs.query({ active: true, currentWindow: true });
|
this._currentCustomTextIndex++;
|
||||||
browser.runtime.sendMessage({ command: "api_send_custom_text", custom_text: customText, tabId: tab[0].id });
|
|
||||||
args.customDiv.style.display = 'none';
|
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';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue