From 5efdf915700f7c03416e0fdd41e48ceabc43ee88 Mon Sep 17 00:00:00 2001 From: mic Date: Fri, 23 May 2025 23:24:39 +0200 Subject: [PATCH] asking for the correct permission when using the Anthropic API. Fixes #389 --- _locales/de/messages.json | 6 +++--- _locales/en/messages.json | 12 ++++++++---- _locales/fr/messages.json | 6 +++--- _locales/it/messages.json | 6 +++--- manifest.json | 1 + pages/onboarding/onboarding.css | 8 ++++---- pages/onboarding/onboarding.html | 7 +++++-- pages/onboarding/onboarding.js | 27 +++++++++++++++++++++++---- popup/mzta-popup.css | 2 +- popup/mzta-popup.html | 5 ++++- popup/mzta-popup.js | 10 ++++++++++ 11 files changed, 65 insertions(+), 25 deletions(-) diff --git a/_locales/de/messages.json b/_locales/de/messages.json index e896fc5f..654be356 100644 --- a/_locales/de/messages.json +++ b/_locales/de/messages.json @@ -1032,16 +1032,16 @@ "GetTask_info_default": { "message": "Auf dieser Seite kannst du den Standard-Prompt anpassen, der verwendet wird, um eine Aufgabe aus dem ausgewählten Text zu erstellen." }, - "ask_chatgptweb_permission_2": { + "ask_integration_permission_2": { "message": "Klicke hier, um fortzufahren." }, "ask_chatgptweb_permission_1": { "message": "Um die ChatGPT-Web-Integration zu nutzen, musst du die erforderliche Berechtigung erteilen." }, - "ask_chatgptweb_permission_2_popup": { + "ask_integration_permission_2_popup": { "message": "Klicke hier, um einen neuen Tab zu öffnen und den Anweisungen zu folgen." }, - "ask_chatgptweb_permission_ok": { + "ask_integration_permission_ok": { "message": "Berechtigung erteilt. Du kannst hier klicken, um diesen Tab zu schließen und zum Hauptfenster zurückzukehren." }, "AccountSelector_AutoTags": { diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 5151bb0d..1b7df299 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -1348,18 +1348,22 @@ "description": "" }, "ask_chatgptweb_permission_1": { - "message": "To use the ChatGPT Web Integration, you need to grant the required permission.", + "message": "To use the ChatGPT Web integration, you need to grant the required permission.", "description": "" }, - "ask_chatgptweb_permission_2_popup": { + "ask_anthropic_api_permission_1": { + "message": "To use the Anthropic API integration, you need to grant the required permission.", + "description": "" + }, + "ask_integration_permission_2_popup": { "message": "Click here to open a new tab and follow the instructions.", "description": "" }, - "ask_chatgptweb_permission_2": { + "ask_integration_permission_2": { "message": "Click here to proceed.", "description": "" }, - "ask_chatgptweb_permission_ok": { + "ask_integration_permission_ok": { "message": "Permission granted. You can click here to close this tab and return to the main window.", "description": "" }, diff --git a/_locales/fr/messages.json b/_locales/fr/messages.json index 2ac1b38e..7bc0c339 100644 --- a/_locales/fr/messages.json +++ b/_locales/fr/messages.json @@ -987,10 +987,10 @@ "prefs_OptionText_chatgpt_web_custom_data_info": { "message": "Cela doit être dans le format suivant :" }, - "ask_chatgptweb_permission_2_popup": { + "ask_integration_permission_2_popup": { "message": "Cliquez ici pour ouvrir un nouvel onglet et suivre les instructions." }, - "ask_chatgptweb_permission_2": { + "ask_integration_permission_2": { "message": "Cliquez ici pour continuer." }, "prefs_OptionText_Project_No_temporary_chat_warn": { @@ -1035,7 +1035,7 @@ "AccountSelector_Spamfilter": { "message": "Choisissez les comptes pour lesquels le filtre anti-spam est activé" }, - "ask_chatgptweb_permission_ok": { + "ask_integration_permission_ok": { "message": "Autorisation accordée. Vous pouvez cliquer ici pour fermer cet onglet et revenir à la fenêtre principale." }, "prefs_OptionText_add_tags_auto_Info2": { diff --git a/_locales/it/messages.json b/_locales/it/messages.json index 4d16bab5..5613ed83 100644 --- a/_locales/it/messages.json +++ b/_locales/it/messages.json @@ -996,7 +996,7 @@ "ask_chatgptweb_permission_1": { "message": "Per utilizzare l'integrazione con ChatGPT Web, devi concedere l'autorizzazione richiesta." }, - "ask_chatgptweb_permission_2_popup": { + "ask_integration_permission_2_popup": { "message": "Clicca qui per aprire una nuova scheda e seguire le istruzioni." }, "GetTask_info_default": { @@ -1035,10 +1035,10 @@ "no_valid_data_received": { "message": "Nessun dato valido ricevuto dall'IA." }, - "ask_chatgptweb_permission_2": { + "ask_integration_permission_2": { "message": "Clicca qui per procedere." }, - "ask_chatgptweb_permission_ok": { + "ask_integration_permission_ok": { "message": "Autorizzazione concessa. Puoi cliccare qui per chiudere questa scheda e tornare alla finestra principale." }, "prompt_proofread_this": { diff --git a/manifest.json b/manifest.json index 4137d556..02c4924b 100644 --- a/manifest.json +++ b/manifest.json @@ -38,6 +38,7 @@ "messagesUpdate", "messagesMove", "https://*.chatgpt.com/*", + "https://*.anthropic.com/*", "" ], "background": { diff --git a/pages/onboarding/onboarding.css b/pages/onboarding/onboarding.css index cd1f9b64..489cdabe 100644 --- a/pages/onboarding/onboarding.css +++ b/pages/onboarding/onboarding.css @@ -182,7 +182,7 @@ h2 { box-shadow: inset 5px 2px 5px rgba(0, 0, 0, 0.3); } -#chatgpt_web_permission { +#chatgpt_web_permission, #anthropic_api_permission { display: none; background-color: red; color: white; @@ -196,12 +196,12 @@ h2 { transition: background-color 0.3s ease, transform 0.3s ease; } -#chatgpt_web_permission:hover { +#chatgpt_web_permission:hover, #anthropic_api_permission:hover { background-color: darkred; transform: scale(1.05); } -#chatgpt_web_permission_ok { +#integration_permission_ok { display: none; background-color: green; color: white; @@ -213,7 +213,7 @@ h2 { text-align: center; cursor: pointer; } -#chatgpt_web_permission_ok:hover { +#integration_permission_ok:hover { background-color: darkgreen; transform: scale(1.05); } \ No newline at end of file diff --git a/pages/onboarding/onboarding.html b/pages/onboarding/onboarding.html index 4312f8a8..5d005741 100644 --- a/pages/onboarding/onboarding.html +++ b/pages/onboarding/onboarding.html @@ -15,9 +15,12 @@
__MSG_ask_chatgptweb_permission_1__ -
__MSG_ask_chatgptweb_permission_2__ +
__MSG_ask_integration_permission_2__
-
__MSG_ask_chatgptweb_permission_ok__
+
__MSG_ask_anthropic_api_permission_1__ +
__MSG_ask_integration_permission_2__ +
+
__MSG_ask_integration_permission_ok__

ThunderAI

diff --git a/pages/onboarding/onboarding.js b/pages/onboarding/onboarding.js index 5468c424..d9f8e6a7 100644 --- a/pages/onboarding/onboarding.js +++ b/pages/onboarding/onboarding.js @@ -32,13 +32,32 @@ document.addEventListener('DOMContentLoaded', async () => { let granted = await messenger.permissions.request({ origins: ["https://*.chatgpt.com/*"] }); if(granted){ document.getElementById("chatgpt_web_permission").style.display = "none"; - document.getElementById("chatgpt_web_permission_ok").style.display = "block"; - taLog.log("ChatGPT web permission granted"); + document.getElementById("integration_permission_ok").style.display = "block"; + taLog.log("ChatGPT Web permission granted"); }else{ - taLog.log("ChatGPT web permission denied"); + taLog.log("ChatGPT Web permission denied"); } }); - document.getElementById("chatgpt_web_permission_ok").addEventListener("click", async () => { + document.getElementById("integration_permission_ok").addEventListener("click", async () => { + await messenger.tabs.remove((await messenger.tabs.getCurrent()).id); + }); + } + } + if(prefs.connection_type === 'anthropic_api'){ + let permission_chatgpt = await messenger.permissions.contains({ origins: ["https://*.anthropic.com/*"] }); + if(permission_chatgpt === false){ + document.getElementById("anthropic_api_permission").style.display = "block"; + document.getElementById("anthropic_api_permission").addEventListener("click", async () => { + let granted = await messenger.permissions.request({ origins: ["https://*.anthropic.com/*"] }); + if(granted){ + document.getElementById("anthropic_api_permission").style.display = "none"; + document.getElementById("integration_permission_ok").style.display = "block"; + taLog.log("Anthropic API permission granted"); + }else{ + taLog.log("Anthropic API web permission denied"); + } + }); + document.getElementById("integration_permission_ok").addEventListener("click", async () => { await messenger.tabs.remove((await messenger.tabs.getCurrent()).id); }); } diff --git a/popup/mzta-popup.css b/popup/mzta-popup.css index c547f20d..7aae2583 100644 --- a/popup/mzta-popup.css +++ b/popup/mzta-popup.css @@ -68,7 +68,7 @@ body { background-color: #cfe9ff; } - #ask_chatgpt_web_perm{ + #ask_chatgpt_web_perm, #ask_anthropic_api_perm{ display: none; max-width: 20em; background-color: red; diff --git a/popup/mzta-popup.html b/popup/mzta-popup.html index 67975cde..a6190e12 100644 --- a/popup/mzta-popup.html +++ b/popup/mzta-popup.html @@ -9,7 +9,10 @@

__MSG_ask_chatgptweb_permission_1__ -
__MSG_ask_chatgptweb_permission_2_popup__ +
__MSG_ask_integration_permission_2_popup__ +
+
__MSG_ask_anthropic_api_permission_1__ +
__MSG_ask_integration_permission_2_popup__
 
diff --git a/popup/mzta-popup.js b/popup/mzta-popup.js index 0588e63b..08115114 100644 --- a/popup/mzta-popup.js +++ b/popup/mzta-popup.js @@ -66,6 +66,16 @@ document.addEventListener('DOMContentLoaded', async () => { }); } } + if(prefs.connection_type === 'anthropic_api'){ + let permission_anthropic = await browser.permissions.contains({ origins: ["https://*.anthropic.com/*"] }); + if(permission_anthropic === false){ + document.getElementById("mzta_search_banner").style.display = "none"; + document.getElementById("ask_anthropic_api_perm").style.display = "block"; + document.getElementById('ask_anthropic_api_perm').addEventListener('click', async () => { + await browser.tabs.create({ url: "../pages/onboarding/onboarding.html" }); + }); + } + } }, { once: true }); async function searchPrompt(allPrompts, tabId, tabType){