Enhance login check and alert handling in run function. see #411
This commit is contained in:
parent
0358d40c0d
commit
1ef91e1bbe
1 changed files with 11 additions and 4 deletions
|
|
@ -389,7 +389,7 @@ function operation_done(){
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkLoggedIn(){
|
function checkLoggedIn(){
|
||||||
return !window.location.href.startsWith('https://chatgpt.com/auth/');
|
return !window.location.href.startsWith('https://chatgpt.com/auth/') && document.querySelector('button[data-testid*=login]') === null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function showCustomTextField(){
|
function showCustomTextField(){
|
||||||
|
|
@ -634,10 +634,17 @@ function doLog(msg){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function run(){
|
function run(checkTab = null) {
|
||||||
if(!checkLoggedIn()){
|
if(!checkLoggedIn()){
|
||||||
// User not logged in
|
// User not logged in
|
||||||
|
if(checkTab){
|
||||||
|
clearInterval(checkTab);
|
||||||
|
}
|
||||||
|
doLog("User not logged in, showing warning message.");
|
||||||
alert(browser.i18n.getMessage("chatgpt_user_not_logged_in"));
|
alert(browser.i18n.getMessage("chatgpt_user_not_logged_in"));
|
||||||
|
// we are not closing the window, because the user could try to log in
|
||||||
|
// doLog("User not logged in, closing window.");
|
||||||
|
// browser.runtime.sendMessage({command: "chatgpt_close", window_id: mztaWinId});
|
||||||
}else{
|
}else{
|
||||||
addCustomDiv(current_action,current_tabId,current_mailMessageId);
|
addCustomDiv(current_action,current_tabId,current_mailMessageId);
|
||||||
(async () => {
|
(async () => {
|
||||||
|
|
@ -666,7 +673,7 @@ browser.runtime.onMessage.addListener((message, sender, sendResponse) => {
|
||||||
if((current_mailMessageId == -1) && (current_action == '1')) { // we are using the reply from the compose window!
|
if((current_mailMessageId == -1) && (current_action == '1')) { // we are using the reply from the compose window!
|
||||||
current_action = '2'; // replace text
|
current_action = '2'; // replace text
|
||||||
}
|
}
|
||||||
run();
|
run(checkTab);
|
||||||
break;
|
break;
|
||||||
case "chatgpt_alive":
|
case "chatgpt_alive":
|
||||||
sendResponse({isAlive: true});
|
sendResponse({isAlive: true});
|
||||||
|
|
@ -679,7 +686,7 @@ let checkTab = setInterval(() => {
|
||||||
if(customDiv){
|
if(customDiv){
|
||||||
clearInterval(checkTab);
|
clearInterval(checkTab);
|
||||||
}else{
|
}else{
|
||||||
run();
|
run(checkTab);
|
||||||
}
|
}
|
||||||
}, 1000);
|
}, 1000);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue