diff --git a/CHANGELOG.md b/CHANGELOG.md index 2401da7a..bff4fe01 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,8 +7,11 @@

Version 3.1.0 - ??/??/2025

diff --git a/README.md b/README.md index e97a8d10..bb624e15 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ThunderAI is a Thunderbird Addon that uses the capabilities of ChatGPT | Google Gemini | Ollama to enhance email management. -It enables users to analyse, write, correct, assign tags and optimize their emails, facilitating more effective and professional communication. +It enables users to analyse, write, correct, assign tags, create calendar events and optimize their emails, facilitating more effective and professional communication. ThunderAI is a tool for anyone looking to improve their email quality, both in content and grammar, making the writing process quicker and more intuitive. diff --git a/_locales/en/messages.json b/_locales/en/messages.json index da85f92e..db9506e0 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -954,5 +954,57 @@ "placeholder_mail_typed_text": { "message": "Typed text before the quoted mail body", "description": "" + }, + "prompt_get_calendar_event": { + "message": "Add a new calendar event", + "description": "" + }, + "prompt_get_calendar_event_full_text": { + "message": "Extract all relevant details required to generate a calendar event from the following text. The extracted information should include:\n- Event Title\n- Start Date and Time (including timezone, if specified)\n- End Date and Time (including timezone, if specified)\n- Full day (if mentioned)\nEnsure the data is formatted clearly and consistently so that it can be directly used for creating a calendar event.\nIf there are relative time references, consider that the date and time of the email are \"{%mail_datetime%}\". Calculate the start date and time based on this reference. If the calculated start date and time are earlier than \"{%current_datetime%}\", recalculate the start date and time using \"{%current_datetime%}\" as the base.\nIf the duration is not specified, set it to one hour.\nIf you're not able to get one or more of the required information, please respond with an empty string.\nGenerate a response in JSON format only. Do not include any additional text or explanations; provide only the JSON. Here is the format to be used:\n{\n\"startDate\": \"YYYYMMDDTHHMMSS\",\n\"endDate\": \"YYYYMMDDTHHMMSS\",\n\"summary\": \"Calendar event summary here\",\n\"forceAllDay\": false\n}\nHere's the text:\"{%selected_text%}\"", + "description": "" + }, + "prefs_OptionText_get_calendar_event": { + "message": "Add a new calendar event from selected text", + "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.", + "description": "" + }, + "prefs_OptionText_btnManageCalendarEventInfo": { + "message": "Manage calendar events settings", + "description": "" + }, + "GetCalendarEvent_PageTitle": { + "message": "Manage Calendar Events Settings", + "description": "" + }, + "GetCalendarEvent_info_default": { + "message": "In this page you can modify the default prompt used to get a calendar event from selected text.", + "description": "" + }, + "GetCalendarEvent_prompt_text_title": { + "message": "Current prompt text", + "description": "" + }, + "prefs_OptionText_GetCalendarEvent_infoline2": { + "message": "You can change the prompt as you wish, but the response received from the AI must be in JSON format as specified in the default prompt!", + "description": "" + }, + "prefs_OptionText_get_calendar_event_Sparks_not_present": { + "message": "To use the calendar event feature, please install the ThunderAI Sparks addon.", + "description": "" + }, + "prefs_OptionText_download_now": { + "message": "Download ThunderAI Sparks now!", + "description": "" + }, + "placeholder_mail_datetime": { + "message": "The date and time of the email", + "description": "" + }, + "placeholder_current_datetime": { + "message": "The current date and time", + "description": "" } } \ No newline at end of file diff --git a/js/mzta-compose-script.js b/js/mzta-compose-script.js index d03e5437..7fdafd0d 100644 --- a/js/mzta-compose-script.js +++ b/js/mzta-compose-script.js @@ -228,12 +228,12 @@ switch (message.command) { break; case "getTags": - console.log(">>>>>>>>>>>>>> getTags: " + JSON.stringify(message.tags)); + // console.log(">>>>>>>>>>>>>> getTags: " + JSON.stringify(message.tags)); // ===== These methods are also defined in the file /js/mzta-addatags-exclusion-list.js async function addTags_getExclusionList() { let prefs_excluded_tags = await browser.storage.local.get({add_tags_exclusions: []}); - console.log(">>>>>>>>>>>>>>> addTags_getExclusionList prefs_excluded_tags: " + JSON.stringify(prefs_excluded_tags)); + // console.log(">>>>>>>>>>>>>>> addTags_getExclusionList prefs_excluded_tags: " + JSON.stringify(prefs_excluded_tags)); return prefs_excluded_tags.add_tags_exclusions; } @@ -358,7 +358,7 @@ switch (message.command) { // Parse the input string into labels const words = inputString.split(',').map(word => word.trim()).filter(word => word !== ''); - console.log(">>>>>>>>>>>>> words: " + JSON.stringify(words)); + // console.log(">>>>>>>>>>>>> words: " + JSON.stringify(words)); if(words.length == 0){ const message = document.createElement('div'); @@ -371,7 +371,7 @@ switch (message.command) { let prefs_tags = await browser.storage.sync.get({add_tags_hide_exclusions: false}); let add_tags_exclusions_list = await addTags_getExclusionList(); - console.log(">>>>>>>>>>>>> add_tags_exclusions_list: " + JSON.stringify(add_tags_exclusions_list)); + // console.log(">>>>>>>>>>>>> add_tags_exclusions_list: " + JSON.stringify(add_tags_exclusions_list)); const words_final = words .filter(word => word !== '') @@ -386,7 +386,7 @@ switch (message.command) { }; }); - console.log(">>>>>>>>>>>>> words_final: " + JSON.stringify(words_final)); + // console.log(">>>>>>>>>>>>> words_final: " + JSON.stringify(words_final)); // Create the form const form = document.createElement('form'); @@ -505,7 +505,7 @@ switch (message.command) { } return createDialog(message.tags, (selected) => { - console.log('>>>>>>>>>>>> Selected tags:', selected); + // console.log('>>>>>>>>>>>> Selected tags:', selected); browser.runtime.sendMessage({ command: "assign_tags", tags: selected, messageId: message.messageId }); }); diff --git a/js/mzta-menus.js b/js/mzta-menus.js index 4bd1c431..1c62bdec 100644 --- a/js/mzta-menus.js +++ b/js/mzta-menus.js @@ -22,7 +22,7 @@ import { getPrompts } from './mzta-prompts.js'; import { getLanguageDisplayName, getMenuContextCompose, getMenuContextDisplay, i18nConditionalGet, getMailSubject, getTagsList, transformTagsLabels } from './mzta-utils.js' import { taLogger } from './mzta-logger.js'; import { placeholdersUtils } from './mzta-placeholders.js'; -import { mzta_specialCommand_AddTags } from './special_commands/mzta-add-tags.js'; +import { mzta_specialCommand } from './mzta-special-commands.js'; export class mzta_Menus { @@ -51,7 +51,7 @@ export class mzta_Menus { } - async initialize(also_special = false) { + async initialize(also_special = []) { // also_special is an array of active special prompts ids this.allPrompts = []; this.rootMenu = []; this.shortcutMenu = []; @@ -63,7 +63,7 @@ export class mzta_Menus { }); } - async reload(also_special = false) { + async reload(also_special = []) { await browser.menus.removeAll().catch(error => { console.error("[ThunderAI] ERROR removing the menus: ", error); }); @@ -175,6 +175,12 @@ export class mzta_Menus { case 'junk_score': finalSubs['junk_score'] = curr_message.junkScore; break; + case 'mail_datetime': + finalSubs['mail_datetime'] = curr_message.date; + break; + case 'current_datetime': + finalSubs['current_datetime'] = new Date().toString(); + break; case 'tags_current_email': let tags_current_email_array = await transformTagsLabels(curr_message.tags, tags_full_list[1]); finalSubs['tags_current_email'] = tags_current_email_array.join(", "); @@ -212,7 +218,7 @@ export class mzta_Menus { //browser.runtime.sendMessage({command: "chatgpt_open", prompt: fullPrompt, action: curr_prompt.action, tabId: tabs[0].id}); if(curr_prompt.is_special == '1'){ // Special prompts switch(curr_prompt.id){ - case 'prompt_add_tags': // Add tags to the email + case 'prompt_add_tags': { // Add tags to the email let tags_current_email = ''; let prefs_at = await browser.storage.sync.get({add_tags_maxnum: 3, connection_type: '', add_tags_force_lang: true, default_chatgpt_lang: ''}); if((prefs_at.connection_type === '')||(prefs_at.connection_type === null)||(prefs_at.connection_type === undefined)||(prefs_at.connection_type === 'chatgpt_web')){ @@ -230,7 +236,7 @@ export class mzta_Menus { // TODO: use the current API, abort if using chatgpt web // COMMENTED TO DO TESTS // tags_current_email = "recipients, TEST, home, work, CAR, light"; - let cmd_addTags = new mzta_specialCommand_AddTags(fullPrompt,prefs_at.connection_type,true); + let cmd_addTags = new mzta_specialCommand(fullPrompt,prefs_at.connection_type,true); await cmd_addTags.initWorker(); try{ tags_current_email = await cmd_addTags.sendPrompt(); @@ -241,10 +247,42 @@ export class mzta_Menus { return {ok:'0'}; } this.logger.log("tags_current_email: " + tags_current_email); - console.log(">>>>>>>>>>>> tags_full_list: " + JSON.stringify(tags_full_list)); + // console.log(">>>>>>>>>>>> tags_full_list: " + JSON.stringify(tags_full_list)); browser.tabs.sendMessage(tabs[0].id, {command: "getTags", tags: tags_current_email, messageId: curr_message.id}); return {ok:'1'}; - break; + break; // Add tags to the email - END + } + case 'prompt_get_calendar_event': { // Get a calendar event info + let calendar_event_data = ''; + let prefs_at = await browser.storage.sync.get({connection_type: ''}); + if((prefs_at.connection_type === '')||(prefs_at.connection_type === null)||(prefs_at.connection_type === undefined)||(prefs_at.connection_type === 'chatgpt_web')){ + console.error("[ThunderAI | GetCalendarEvent] Invalid connection type: " + prefs_at.connection_type); + return {ok:'0'}; + } + /* We expect to receive from the AI a JSON object like this: + * { + * "startDate": "20250104T183000Z", + * "endDate": "20250104T193000Z", + * "summary": "ThunderAI Sparks", + * "forceAllDay": false + * } + */ + this.logger.log("fullPrompt: " + fullPrompt); + let cmd_GetCalendarEvent = new mzta_specialCommand(fullPrompt,prefs_at.connection_type,true); + await cmd_GetCalendarEvent.initWorker(); + try{ + calendar_event_data = await cmd_GetCalendarEvent.sendPrompt(); + // console.log(">>>>>>>>>>> calendar_event_data: " + calendar_event_data); + }catch(err){ + console.error("[ThunderAI] Error getting calendar event data: ", JSON.stringify(err)); + browser.tabs.sendMessage(tabs[0].id, { command: "sendAlert", curr_tab_type: tabs[0].type, message: "Error getting calendar event data: " + JSON.stringify(err) }); + return {ok:'0'}; + } + this.logger.log("calendar_event_data: " + calendar_event_data); + browser.runtime.sendMessage('thunderai-sparks@micz.it',{action: "openCalendarEventDialog", calendar_event_data: calendar_event_data}) + return {ok:'1'}; + break; // Get a calendar event info - END + } default: console.error("[ThunderAI] Unknown special prompt id: " + curr_prompt.id); break; @@ -278,7 +316,7 @@ export class mzta_Menus { this.shortcutMenu.push(curr_menu_entry); } - async loadMenus(also_special = false) { + async loadMenus(also_special = []) { await this.initialize(also_special); await this.addMenu(this.rootMenu); this.addClickListener(); diff --git a/js/mzta-placeholders.js b/js/mzta-placeholders.js index ca40900b..11b9a51b 100644 --- a/js/mzta-placeholders.js +++ b/js/mzta-placeholders.js @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -/* ================= PROMPTS PROPERTIES ======================================== +/* ================= PLACEHOLDERS PROPERTIES ======================================== ================ BASE PROPERTIES @@ -103,6 +103,20 @@ const defaultPlaceholders = [ type: 0, is_default: "1", }, + { + id: 'mail_datetime', + name: "__MSG_placeholder_mail_datetime__", + default_value: "", + type: 1, + is_default: "1", + }, + { + id: 'current_datetime', + name: "__MSG_placeholder_current_datetime__", + default_value: "", + type: 0, + is_default: "1", + }, { id: 'tags_current_email', name: "__MSG_placeholder_tags_current_email__", diff --git a/js/mzta-prompts.js b/js/mzta-prompts.js index 636efdf9..29581670 100644 --- a/js/mzta-prompts.js +++ b/js/mzta-prompts.js @@ -182,18 +182,44 @@ const specialPrompts = [ is_default: "1", is_special: "1", }, + { + id: 'prompt_get_calendar_event', + name: "__MSG_prompt_get_calendar_event__", + text: "prompt_get_calendar_event_full_text", + type: "1", + action: "0", + need_selected: "1", + need_signature: "0", + need_custom_text: "0", + define_response_lang: "0", + is_default: "1", + is_special: "1", + }, ]; -export async function getPrompts(onlyEnabled = false, includeSpecial = false){ +export async function getPrompts(onlyEnabled = false, includeSpecial = []){ // includeSpecial is an array of active special prompts ids const _defaultPrompts = await getDefaultPrompts_withProps(); // console.log('>>>>>>>>>>>> getPrompts _defaultPrompts: ' + JSON.stringify(_defaultPrompts)); const customPrompts = await getCustomPrompts(); // console.log('>>>>>>>>>>>> getPrompts customPrompts: ' + JSON.stringify(customPrompts)); const specialPrompts = await getSpecialPrompts(); let output = specialPrompts.concat(_defaultPrompts).concat(customPrompts); - if(!includeSpecial){ + if(includeSpecial.length == 0){ output = output.filter(obj => obj.is_special != 1); // we do not want special prompts + }else{ + // console.log(">>>>>>>>>> getPrompts includeSpecial: " + JSON.stringify(includeSpecial)); + output = output.filter(obj => includeSpecial.includes(obj.id) || obj.is_special != 1); + // output = output.filter(obj => { + // const isIncluded = includeSpecial.includes(obj.id); + // const isNotSpecial = obj.is_special != 1; + + // console.log(`>>>>>>>>>> Checking obj:`, obj); + // console.log(`>>>>>>>>>> isIncluded: ${isIncluded}`); + // console.log(`>>>>>>>>>> isNotSpecial: ${isNotSpecial}`); + + // return isIncluded || isNotSpecial; + // }); } if(onlyEnabled){ output = output.filter(obj => obj.enabled != 0); @@ -311,7 +337,21 @@ export async function getSpecialPrompts(){ }) return def_specPrompts; } else { - return prefs._special_prompts; + let updatedPrompts = [...prefs._special_prompts]; + + specialPrompts.forEach((defaultPrompt) => { + if (!updatedPrompts.some((prompt) => prompt.id === defaultPrompt.id)) { + let newPrompt = { ...defaultPrompt }; + newPrompt.text = browser.i18n.getMessage(newPrompt.text); + updatedPrompts.push(newPrompt); + } + }); + + if (updatedPrompts.length !== prefs._special_prompts.length) { + await browser.storage.local.set({ _special_prompts: updatedPrompts }); + } + + return updatedPrompts; } } diff --git a/js/special_commands/mzta-add-tags.js b/js/mzta-special-commands.js similarity index 85% rename from js/special_commands/mzta-add-tags.js rename to js/mzta-special-commands.js index b126ef90..e70eb822 100644 --- a/js/special_commands/mzta-add-tags.js +++ b/js/mzta-special-commands.js @@ -15,12 +15,13 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - // Call the API to get the tags + // Call the API to use a special prompt - import { taLogger } from '../mzta-logger.js'; + + import { taLogger } from './mzta-logger.js'; - export class mzta_specialCommand_AddTags { + export class mzta_specialCommand { prompt = ""; worker = null; @@ -32,20 +33,20 @@ constructor(prompt, llm, do_debug = false) { this.prompt = prompt; this.llm = llm; - this.logger = new taLogger('mzta_specialCommand_AddTags', do_debug); + this.logger = new taLogger('mzta_specialCommand', do_debug); this.do_debug = do_debug; switch (this.llm) { case "chatgpt_api": - this.worker = new Worker(new URL('../workers/model-worker-openai.js', import.meta.url), { type: 'module' }); + this.worker = new Worker(new URL('./workers/model-worker-openai.js', import.meta.url), { type: 'module' }); break; case "google_gemini_api": - this.worker = new Worker(new URL('../workers/model-worker-google_gemini.js', import.meta.url), { type: 'module' }); + this.worker = new Worker(new URL('./workers/model-worker-google_gemini.js', import.meta.url), { type: 'module' }); break; case "ollama_api": - this.worker = new Worker(new URL('../workers/model-worker-ollama.js', import.meta.url), { type: 'module' }); + this.worker = new Worker(new URL('./workers/model-worker-ollama.js', import.meta.url), { type: 'module' }); break; case "openai_comp_api": - this.worker = new Worker(new URL('../workers/model-worker-openai_comp.js', import.meta.url), { type: 'module' }); + this.worker = new Worker(new URL('./workers/model-worker-openai_comp.js', import.meta.url), { type: 'module' }); break; } } @@ -69,7 +70,7 @@ } case "openai_comp_api": { let prefs_api = await browser.storage.sync.get({openai_comp_host: '', openai_comp_model: '', openai_comp_api_key: '', openai_comp_use_v1: true, openai_comp_chat_name: '', do_debug: false}); - console.log(">>>>>>>>>>>> [ThunderAI] prefs_api: " + JSON.stringify(prefs_api)); + // console.log(">>>>>>>>>>>> [ThunderAI] prefs_api: " + JSON.stringify(prefs_api)); this.worker.postMessage({ type: 'init', openai_comp_host: prefs_api.openai_comp_host, openai_comp_model: prefs_api.openai_comp_model, openai_comp_api_key: prefs_api.openai_comp_api_key, openai_comp_use_v1: prefs_api.openai_comp_use_v1, do_debug: this.do_debug, i18nStrings: ''}); break; } @@ -89,7 +90,7 @@ this.full_message += payload.token; break; case 'tokensDone': - console.log(">>>>>>>>>>>> [ThunderAI] tokensDone: " + this.full_message); + // console.log(">>>>>>>>>>>> [ThunderAI] tokensDone: " + this.full_message); resolve(this.full_message); // Resolve the promise with the full message break; case 'error': diff --git a/js/mzta-utils.js b/js/mzta-utils.js index 76240221..691ec949 100644 --- a/js/mzta-utils.js +++ b/js/mzta-utils.js @@ -254,8 +254,8 @@ function generateHexColorForTag() { } export async function transformTagsLabels(labels, tags_list) { - console.log(">>>>>>>>> transformTagsLabels labels: " + labels); - console.log(">>>>>>>>> transformTagsLabels tags_list: " + tags_list); + // console.log(">>>>>>>>> transformTagsLabels labels: " + labels); + // console.log(">>>>>>>>> transformTagsLabels tags_list: " + tags_list); let output = []; for(let label of labels) { output.push(tags_list[label].tag); @@ -263,6 +263,30 @@ export async function transformTagsLabels(labels, tags_list) { return output; } +export function getActiveSpecialPromptsIDs(addtags = false, get_calendar_event = false, is_chatgpt_web = false) { + let output = []; + // console.log(">>>>>>>>>> getActiveSpecialPromptsIDs addtags: " + addtags + " get_calendar_event: " + get_calendar_event + " is_chatgpt_web: " + is_chatgpt_web); + if(is_chatgpt_web){ + return output; + } + if(addtags){ + output.push('prompt_add_tags'); + } + if(get_calendar_event){ + output.push('prompt_get_calendar_event'); + } + // console.log(">>>>>>>>>> getActiveSpecialPromptsIDs output: " + JSON.stringify(output)); + return output; +} + +export async function checkSparksPresence() { + try { + return (await browser.runtime.sendMessage('thunderai-sparks@micz.it',{action: "checkPresence"}) === 'ok'); + } catch (error) { + return false; + } +} + // The following methods are a modified version derived from https://github.com/ali-raheem/Aify/blob/13ff87583bc520fb80f555ab90a90c5c9df797a7/plugin/content_scripts/compose.js diff --git a/manifest.json b/manifest.json index 84fcc53a..4de13431 100644 --- a/manifest.json +++ b/manifest.json @@ -2,7 +2,7 @@ "manifest_version": 2, "name": "ThunderAI", "description": "__MSG_extensionDescription__", - "version": "3.1.0", + "version": "3.1.0pre1", "author": "Mic (m@micz.it)", "homepage_url": "https://micz.it/thunderbird-addon-thunderai/", "browser_specific_settings": { diff --git a/mzta-background.js b/mzta-background.js index 9a70f6c0..4db6daab 100644 --- a/mzta-background.js +++ b/mzta-background.js @@ -20,7 +20,7 @@ import { mzta_script } from './js/mzta-chatgpt.js'; import { prefs_default } from './options/mzta-options-default.js'; import { mzta_Menus } from './js/mzta-menus.js'; import { taLogger } from './js/mzta-logger.js'; -import { getCurrentIdentity, getOriginalBody, replaceBody, setBody, i18nConditionalGet, generateCallID, migrateCustomPromptsStorage, migrateDefaultPromptsPropStorage, getGPTWebModelString, getTagsList, createTag, assignTagsToMessage, checkIfTagExists } from './js/mzta-utils.js'; +import { getCurrentIdentity, getOriginalBody, replaceBody, setBody, i18nConditionalGet, generateCallID, migrateCustomPromptsStorage, migrateDefaultPromptsPropStorage, getGPTWebModelString, getTagsList, createTag, assignTagsToMessage, checkIfTagExists, getActiveSpecialPromptsIDs, checkSparksPresence } from './js/mzta-utils.js'; await migrateCustomPromptsStorage(); await migrateDefaultPromptsPropStorage(); @@ -28,9 +28,11 @@ await migrateDefaultPromptsPropStorage(); var original_html = ''; var modified_html = ''; -let prefs_init = await browser.storage.sync.get({do_debug: false, add_tags: true, connection_type: 'chatgpt_web'}); +let prefs_init = await browser.storage.sync.get({do_debug: false, add_tags: true, get_calendar_event: true, connection_type: 'chatgpt_web'}); let taLog = new taLogger("mzta-background",prefs_init.do_debug); +let special_prompts_ids = getActiveSpecialPromptsIDs(prefs_init.add_tags, await doGetCalendarEvent(prefs_init.get_calendar_event), (prefs_init.connection_type === "chatgpt_web")); + browser.composeScripts.register({ js: [{file: "/js/mzta-compose-script.js"}] }); @@ -211,8 +213,11 @@ messenger.runtime.onMessage.addListener((message, sender, sendResponse) => { break; case 'reload_menus': async function _reload_menus() { - let prefs_reload = await browser.storage.sync.get({add_tags: true, connection_type: 'chatgpt_web'}); - menus.reload(prefs_reload.add_tags && (prefs_reload.connection_type !== "chatgpt_web")); + let prefs_reload = await browser.storage.sync.get({add_tags: true, get_calendar_event: false, connection_type: 'chatgpt_web'}); + doGetCalendarEvent(prefs_reload.get_calendar_event).then(calendarEvent => { + const special_prompts_ids = getActiveSpecialPromptsIDs(prefs_reload.add_tags, calendarEvent, (prefs_reload.connection_type === "chatgpt_web")); + menus.reload(special_prompts_ids); + }); taLog.log("Reloading menus"); return true; } @@ -573,23 +578,59 @@ function checkScreenDimensions(prefs){ return prefs; } -// Register the listener for storage changes -browser.storage.onChanged.addListener((changes, areaName) => { - // Check if the change happened in the 'sync' storage area - if (areaName === 'sync') { - // Check if 'add_tags' has changed - //console.log(">>>>>>>>>>>>> changes: " + JSON.stringify(changes)); - if (changes.add_tags) { - menus.reload(changes.add_tags.newValue && (prefs_init.connection_type !== "chatgpt_web")); - } - - // Check if 'connection_type' has changed - if (changes.connection_type) { - menus.reload(prefs_init.add_tags && (changes.connection_type.newValue !== "chatgpt_web")); - } +async function doGetCalendarEvent(get_calendar_event) { + if(get_calendar_event) { + return await checkSparksPresence(); + } else { + return false; } -}); +} + +async function reload_pref_init(){ + prefs_init = await await browser.storage.sync.get({do_debug: false, add_tags: true, get_calendar_event: true, connection_type: 'chatgpt_web'}); +} + + +// Register the listener for storage changes +function setupStorageChangeListener() { + browser.storage.onChanged.addListener((changes, areaName) => { + // Check if the change happened in the 'sync' storage area + if (areaName === 'sync') { + // Process 'add_tags' changes + if (changes.add_tags) { + const newTags = changes.add_tags.newValue; + doGetCalendarEvent(prefs_init.get_calendar_event).then(calendarEvent => { + const special_prompts_ids = getActiveSpecialPromptsIDs(newTags, calendarEvent, (prefs_init.connection_type === "chatgpt_web")); + menus.reload(special_prompts_ids); + }); + } + + // Process 'get_calendar_event' changes + if (changes.get_calendar_event) { + const newCalendarEvent = changes.get_calendar_event.newValue; + doGetCalendarEvent(newCalendarEvent).then(calendarEvent => { + const special_prompts_ids = getActiveSpecialPromptsIDs(prefs_init.add_tags, calendarEvent, (prefs_init.connection_type === "chatgpt_web")); + menus.reload(special_prompts_ids); + }); + } + + // Process 'connection_type' changes + if (changes.connection_type) { + const newConnectionType = changes.connection_type.newValue; + doGetCalendarEvent(prefs_init.get_calendar_event).then(calendarEvent => { + const special_prompts_ids = getActiveSpecialPromptsIDs(prefs_init.add_tags, calendarEvent, (newConnectionType === "chatgpt_web")); + menus.reload(special_prompts_ids); + }); + } + reload_pref_init(); + } + }); +} + +// Call the function to set up the listener +setupStorageChangeListener(); + // Menus handling const menus = new mzta_Menus(openChatGPT, prefs_init.do_debug); -menus.loadMenus(prefs_init.add_tags && (prefs_init.connection_type !== "chatgpt_web")); \ No newline at end of file +menus.loadMenus(special_prompts_ids); \ No newline at end of file diff --git a/options/mzta-options-default.js b/options/mzta-options-default.js index 36f70640..10e08fe6 100644 --- a/options/mzta-options-default.js +++ b/options/mzta-options-default.js @@ -46,4 +46,5 @@ export const prefs_default = { add_tags_hide_exclusions: false, add_tags_first_uppercase: true, add_tags_force_lang: true, + get_calendar_event: true, } \ No newline at end of file diff --git a/options/mzta-options.css b/options/mzta-options.css index e3680a08..a34037e3 100644 --- a/options/mzta-options.css +++ b/options/mzta-options.css @@ -118,6 +118,12 @@ tr.conntype_google_gemini_api, tr.conntype_google_gemini_api2{ font-style: italic; } +#no_sparks td{ + text-align: center; + padding: 1em !important; + background: #bbf7f1; +} + textarea.option-textarea{ width: -moz-available; height: 10em; @@ -244,4 +250,7 @@ input.option-input[type="text"]{ background-color: rgb(2, 0, 100); } + #no_sparks td{ + background: #3b514f; + } } \ No newline at end of file diff --git a/options/mzta-options.html b/options/mzta-options.html index 76e99676..8cd6443e 100644 --- a/options/mzta-options.html +++ b/options/mzta-options.html @@ -334,6 +334,22 @@ + + __MSG_prefs_OptionText_get_calendar_event__ +
+ + + + + + + __MSG_prefs_OptionText_get_calendar_event_Sparks_not_present__ +
__MSG_prefs_OptionText_download_now__ + +