disablign the button only when needed. see #104
This commit is contained in:
parent
31d3804ad1
commit
ea8c2975d6
1 changed files with 7 additions and 2 deletions
|
|
@ -23,6 +23,7 @@
|
||||||
export const mzta_script = `
|
export const mzta_script = `
|
||||||
let force_go = false;
|
let force_go = false;
|
||||||
let current_message = null;
|
let current_message = null;
|
||||||
|
let current_action = null;
|
||||||
let selectionChangeTimeout = null;
|
let selectionChangeTimeout = null;
|
||||||
|
|
||||||
async function chatgpt_sendMsg(msg, method ='') { // return -1 send button not found, -2 textarea not found
|
async function chatgpt_sendMsg(msg, method ='') { // return -1 send button not found, -2 textarea not found
|
||||||
|
|
@ -161,6 +162,7 @@ function addCustomDiv(prompt_action,tabId,mailMessageId) {
|
||||||
};
|
};
|
||||||
break;
|
break;
|
||||||
case "1": // do reply
|
case "1": // do reply
|
||||||
|
btn_ok.disabled = true;
|
||||||
btn_ok.textContent = browser.i18n.getMessage("chatgpt_win_get_answer");
|
btn_ok.textContent = browser.i18n.getMessage("chatgpt_win_get_answer");
|
||||||
btn_ok.onclick = async function() {
|
btn_ok.onclick = async function() {
|
||||||
const response = getSelectedHtml();
|
const response = getSelectedHtml();
|
||||||
|
|
@ -170,6 +172,7 @@ function addCustomDiv(prompt_action,tabId,mailMessageId) {
|
||||||
};
|
};
|
||||||
break;
|
break;
|
||||||
case "2": // replace text
|
case "2": // replace text
|
||||||
|
btn_ok.disabled = true;
|
||||||
btn_ok.textContent = browser.i18n.getMessage("chatgpt_win_get_answer");
|
btn_ok.textContent = browser.i18n.getMessage("chatgpt_win_get_answer");
|
||||||
btn_ok.onclick = async function() {
|
btn_ok.onclick = async function() {
|
||||||
const response = getSelectedHtml();
|
const response = getSelectedHtml();
|
||||||
|
|
@ -181,7 +184,6 @@ function addCustomDiv(prompt_action,tabId,mailMessageId) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
btn_ok.style.display = 'none';
|
btn_ok.style.display = 'none';
|
||||||
btn_ok.disabled = true;
|
|
||||||
fixedDiv.appendChild(btn_ok);
|
fixedDiv.appendChild(btn_ok);
|
||||||
|
|
||||||
//div per custom text
|
//div per custom text
|
||||||
|
|
@ -384,7 +386,9 @@ function isSomethingSelected() {
|
||||||
document.addEventListener("selectionchange", function() {
|
document.addEventListener("selectionchange", function() {
|
||||||
// Clear any previous timeout to reset the delay
|
// Clear any previous timeout to reset the delay
|
||||||
clearTimeout(selectionChangeTimeout);
|
clearTimeout(selectionChangeTimeout);
|
||||||
|
if(current_action === '0'){
|
||||||
|
return;
|
||||||
|
}
|
||||||
// Set a timeout to delay the execution of the callback
|
// Set a timeout to delay the execution of the callback
|
||||||
selectionChangeTimeout = setTimeout(function() {
|
selectionChangeTimeout = setTimeout(function() {
|
||||||
let btn_ok = document.getElementById('mzta-btn_ok');
|
let btn_ok = document.getElementById('mzta-btn_ok');
|
||||||
|
|
@ -405,6 +409,7 @@ browser.runtime.onMessage.addListener((message, sender, sendResponse) => {
|
||||||
// User not logged in
|
// User not logged in
|
||||||
alert(browser.i18n.getMessage("chatgpt_user_not_logged_in"));
|
alert(browser.i18n.getMessage("chatgpt_user_not_logged_in"));
|
||||||
}else{
|
}else{
|
||||||
|
current_action = message.action;
|
||||||
addCustomDiv(message.action,message.tabId,message.mailMessageId);
|
addCustomDiv(message.action,message.tabId,message.mailMessageId);
|
||||||
(async () => {
|
(async () => {
|
||||||
if(mztaDoCustomText === 1){
|
if(mztaDoCustomText === 1){
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue