check if the user is logged in, otherwise show a message. fixes #7

This commit is contained in:
mic 2024-04-03 23:32:59 +02:00
parent a97217ba64
commit ddd0475076
3 changed files with 26 additions and 10 deletions

View file

@ -74,6 +74,11 @@
"description": "" "description": ""
}, },
"chatgpt_user_not_logged_in": {
"message": "You are not logged in to ChatGPT. Please log in with your credentials, close the ChatGPT window, and then repeat the action you attempted. You will remain logged in afterwards.",
"description": ""
},
"prefs_OptionText_chatgpt_win_text": { "prefs_OptionText_chatgpt_win_text": {
"message": "ChatGPT window dimensions", "message": "ChatGPT window dimensions",
"description": "" "description": ""

View file

@ -74,6 +74,11 @@
"description": "" "description": ""
}, },
"chatgpt_user_not_logged_in": {
"message": "Non sei connesso a ChatGPT. Effettua l'accesso con le tue credenziali, chiudi la finestra di ChatGPT e poi ripeti l'azione che avevi tentato. Rimarrai connesso in seguito.",
"description": ""
},
"prefs_OptionText_chatgpt_win_text": { "prefs_OptionText_chatgpt_win_text": {
"message": "Dimensioni della finestra di ChatGPT", "message": "Dimensioni della finestra di ChatGPT",
"description": "" "description": ""

View file

@ -146,20 +146,26 @@ function operation_done(){
chatpgt_scrollToBottom(); chatpgt_scrollToBottom();
} }
function checkLoggedIn(){
return !window.location.href.startsWith('https://chat.openai.com/auth/');
}
// Nello script di contenuto // Nello script di contenuto
browser.runtime.onMessage.addListener((message, sender, sendResponse) => { browser.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.command === "chatgpt_send") { if (message.command === "chatgpt_send") {
addCustomDiv(message.action,message.tabId); if(!checkLoggedIn()){
//console.log(message.prompt); // User not logged in
(async () => { alert(browser.i18n.getMessage("chatgpt_user_not_logged_in"));
//await chatgpt.isLoaded(); }else{
await chatgpt_sendMsg(message.prompt,'click'); addCustomDiv(message.action,message.tabId);
await chatgpt_isIdle(); (async () => {
// console.log(response); //await chatgpt.isLoaded();
operation_done(); await chatgpt_sendMsg(message.prompt,'click');
})(); await chatgpt_isIdle();
// console.log(response);
operation_done();
})();
}
} }
}); });