Add 'get task' feature to the options page and added the get_task settings managing page. see #333

This commit is contained in:
Mic 2025-04-16 23:44:00 +02:00
parent 6df9f86244
commit 15159452ea
7 changed files with 400 additions and 4 deletions

View file

@ -1012,13 +1012,25 @@
"description": ""
},
"prefs_OptionText_get_calendar_event_Info": {
"message": "If checked, an item will be included in the menu to get a calendar event information from selected text.",
"message": "If checked, an item will be included in the menu to get calendar event information from selected text.",
"description": ""
},
"get_calendar_event_prompt_prefs_title": {
"message": "Calendar Events Options",
"description": ""
},
"prefs_OptionText_get_task": {
"message": "Add a new task from selected text",
"description": ""
},
"prefs_OptionText_get_task_Info": {
"message": "If checked, an item will be included in the menu to get task information from selected text.",
"description": ""
},
"get_task_prompt_prefs_title": {
"message": "Tasks Options",
"description": ""
},
"Select_your_timezone": {
"message": "Select your timezone",
"description": ""
@ -1028,7 +1040,7 @@
"description": ""
},
"prefs_OptionText_calendar_enforce_timezone_Info": {
"message": "If checked, the specified timezone will be enforced for the calendar events.",
"message": "If checked, the specified timezone will be enforced for the calendar events and the tasks.",
"description": ""
},
"prefs_OptionText_btnManageCalendarEventInfo": {
@ -1052,11 +1064,23 @@
"description": ""
},
"prefs_OptionText_get_calendar_event_Sparks_not_present": {
"message": "To use the calendar event feature, please install the ThunderAI Sparks addon.",
"message": "To use the calendar event and task features, please install the ThunderAI Sparks addon.",
"description": ""
},
"prefs_OptionText_get_calendar_event_Sparks_wrong_version": {
"message": "To use the calendar event feature, please install an updated version of ThunderAI Sparks addon.",
"message": "To use the calendar event and task features, please install an updated version of ThunderAI Sparks addon.",
"description": ""
},
"GetTask_PageTitle": {
"message": "Manage Tasks Settings",
"description": ""
},
"GetTask_info_default": {
"message": "In this page you can modify the default prompt used to get a task from selected text.",
"description": ""
},
"prefs_OptionText_btnManageTaskInfo": {
"message": "Manage tasks settings",
"description": ""
},
"prefs_OptionText_download_now": {

View file

@ -52,6 +52,7 @@ export const prefs_default = {
add_tags_auto_only_inbox: true,
add_tags_context_menu: true,
get_calendar_event: true,
get_task: true,
calendar_enforce_timezone: false,
calendar_timezone: '',
spamfilter: false,

View file

@ -374,6 +374,16 @@
</label>
</td>
</tr>
<tr class="get_task_tr">
<td><span>__MSG_prefs_OptionText_get_task__</span>
<br><button id="btnManageTaskInfo" class="btn_small">__MSG_prefs_OptionText_btnManageTaskInfo__</button></td>
<td>
<label>
<input type="checkbox" id="get_task" name="get_task" class="option-input" />
__MSG_prefs_OptionText_get_task_Info__
</label>
</td>
</tr>
<tr class="get_calendar_event_tr" id="no_sparks">
<td colspan="2">
<span id="no_sparks_text">__MSG_prefs_OptionText_get_calendar_event_Sparks_not_present__</span>

View file

@ -386,6 +386,13 @@ document.addEventListener('DOMContentLoaded', async () => {
get_calendar_event_info_btn.disabled = event.target.checked ? '' : 'disabled';
});
get_calendar_event_info_btn.disabled = get_calendar_event_el.checked ? '' : 'disabled';
let get_task_el = document.getElementById('get_task');
let get_task_info_btn = document.getElementById('btnManageTaskInfo');
get_task_el.addEventListener('click', (event) => {
get_task_info_btn.disabled = event.target.checked ? '' : 'disabled';
});
get_task_info_btn.disabled = get_task_el.checked ? '' : 'disabled';
document.getElementById('btnManagePrompts').addEventListener('click', () => {
// check if the tab is already there
@ -439,6 +446,19 @@ document.addEventListener('DOMContentLoaded', async () => {
})
});
document.getElementById('btnManageTaskInfo').addEventListener('click', () => {
// check if the tab is already there
browser.tabs.query({url: browser.runtime.getURL('../pages/get-task/mzta-get-task.html')}).then((tabs) => {
if (tabs.length > 0) {
// if the tab is already there, focus it
browser.tabs.update(tabs[0].id, {active: true});
} else {
// if the tab is not there, create it
browser.tabs.create({url: browser.runtime.getURL('../pages/get-task/mzta-get-task.html')});
}
})
});
document.getElementById('btnOpenAICompForceModel').addEventListener('click', () => {
let modelName = prompt(browser.i18n.getMessage('OpenAIComp_force_model_ask')).trim();
if ((modelName !== null) && (modelName !== undefined) && (modelName !== '')) {

View file

@ -0,0 +1,119 @@
#get_task_prompt_container{
width: 90%;
margin: 20px auto;
}
#get_task_prompt_text{
width: 100%;
}
.infoline{
font-size: 0.8em;
font-style: italic;
}
.btn_div{
width: 100%;
display: flex;
justify-content: space-between;
}
table#miczPrefs {
padding: 10px;
border-spacing: 0px;
width: 90%;
margin: 0px auto 40px auto;
border: 1px solid #ccc;
}
.get_task_table_title{
width: 90%;
margin: auto;
}
.section_title{
font-weight: bold;
}
table#miczPrefs td{
border-top: 1px solid #ccc;
border-bottom: 1px solid #ccc;
vertical-align: top;
padding: 2px;
}
table#miczPrefs tr:first-child td {
border-top: none;
}
table#miczPrefs tr:last-child td {
border-bottom: none;
}
.autocomplete-container {
position: relative;
}
.autocomplete-list {
position: absolute;
top: 100%;
left: 0;
right: 0;
background-color: white;
border: 1px solid #ccc;
z-index: 1000;
max-height: 200px;
overflow-y: auto;
padding: 0;
margin: 0;
list-style: none;
font-size: small;
}
.autocomplete-list li {
padding: 8px;
cursor: pointer;
}
.autocomplete-list li:hover {
background-color: #f0f0f0;
}
.autocomplete-list li.active {
background-color: #ddd;
}
.hidden {
display: none;
}
.unsaved{
color: red;
}
@media (prefers-color-scheme: dark) {
body {
background-color: #1C1B22;
color: rgb(251, 251, 254);
}
a:link { color: #409EFF; }
a:visited { color: #409EFF; }
a:hover { color: #66B1FF; }
a:active { color: #66B1FF; }
a:active { color: #66B1FF; }
.autocomplete-list {
background-color: #2E2F36;
border: 1px solid #2E2F36;
}
.autocomplete-list li:hover {
background-color: #4c4e58;
}
.autocomplete-list li.active {
background-color: #4c4e58;
}
}

View file

@ -0,0 +1,73 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>ThunderAI - __MSG_GetTask_PageTitle__</title>
<link rel="stylesheet" href="mzta-get-task.css">
<link rel="icon" href="../../images/icon-16px.png">
</head>
<body>
<div>
<h1 class="page_title">__MSG_GetTask_PageTitle__</h1>
<p>__MSG_GetTask_info_default__</p>
</div>
<div class="get_calendar_event_table_title section_title">__MSG_get_calendar_event_prompt_prefs_title__</div>
<table id="miczPrefs">
<tr class="get_calendar_event_tr">
<td><span>__MSG_prefs_OptionText_calendar_enforce_timezone__</span></td>
<td>
<label>
<input type="checkbox" id="calendar_enforce_timezone" name="calendar_enforce_timezone" class="option-input" /> __MSG_prefs_OptionText_calendar_enforce_timezone_Info__
<br><label for="timezone">__MSG_Select_your_timezone__:</label>
<select id="calendar_timezone" name="calendar_timezone" class="option-input">
<option value=""></option>
<option value="Pacific/Midway">(UTC-11:00) Atol Midway</option>
<option value="Pacific/Honolulu">(UTC-10:00) Honolulu</option>
<option value="America/Anchorage">(UTC-09:00) Anchorage</option>
<option value="America/Los_Angeles">(UTC-08:00) Los Angeles</option>
<option value="America/Denver">(UTC-07:00) Denver</option>
<option value="America/Mexico_City">(UTC-06:00) Ciudad de Mexico</option>
<option value="America/New_York">(UTC-05:00) Nueva York</option>
<option value="America/Caracas">(UTC-04:00) Caracas</option>
<option value="America/Sao_Paulo">(UTC-03:00) Sao Paulo</option>
<option value="Atlantic/South_Georgia">(UTC-02:00) South Georgia</option>
<option value="Atlantic/Azores">(UTC-01:00) Azores</option>
<option value="Europe/London">(UTC+00:00) London</option>
<option value="Europe/Rome">(UTC+01:00) Roma</option>
<option value="Africa/Johannesburg">(UTC+02:00) Johannesburg</option>
<option value="Europe/Moscow">(UTC+03:00) Moscow</option>
<option value="Asia/Dubai">(UTC+04:00) Dubai</option>
<option value="Asia/Karachi">(UTC+05:00) Karachi</option>
<option value="Asia/Dhaka">(UTC+06:00) Dhaka</option>
<option value="Asia/Yangon">(UTC+06:30) Yangon</option>
<option value="Asia/Bangkok">(UTC+07:00) Bangkok</option>
<option value="Asia/Shanghai">(UTC+08:00) Shanghai</option>
<option value="Asia/Tokyo">(UTC+09:00) Tokyo</option>
<option value="Australia/Adelaide">(UTC+09:30) Adelaide</option>
<option value="Australia/Sydney">(UTC+10:00) Sydney</option>
<option value="Pacific/Noumea">(UTC+11:00) Noumea</option>
<option value="Pacific/Fiji">(UTC+12:00) Suva</option>
<option value="Pacific/Chatham">(UTC+12:45) Chatham Islands</option>
<option value="Pacific/Tongatapu">(UTC+13:00) Nuku'alofa</option>
<option value="Pacific/Kiritimati">(UTC+14:00) Kiritimati</option>
</select>
</label>
</td>
</tr>
</table>
<div id="get_task_container">
<span class="section_title">__MSG_GetCalendarEvent_prompt_text_title__</span><span id="get_task_prompt_unsaved" class="unsaved hidden"> __MSG_customPrompts_unsaved_changes__</span>
<br><span class="infoline">__MSG_prefs_OptionText_btnManagePrompts_infoline__ <a href="https://micz.it/thunderbird-addon-thunderai/data-placeholders/">__MSG_customPrompts_managePrompts_help__</a>
<br><b>__MSG_prefs_OptionText_GetCalendarEvent_infoline2__</b></span>
<br>
<div class="autocomplete-container">
<textarea id="get_task_prompt_text" rows="15"></textarea>
<ul class="autocomplete-list hidden"></ul>
</div>
<div id="get_task_info_additional_statements"></div>
<div class="btn_div"><button id="btn_reset_prompt" disabled>__MSG_reset_default__</button><button id="btn_save_prompt" disabled>__MSG_save__</button></div>
</div>
<script src="mzta-get-task.js" type="module"></script>
<script src="../../js/mzta-i18n.js"></script>
</body>
</html>

View file

@ -0,0 +1,149 @@
/*
* 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 { prefs_default } from '../../options/mzta-options-default.js';
import { taLogger } from '../../js/mzta-logger.js';
import { getSpecialPrompts, setSpecialPrompts } from "../../js/mzta-prompts.js";
import { getPlaceholders } from "../../js/mzta-placeholders.js";
import { textareaAutocomplete } from "../../js/mzta-placeholders-autocomplete.js";
let autocompleteSuggestions = [];
let taLog = new taLogger("mzta-get-calendar-event-page",true);
document.addEventListener('DOMContentLoaded', async () => {
i18n.updateDocument();
await restoreOptions();
document.querySelectorAll(".option-input").forEach(element => {
element.addEventListener("change", saveOptions);
});
let get_calendar_event_textarea = document.getElementById('get_task_prompt_text');
let get_calendar_event_save_btn = document.getElementById('btn_save_prompt');
let get_calendar_event_reset_btn = document.getElementById('btn_reset_prompt');
let specialPrompts = await getSpecialPrompts();
let get_calendar_event_prompt = specialPrompts.find(prompt => prompt.id === 'prompt_get_task');
get_calendar_event_textarea.addEventListener('input', (event) => {
get_calendar_event_reset_btn.disabled = (event.target.value === browser.i18n.getMessage('prompt_get_task_full_text'));
get_calendar_event_save_btn.disabled = (event.target.value === get_calendar_event_prompt.text);
if(get_calendar_event_save_btn.disabled){
document.getElementById('get_task_prompt_unsaved').classList.add('hidden');
} else {
document.getElementById('get_task_prompt_unsaved').classList.remove('hidden');
}
});
get_calendar_event_reset_btn.addEventListener('click', () => {
get_calendar_event_textarea.value = browser.i18n.getMessage('prompt_get_task_full_text');
get_calendar_event_reset_btn.disabled = true;
let event = new Event('input', { bubbles: true, cancelable: true });
get_calendar_event_textarea.dispatchEvent(event);
});
get_calendar_event_save_btn.addEventListener('click', () => {
specialPrompts.find(prompt => prompt.id === 'prompt_get_task').text = get_calendar_event_textarea.value;
setSpecialPrompts(specialPrompts);
get_calendar_event_save_btn.disabled = true;
document.getElementById('get_task_prompt_unsaved').classList.add('hidden');
browser.runtime.sendMessage({command: "reload_menus"});
});
if(get_calendar_event_prompt.text === 'prompt_get_task_full_text'){
get_calendar_event_prompt.text = browser.i18n.getMessage(get_calendar_event_prompt.text);
}
get_calendar_event_textarea.value = get_calendar_event_prompt.text;
get_calendar_event_reset_btn.disabled = (get_calendar_event_textarea.value === browser.i18n.getMessage('prompt_get_task_full_text'));
autocompleteSuggestions = (await getPlaceholders(true)).filter(p => !(p.id === 'additional_text')).map(p => ({command: '{%'+p.id+'%}', type: p.type}));
textareaAutocomplete(get_calendar_event_textarea, autocompleteSuggestions, 1); // type_value = 1, only when reading an email
});
// Methods to manage options, derived from: /options/mzta-options.js
function saveOptions(e) {
e.preventDefault();
let options = {};
let element = e.target;
switch (element.type) {
case 'checkbox':
options[element.id] = element.checked;
break;
case 'number':
options[element.id] = element.valueAsNumber;
break;
case 'text':
case 'password':
options[element.id] = element.value.trim();
break;
default:
if (element.tagName === 'SELECT') {
options[element.id] = element.value;
}else{
console.error("[ThunderAI] Unhandled input type:", element.type);
}
}
browser.storage.sync.set(options);
}
async function restoreOptions() {
function setCurrentChoice(result) {
document.querySelectorAll(".option-input").forEach(element => {
taLog.log("Options restoring " + element.id + " = " + (element.id=="chatgpt_api_key" || element.id=="openai_comp_api_key" ? "****************" : result[element.id]));
switch (element.type) {
case 'checkbox':
element.checked = result[element.id] || false;
break;
case 'number':
let default_number_value = 0;
if(element.id == 'chatgpt_win_height') default_number_value = prefs_default.chatgpt_win_height;
if(element.id == 'chatgpt_win_width') default_number_value = prefs_default.chatgpt_win_width;
element.value = result[element.id] ?? default_number_value;
break;
case 'text':
case 'password':
let default_text_value = '';
if(element.id == 'default_chatgpt_lang') default_text_value = prefs_default.default_chatgpt_lang;
element.value = result[element.id] || default_text_value;
break;
default:
if (element.tagName === 'SELECT') {
let default_select_value = '';
if(element.id == 'reply_type') default_select_value = 'reply_all';
if(element.id == 'connection_type') default_select_value = 'chatgpt_web';
element.value = result[element.id] || default_select_value;
if (element.value === '') {
element.selectedIndex = -1;
}
}else{
console.error("[ThunderAI] Unhandled input type:", element.type);
}
}
});
}
let getting = await browser.storage.sync.get(prefs_default);
setCurrentChoice(getting);
}