Merge pull request #340 from micz/chatgpt_permission_optional

Add ChatGPT web permission as optional
This commit is contained in:
Mic 2025-04-13 20:58:24 +02:00 committed by GitHub
commit 799bd1d1d5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 133 additions and 3 deletions

View file

@ -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": ""
}
}

View file

@ -31,13 +31,13 @@
"activeTab",
"accountsRead",
"downloads",
"messagesTagsList",
"https://*.chatgpt.com/*"
"messagesTagsList"
],
"optional_permissions": [
"messagesTags",
"messagesUpdate",
"messagesMove",
"https://*.chatgpt.com/*",
"<all_urls>"
],
"background": {

View file

@ -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);
}

View file

@ -14,6 +14,10 @@
</head>
<body>
<div class="content">
<div id="chatgpt_web_permission">__MSG_ask_chatgptweb_permission_1__
<br>__MSG_ask_chatgptweb_permission_2__
</div>
<div id="chatgpt_web_permission_ok">__MSG_ask_chatgptweb_permission_ok__</div>
<div class="section header">
<h1><img src="../../images/icon.png" class="title-icon"/>ThunderAI</h1>
<p>
@ -82,5 +86,7 @@
</p>
</div>
</div>
<script src="onboarding.js" type="module"></script>
<script src="../../js/mzta-i18n.js"></script>
</body>
</html>

View file

@ -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 <http://www.gnu.org/licenses/>.
*/
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 });

View file

@ -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{

View file

@ -8,6 +8,9 @@
</head>
<body>
<div id="ask_chatgpt_web_perm">__MSG_ask_chatgptweb_permission_1__
<br>__MSG_ask_chatgptweb_permission_2_popup__
</div>
<div id="mzta_search_banner">
<div id="_spacer_div">&nbsp;</div>
<div id="mzta_sending_prompt"><img src="mzta-loading.svg" title="__MSG_SendingPrompt__"></div>

View file

@ -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){