From e0736c4a6cd2a77b5a4e07ab23a5fadf42fbd682 Mon Sep 17 00:00:00 2001 From: mic Date: Sun, 13 Apr 2025 14:55:45 +0200 Subject: [PATCH] Add ChatGPT web permission handling as optional in onboarding and popup. See #293 --- _locales/en/messages.json | 16 +++++++++++ manifest.json | 4 +-- pages/onboarding/onboarding.css | 36 +++++++++++++++++++++++++ pages/onboarding/onboarding.html | 6 +++++ pages/onboarding/onboarding.js | 46 ++++++++++++++++++++++++++++++++ popup/mzta-popup.css | 14 +++++++++- popup/mzta-popup.html | 3 +++ popup/mzta-popup.js | 11 ++++++++ 8 files changed, 133 insertions(+), 3 deletions(-) create mode 100644 pages/onboarding/onboarding.js diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 6299116a..504649ad 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -1278,5 +1278,21 @@ "CORS_give_allurls_perm": { "message": "Give \"all URLs\" permission", "description": "" + }, + "ask_chatgptweb_permission_1": { + "message": "To use the ChatGPT Web Integration, you need to grant the required permission.", + "description": "" + }, + "ask_chatgptweb_permission_2_popup": { + "message": "Click here to open a new tab and follow the instructions.", + "description": "" + }, + "ask_chatgptweb_permission_2": { + "message": "Click here to proceed.", + "description": "" + }, + "ask_chatgptweb_permission_ok": { + "message": "Permission granted. You can close this tab and return to the main window.", + "description": "" } } \ No newline at end of file diff --git a/manifest.json b/manifest.json index 201bbf85..40f56907 100644 --- a/manifest.json +++ b/manifest.json @@ -31,13 +31,13 @@ "activeTab", "accountsRead", "downloads", - "messagesTagsList", - "https://*.chatgpt.com/*" + "messagesTagsList" ], "optional_permissions": [ "messagesTags", "messagesUpdate", "messagesMove", + "https://*.chatgpt.com/*", "" ], "background": { diff --git a/pages/onboarding/onboarding.css b/pages/onboarding/onboarding.css index d3404775..cd1f9b64 100644 --- a/pages/onboarding/onboarding.css +++ b/pages/onboarding/onboarding.css @@ -181,3 +181,39 @@ h2 { .section .button:active { box-shadow: inset 5px 2px 5px rgba(0, 0, 0, 0.3); } + +#chatgpt_web_permission { + display: none; + background-color: red; + color: white; + padding: 10px; + border-radius: 5px; + margin: 10px 0; + font-size: 18px; + font-weight: bold; + text-align: center; + cursor: pointer; + transition: background-color 0.3s ease, transform 0.3s ease; +} + +#chatgpt_web_permission:hover { + background-color: darkred; + transform: scale(1.05); +} + +#chatgpt_web_permission_ok { + display: none; + background-color: green; + color: white; + padding: 10px; + border-radius: 5px; + margin: 10px 0; + font-size: 18px; + font-weight: bold; + text-align: center; + cursor: pointer; +} +#chatgpt_web_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 8ab0c1d0..4312f8a8 100644 --- a/pages/onboarding/onboarding.html +++ b/pages/onboarding/onboarding.html @@ -14,6 +14,10 @@
+
__MSG_ask_chatgptweb_permission_1__ +
__MSG_ask_chatgptweb_permission_2__ +
+
__MSG_ask_chatgptweb_permission_ok__

ThunderAI

@@ -82,5 +86,7 @@

+ + diff --git a/pages/onboarding/onboarding.js b/pages/onboarding/onboarding.js new file mode 100644 index 00000000..5468c424 --- /dev/null +++ b/pages/onboarding/onboarding.js @@ -0,0 +1,46 @@ +/* + * ThunderAI [https://micz.it/thunderbird-addon-thunderai/] + * Copyright (C) 2024 - 2025 Mic (m@micz.it) + + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +import { taLogger } from '../../js/mzta-logger.js'; + +let taLog = null; + +document.addEventListener('DOMContentLoaded', async () => { + let prefs = await browser.storage.sync.get({do_debug: false, connection_type: 'chatgpt_web'}); + taLog = new taLogger("mzta-popup",prefs.do_debug); + i18n.updateDocument(); + if(prefs.connection_type === 'chatgpt_web'){ + let permission_chatgpt = await messenger.permissions.contains({ origins: ["https://*.chatgpt.com/*"] }); + if(permission_chatgpt === false){ + document.getElementById("chatgpt_web_permission").style.display = "block"; + document.getElementById("chatgpt_web_permission").addEventListener("click", 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"); + }else{ + taLog.log("ChatGPT web permission denied"); + } + }); + document.getElementById("chatgpt_web_permission_ok").addEventListener("click", async () => { + await messenger.tabs.remove((await messenger.tabs.getCurrent()).id); + }); + } + } +}, { once: true }); \ No newline at end of file diff --git a/popup/mzta-popup.css b/popup/mzta-popup.css index 6052981f..c547f20d 100644 --- a/popup/mzta-popup.css +++ b/popup/mzta-popup.css @@ -68,7 +68,19 @@ body { background-color: #cfe9ff; } - + #ask_chatgpt_web_perm{ + display: none; + max-width: 20em; + background-color: red; + color: white; + padding: 10px; + border-radius: 5px; + font-size: 18px; + font-weight: bold; + text-align: center; + cursor: pointer; + } + @media (prefers-color-scheme: dark) { body{ diff --git a/popup/mzta-popup.html b/popup/mzta-popup.html index 8b1f3d83..67975cde 100644 --- a/popup/mzta-popup.html +++ b/popup/mzta-popup.html @@ -8,6 +8,9 @@ +
__MSG_ask_chatgptweb_permission_1__ +
__MSG_ask_chatgptweb_permission_2_popup__ +
 
diff --git a/popup/mzta-popup.js b/popup/mzta-popup.js index a7d1ce65..347277a1 100644 --- a/popup/mzta-popup.js +++ b/popup/mzta-popup.js @@ -46,6 +46,17 @@ document.addEventListener('DOMContentLoaded', async () => { get_calendar_event = prefs.get_calendar_event; searchPrompt(active_prompts, tabId, tabType); i18n.updateDocument(); + + if(prefs.connection_type === 'chatgpt_web'){ + let permission_chatgpt = await browser.permissions.contains({ origins: ["https://*.chatgpt.com/*"] }); + if(permission_chatgpt === false){ + document.getElementById("mzta_search_banner").style.display = "none"; + document.getElementById("ask_chatgpt_web_perm").style.display = "block"; + document.getElementById('ask_chatgpt_web_perm').addEventListener('click', async () => { + await browser.tabs.create({ url: "../pages/onboarding/onboarding.html" }); + }); + } + } }, { once: true }); async function searchPrompt(allPrompts, tabId, tabType){