From 8fabbd95beffea99b9d9dc841b5da5c693ad3f0f Mon Sep 17 00:00:00 2001 From: mic Date: Thu, 12 Sep 2024 20:24:00 +0200 Subject: [PATCH 001/119] version set to 2.2.0 --- CHANGELOG.md | 5 +++++ manifest.json | 2 +- options/mzta-release-notes.html | 4 ++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 80d2b62f..5d5d7e5f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ + +

Version 2.2.0 - ??/??/2024

+

Version 2.1.4 - 11/09/2024

Version 2.1.4 - 11/09/2024

diff --git a/options/mzta-release-notes.html b/options/mzta-release-notes.html index b038051d..1e7d9673 100644 --- a/options/mzta-release-notes.html +++ b/options/mzta-release-notes.html @@ -12,6 +12,7 @@
  • [ChatGPT Web] Removed the option to force the ChatGPT4 model over ChatGPT3.5, since it was useless now.
  • [OpenAI Comp API] Added a new integration method to use a local LLM via an API compatible with OpenAI's API specifications [#126].
  • Custom Prompts storage space incremented to 5MB, using
    storage.local
    . Added also the total occupied space at the bottom of the Custom Prompts page [#129].
  • +
  • [ChatGPT Web] Updated the information in the option page.
  • ...
  • Version 2.1.4 - 11/09/2024

    From 401ae6b8eab1240372d8f5f4295674496d2bc3a1 Mon Sep 17 00:00:00 2001 From: mic Date: Fri, 20 Sep 2024 23:55:27 +0200 Subject: [PATCH 031/119] working on a shortcut that opens a popup. see #130 --- _locales/en/messages.json | 4 + js/mzta-menus.js | 41 +++++++- js/mzta-store.js | 32 ++++++ manifest.json | 11 +- mzta-background.js | 49 +++++++++ popup/mzta-popup.css | 94 +++++++++++++++++ popup/mzta-popup.html | 20 ++++ popup/mzta-popup.js | 212 ++++++++++++++++++++++++++++++++++++++ 8 files changed, 458 insertions(+), 5 deletions(-) create mode 100644 js/mzta-store.js create mode 100644 popup/mzta-popup.css create mode 100644 popup/mzta-popup.html create mode 100644 popup/mzta-popup.js diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 6d2347ee..3ccb5f74 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -542,5 +542,9 @@ "StorageSpace": { "message": "Total storage space occupied", "description": "" + }, + "SearchPrompt": { + "message": "Search a prompt", + "description": "" } } \ No newline at end of file diff --git a/js/mzta-menus.js b/js/mzta-menus.js index 9b709e19..a6c8fd96 100644 --- a/js/mzta-menus.js +++ b/js/mzta-menus.js @@ -19,7 +19,7 @@ // Some original methods are derived from https://github.com/ali-raheem/Aify/blob/cfadf52f576b7be3720b5b73af7c8d3129c054da/plugin/html/actions.js import { getPrompts } from './mzta-prompts.js'; -import { getLanguageDisplayName, getMenuContextCompose, getMenuContextDisplay } from './mzta-utils.js' +import { getLanguageDisplayName, getMenuContextCompose, getMenuContextDisplay, i18nConditionalGet } from './mzta-utils.js' export class mzta_Menus { @@ -33,6 +33,10 @@ export class mzta_Menus { //{ id: 'ItemC', act: (info, tab) => { console.log('ItemC', info, tab, info.menuItemId); alert('ItemC') } }, ]; + shortcutMenu = [ + //{ id: 'ItemD', label: 'LabelD' }, + ]; + constructor(openChatGPT) { this.menu_context_compose = getMenuContextCompose(); this.menu_context_display = getMenuContextDisplay(); @@ -45,6 +49,7 @@ export class mzta_Menus { async initialize() { this.allPrompts = []; this.rootMenu = []; + this.shortcutMenu = []; this.menu_listeners = {}; this.allPrompts = await getPrompts(true); this.allPrompts.sort((a, b) => a.name.localeCompare(b.name)); @@ -55,7 +60,7 @@ export class mzta_Menus { async reload(){ await browser.menus.removeAll().catch(error => { - console.error("[ThunderAI] ERROR removing the menus: ", error); + console.error("[ThunderAI] ERROR removing the menus: ", error); }); this.removeClickListener(); this.loadMenus(); @@ -140,10 +145,23 @@ export class mzta_Menus { } } + loadShortcutMenu() { + this.shortcutMenu = []; + this.allPrompts.forEach((prompt) => { + this.addShortcutMenu(prompt); + }); + } + + addShortcutMenu(prompt) { + let curr_menu_entry = {id: prompt.id, label: i18nConditionalGet(prompt.name), type: prompt.type}; + this.shortcutMenu.push(curr_menu_entry); + } + async loadMenus() { await this.initialize(); await this.addMenu(this.rootMenu); this.addClickListener(); + this.loadShortcutMenu(); } listener(info, tab) { @@ -219,4 +237,23 @@ export class mzta_Menus { } } + + async executeMenuAction(id) { + // Retrieve the action callback from the menu listeners using the provided ID + const action = this.menu_listeners[id]; + + if (action) { + try { + // Execute the action callback + await action(); + } catch (error) { + // Log any errors that occur during execution + console.error(`Error executing action for menu item ${id}:`, error); + } + } else { + // Warn if no action is found for the provided ID + console.warn(`No action found for menu item ID: ${id}`); + } + } + } \ No newline at end of file diff --git a/js/mzta-store.js b/js/mzta-store.js new file mode 100644 index 00000000..1a12b15a --- /dev/null +++ b/js/mzta-store.js @@ -0,0 +1,32 @@ +/* + * ThunderAI [https://micz.it/thunderbird-addon-thunderai/] + * Copyright (C) 2024 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 . + */ + + +export const taStore = { + + async setSessionData (key, value) { + let obj = {}; + obj[key] = value; + await browser.storage.session.set(obj); + }, + + async getSessionData (key) { + let output = await browser.storage.session.get(key); + return output[key]; + }, +}; \ No newline at end of file diff --git a/manifest.json b/manifest.json index d1f88f32..ebd1464b 100644 --- a/manifest.json +++ b/manifest.json @@ -14,12 +14,12 @@ "message_display_action": { "default_title": "__MSG_menu_title__", "default_icon": "images/icon-32px.png", - "type": "menu" + "default_popup": "popup/mzta-popup.html" }, "compose_action": { "default_title": "__MSG_menu_title__", "default_icon": "images/icon-32px.png", - "type":"menu" + "default_popup": "popup/mzta-popup.html" }, "permissions": [ "compose", @@ -44,5 +44,10 @@ "default_locale": "en", "options_ui": { "page": "options/mzta-options.html" - } + }, + "commands": { + "_thunderai__do_action": { + "description": "" + } + } } diff --git a/mzta-background.js b/mzta-background.js index 49763d55..f7d35795 100644 --- a/mzta-background.js +++ b/mzta-background.js @@ -20,6 +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 { taStore } from './js/mzta-store.js'; import { getCurrentIdentity, getOriginalBody, replaceBody, setBody, i18nConditionalGet, generateCallID, migrateCustomPromptsStorage, migrateDefaultPromptsPropStorage } from './js/mzta-utils.js'; await migrateCustomPromptsStorage(); @@ -65,6 +66,50 @@ browser.contentScripts.register({ runAt: "document_idle" }); +let ThunderAI_Shortcut = "Ctrl+Alt+A"; + +// Shortcut +messenger.commands.update({ + name: "_thunderai__do_action", + shortcut: ThunderAI_Shortcut +}).then(() => { + taLog.log('Shortcut [' + ThunderAI_Shortcut + '] registered successfully!'); +}).catch((error) => { + taLog.error('Error registering shortcut [' + ThunderAI_Shortcut + ']: ' + error); +}); + +// Listen for shortcut command +messenger.commands.onCommand.addListener((command, tab) => { + if (command === "_thunderai__do_action") { + handleShortcut(tab); + } +}); + +async function handleShortcut(tab) { + taLog.log("Shortcut triggered!"); + if(!["mail", "messageCompose","messageDisplay"].includes(tab.type)){ + return; + } + await taStore.setSessionData("lastShortcutTabId", tab.id); + await taStore.setSessionData("lastShortcutTabType", tab.type); + await taStore.setSessionData("lastShortcutPromptsData", menus.shortcutMenu); + console.log(">>>>>>>> menus.shortcutMenu: " + JSON.stringify(menus.shortcutMenu)); + switch (tab.type) { + case "mail": + case "messageDisplay": + taStore.setSessionData("lastShortcutFiltering", 1); + browser.messageDisplayAction.openPopup(); + break; + case "messageCompose": + taStore.setSessionData("lastShortcutFiltering", 2); + browser.composeAction.openPopup(); + break; + + default: + break; + } +} + messenger.runtime.onMessage.addListener(async (message, sender, sendResponse) => { // Check what type of message we have received and invoke the appropriate // handler function. @@ -147,6 +192,10 @@ messenger.runtime.onMessage.addListener(async (message, sender, sendResponse) => await menus.reload(); taLog.log("[ThunderAI] Reloaded menus"); break; + case 'shortcut_do_prompt': + taLog.log("Executing shortcut, promptId: " + message.promptId); + menus.executeMenuAction(message.promptId); + brea default: break; } diff --git a/popup/mzta-popup.css b/popup/mzta-popup.css new file mode 100644 index 00000000..6f1ef3de --- /dev/null +++ b/popup/mzta-popup.css @@ -0,0 +1,94 @@ +body { + background-color: rgb(122, 180, 255); +} + +#mzta_popup{ + width: 10em; + height: 11em; + background-color: rgb(122, 180, 255); + padding: 0; +} + +#mzta_search_banner{ + background-color: rgb(122, 180, 255); + color:black; + border-radius: 5px; + width: fit-content; + height: fit-content; + display: flex; + justify-content: center; + align-items: center; + position: relative; + width: fit-content; + height: 2em; + z-index: 1000; + } + + #mzta_search_input{ + width: 12em; + } + + #mzta_autocomplete-items { + position: absolute; + top: 2em; + left: 0em; + border: 1px solid #ccc; + border-top: none; + z-index: 1001; + background-color: #fff; + overflow-y: auto; + width: 10em; + max-height: 11em; + } + + .mzta_autocomplete-item { + padding: 8px; + cursor: pointer; + } + + .mzta_autocomplete-item:hover { + background-color: #e9e9e9; + } + + .mzta_autocomplete-item-active { + background-color: #e9e9e9; + } + + + @media (prefers-color-scheme: dark) { + + body{ + background-color: #27272a; + } + + #mzta_popup{ + background-color: #27272a; + } + + input { + background-color: #27272a; + color: #ffffff; + } + + #mzta_search_banner{ + background-color: #27272a; + color:#ffffff; + } + + #mzta_autocomplete-items { + border: 1px solid #555; + background-color: #2c2c2c; + } + + .mzta_autocomplete-item { + color: #ffffff; + } + + .mzta_autocomplete-item:hover { + background-color: #444444; + } + + .mzta_autocomplete-item-active { + background-color: #444444; + } + } \ No newline at end of file diff --git a/popup/mzta-popup.html b/popup/mzta-popup.html new file mode 100644 index 00000000..a622bd2e --- /dev/null +++ b/popup/mzta-popup.html @@ -0,0 +1,20 @@ + + + + + + + ThunderAI Prompts + + + +
    +
    + + +
    +
    + + + + \ No newline at end of file diff --git a/popup/mzta-popup.js b/popup/mzta-popup.js new file mode 100644 index 00000000..5441d3be --- /dev/null +++ b/popup/mzta-popup.js @@ -0,0 +1,212 @@ +/* + * ThunderAI [https://micz.it/thunderbird-addon-thunderai/] + * Copyright (C) 2024 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 { taStore } from "../js/mzta-store.js"; + +document.addEventListener('DOMContentLoaded', async () => { + let tabId = await taStore.getSessionData("lastShortcutTabId"); + let tabType = await taStore.getSessionData("lastShortcutTabType"); + let filtering = await taStore.getSessionData("lastShortcutFiltering"); + let _prompts_data = await taStore.getSessionData("lastShortcutPromptsData"); + console.log(">>>>>>>>>>>>> _prompts_data: " + JSON.stringify(_prompts_data)); + let active_prompts = filterPromptsForTab(_prompts_data, filtering); + console.log(">>>>>>>>>>>>>> active_prompts: " + JSON.stringify(active_prompts)); + searchPrompt(active_prompts, tabId, tabType); + i18n.updateDocument(); +}, { once: true }); + +async function searchPrompt(allPrompts, tabId, tabType){ + console.log(">>>>>>>>>>>>>> allPrompts: " + JSON.stringify(allPrompts)); + console.log(">>>>>>>>>>>>>>> tabType: " + tabType); + + let input = document.getElementById('mzta_search_input'); + let autocompleteList = document.getElementById('mzta_autocomplete-items'); + let banner = document.getElementById('mzta_search_banner'); + + // Initialize variables to track focus and selection + let currentFocus = -1; // Tracks the currently highlighted item + let selectedId = null; // Tracks the ID of the selected item + + // Function to filter and display autocomplete suggestions + input.addEventListener('input', function() { + const query = this.value.trim().toLowerCase(); + autocompleteList.innerHTML = ''; // Clear previous suggestions + currentFocus = -1; // Reset the highlighted index + selectedId = null; // Reset the selected ID since input has changed + + // Uncomment the following lines if you want to hide suggestions when input is empty + /* + if (query === '') { + autocompleteList.style.display = 'none'; + return; + } + */ + + // Filter data based on the query + const filteredData = allPrompts.filter(item => + item.label.toLowerCase().startsWith(query) + ); + + if (filteredData.length === 0) { + autocompleteList.style.display = 'none'; + return; + } + + // Prepend numbers to the first 10 items + Array.from(filteredData).slice(0, 10).forEach((item, index) => { + const number = (index < 9) ? (index + 1).toString() : '0'; + // Check if the number is already prepended to avoid duplication + if (!item.numberPrepended) { + item.label = `${number}. ${item.label}`; + item.numberPrepended = 'true'; // Mark as prepended + } + }); + + // Create a div for each filtered result + filteredData.forEach(item => { + const itemDiv = document.createElement('div'); + itemDiv.classList.add('mzta_autocomplete-item'); + itemDiv.textContent = item.label; + itemDiv.setAttribute('data-id', item.id); + + // Add a mousedown event to select the item + itemDiv.addEventListener('mousedown', function(e) { // Use mousedown instead of click + e.preventDefault(); // Prevents the input from losing focus + input.value = item.label; + selectedId = item.id; // Store the selected item's ID + console.log('>>>>>>>>>>>>> mousedown selectedId:', selectedId); + autocompleteList.style.display = 'none'; + }); + + autocompleteList.appendChild(itemDiv); + }); + + autocompleteList.style.display = 'block'; + }); + + // Add a keydown event listener to handle arrow navigation and selection + input.addEventListener('keydown', function (e) { + + const items = autocompleteList.getElementsByClassName('mzta_autocomplete-item'); + if ((autocompleteList.style.display === 'none' || items.length === 0) + && (e.key !== 'Enter') + && !['1','2','3','4','5','6','7','8','9','0'].includes(e.key)) + { + return; // Do nothing if the autocomplete list is not visible + } + + // Handle number key presses (1-9,0) to select the corresponding item directly + if (['1','2','3','4','5','6','7','8','9','0'].includes(e.key)) { + // Map '1' to index 0, '2' to 1, ..., '9' to 8, '0' to 9 + const numIndex = (e.key === '0') ? 9 : parseInt(e.key, 10) - 1; + if (items[numIndex]) { + e.preventDefault(); // Prevent any default behavior + // Dispatch a mousedown event to simulate a click/select action + items[numIndex].dispatchEvent(new Event('mousedown')); + return; // Exit after handling the number key + } + } + + if (e.key === 'ArrowDown') { + // Navigate down the list + currentFocus++; + if (currentFocus >= items.length) currentFocus = 0; // Wrap to the first item + addActive(items); + e.preventDefault(); // Prevent cursor from moving to the end + } else if (e.key === 'ArrowUp') { + // Navigate up the list + currentFocus--; + if (currentFocus < 0) currentFocus = items.length - 1; // Wrap to the last item + addActive(items); + e.preventDefault(); // Prevent cursor from moving to the start + } else if (e.key === 'Enter') { + console.log(">>>>>>>>>>>>>> keydown == enter selectedId: " + selectedId); + if (selectedId) { + // If an item is already selected, call sendPrompt with the selected ID + e.preventDefault(); + sendPrompt(selectedId, tabId); // Call your sendPrompt function + banner.remove(); // Remove the banner after sending the prompt + } else { + // If no item is selected yet, select the highlighted item + // Select the highlighted item, or the first item if none is highlighted + e.preventDefault(); // Prevent form submission if inside a form + if (currentFocus > -1) { + if (items[currentFocus]) { + items[currentFocus].dispatchEvent(new Event('mousedown')); // Trigger the mousedown event + } + } else if (items.length > 0) { + // If no item is highlighted, select the first item + items[0].dispatchEvent(new Event('mousedown')); + } + } + } + }); + + // Function to add the "active" class to the current item + function addActive(items) { + removeActive(items); // Remove the "active" class from all items + if (currentFocus >= items.length) currentFocus = 0; + if (currentFocus < 0) currentFocus = items.length - 1; + items[currentFocus].classList.add('mzta_autocomplete-item-active'); // Add "active" class to the current item + // Ensure the active item is visible within the scrollable list + items[currentFocus].scrollIntoView({ + behavior: 'auto', // You can change to 'smooth' if you prefer smooth scrolling + block: 'nearest', // Align the item to the nearest edge of the visible area + }); + } + + // Function to remove the "active" class from all items + function removeActive(items) { + for (let i = 0; i < items.length; i++) { + items[i].classList.remove('mzta_autocomplete-item-active'); + } + } + +document.body.insertBefore(banner, document.body.firstChild); + setTimeout(() => { + input.dispatchEvent(new InputEvent('input', { bubbles: true })); + input.focus(); + }, 100); +} + + +function sendPrompt(prompt_id, tabId){ + console.log(">>>>>>>>>>>>> [ThunderAI] sendPrompt: " + prompt_id); + browser.runtime.sendMessage({command: "shortcut_do_prompt", tabId: tabId, promptId: prompt_id}); +} + +function filterPromptsForTab(prompts_data, filtering){ + // If filtering is 0, return the original array without any filters (btw it should not happen) + if (filtering === 0) { + return prompts_data; + } + + // Define the types to include based on the value of filtering + let allowedTypes; + if (filtering === 1) { + allowedTypes = ["0", "1"]; + } else if (filtering === 2) { + allowedTypes = ["0", "2"]; + } else { + // If filtering has an unexpected value, return the original data + return prompts_data; + } + + // Filter the array based on the allowed types + return prompts_data.filter(prompt => allowedTypes.includes(prompt.type)); +} \ No newline at end of file From faee5fcea62a2cb7cc1147d24065fa97ff84dee7 Mon Sep 17 00:00:00 2001 From: mic Date: Sat, 21 Sep 2024 15:55:23 +0200 Subject: [PATCH 032/119] shortcut menu grapchic improved. see #130 --- popup/mzta-popup.css | 43 ++++++++++++++++++------------------------- popup/mzta-popup.html | 8 +++----- 2 files changed, 21 insertions(+), 30 deletions(-) diff --git a/popup/mzta-popup.css b/popup/mzta-popup.css index 6f1ef3de..636d0e08 100644 --- a/popup/mzta-popup.css +++ b/popup/mzta-popup.css @@ -1,48 +1,46 @@ body { background-color: rgb(122, 180, 255); -} - -#mzta_popup{ - width: 10em; - height: 11em; - background-color: rgb(122, 180, 255); - padding: 0; + font-size: 14px; } #mzta_search_banner{ background-color: rgb(122, 180, 255); color:black; - border-radius: 5px; width: fit-content; height: fit-content; display: flex; justify-content: center; align-items: center; position: relative; - width: fit-content; - height: 2em; - z-index: 1000; + width: 10em; + max-height: 11em; + min-height: 1em; + padding: 0; + overflow-y: auto; } #mzta_search_input{ width: 12em; + position: fixed; + top:0; + left:0; + width: -moz-available; + z-index: 1001; + font-size: 13px; } #mzta_autocomplete-items { - position: absolute; - top: 2em; + position: relative; + top: 1.5em; left: 0em; - border: 1px solid #ccc; - border-top: none; - z-index: 1001; + border: none; + z-index: 1000; background-color: #fff; - overflow-y: auto; width: 10em; - max-height: 11em; } .mzta_autocomplete-item { - padding: 8px; + padding: 4px; cursor: pointer; } @@ -61,11 +59,7 @@ body { background-color: #27272a; } - #mzta_popup{ - background-color: #27272a; - } - - input { + #mzta_search_input { background-color: #27272a; color: #ffffff; } @@ -76,7 +70,6 @@ body { } #mzta_autocomplete-items { - border: 1px solid #555; background-color: #2c2c2c; } diff --git a/popup/mzta-popup.html b/popup/mzta-popup.html index a622bd2e..2563afd2 100644 --- a/popup/mzta-popup.html +++ b/popup/mzta-popup.html @@ -8,11 +8,9 @@ -
    -
    - - -
    +
    + +
    From 3d0199b2c6ee3dff69e624086502df605f4411d2 Mon Sep 17 00:00:00 2001 From: mic Date: Sun, 22 Sep 2024 21:17:26 +0200 Subject: [PATCH 033/119] menu query using include --- popup/mzta-popup.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/popup/mzta-popup.js b/popup/mzta-popup.js index 5441d3be..bd26dc24 100644 --- a/popup/mzta-popup.js +++ b/popup/mzta-popup.js @@ -45,6 +45,7 @@ async function searchPrompt(allPrompts, tabId, tabType){ // Function to filter and display autocomplete suggestions input.addEventListener('input', function() { const query = this.value.trim().toLowerCase(); + console.log(">>>>>>>>>>>> query: " + query); autocompleteList.innerHTML = ''; // Clear previous suggestions currentFocus = -1; // Reset the highlighted index selectedId = null; // Reset the selected ID since input has changed @@ -59,8 +60,9 @@ async function searchPrompt(allPrompts, tabId, tabType){ // Filter data based on the query const filteredData = allPrompts.filter(item => - item.label.toLowerCase().startsWith(query) + item.label.toLowerCase().includes(query) ); + // console.log(">>>>>>>>>>>>> filteredData: " + JSON.stringify(filteredData)); if (filteredData.length === 0) { autocompleteList.style.display = 'none'; @@ -77,6 +79,8 @@ async function searchPrompt(allPrompts, tabId, tabType){ } }); + // console.log(">>>>>>>>>>>>> filteredData: " + JSON.stringify(filteredData)); + // Create a div for each filtered result filteredData.forEach(item => { const itemDiv = document.createElement('div'); From 546a85ebe39bad87efe7cfe53d4739fa9e45565a Mon Sep 17 00:00:00 2001 From: mic Date: Sun, 22 Sep 2024 21:20:12 +0200 Subject: [PATCH 034/119] working on popup css --- popup/mzta-popup.css | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/popup/mzta-popup.css b/popup/mzta-popup.css index 636d0e08..09503173 100644 --- a/popup/mzta-popup.css +++ b/popup/mzta-popup.css @@ -13,10 +13,9 @@ body { align-items: center; position: relative; width: 10em; - max-height: 11em; + max-height: 12em; min-height: 1em; padding: 0; - overflow-y: auto; } #mzta_search_input{ @@ -30,13 +29,12 @@ body { } #mzta_autocomplete-items { - position: relative; - top: 1.5em; - left: 0em; - border: none; - z-index: 1000; - background-color: #fff; - width: 10em; + margin-top: 1.5em; + border: none; + z-index: 1000; + background-color: #fff; + width: 10em; + overflow-y: auto; } .mzta_autocomplete-item { From 4bc95623d6e4f210f78dc45606a3aaa334e8a6e0 Mon Sep 17 00:00:00 2001 From: mic Date: Sun, 22 Sep 2024 21:21:47 +0200 Subject: [PATCH 035/119] version set to 2.2.0pre2 --- manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifest.json b/manifest.json index d1f88f32..4b11c3a0 100644 --- a/manifest.json +++ b/manifest.json @@ -2,7 +2,7 @@ "manifest_version": 2, "name": "ThunderAI", "description": "__MSG_extensionDescription__", - "version": "2.2.0pre1", + "version": "2.2.0pre2", "author": "Mic (m@micz.it)", "homepage_url": "https://micz.it/thunderbird-addon-thunderai/", "browser_specific_settings": { From a54fa1f621d578e35f79a936e3e6ef523243c0f3 Mon Sep 17 00:00:00 2001 From: mic Date: Sun, 22 Sep 2024 21:27:47 +0200 Subject: [PATCH 036/119] typo fixed --- CHANGELOG.md | 2 +- options/mzta-release-notes.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b42d5639..82c98c42 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@
    • [ChatGPT Web] Removed the option to force the ChatGPT4 model over ChatGPT3.5, since it was useless now.
    • [OpenAI Comp API] Added a new integration method to use a local LLM via an API compatible with OpenAI's API specifications [#126].
    • -
    • Custom Prompts storage space incremented to 5MB, using
      storage.local
      . Added also the total occupied space at the bottom of the Custom Prompts page [#129].
    • +
    • Custom Prompts storage space incremented to 5MB, using
      storage.local
      . Added also the total occupied space at the bottom of the Custom Prompts page [#129].
    • [ChatGPT Web] Updated the information in the option page.
    • ...
    diff --git a/options/mzta-release-notes.html b/options/mzta-release-notes.html index 1e7d9673..6aa36601 100644 --- a/options/mzta-release-notes.html +++ b/options/mzta-release-notes.html @@ -11,7 +11,7 @@
    • [ChatGPT Web] Removed the option to force the ChatGPT4 model over ChatGPT3.5, since it was useless now.
    • [OpenAI Comp API] Added a new integration method to use a local LLM via an API compatible with OpenAI's API specifications [#126].
    • -
    • Custom Prompts storage space incremented to 5MB, using
      storage.local
      . Added also the total occupied space at the bottom of the Custom Prompts page [#129].
    • +
    • Custom Prompts storage space incremented to 5MB, using
      storage.local
      . Added also the total occupied space at the bottom of the Custom Prompts page [#129].
    • [ChatGPT Web] Updated the information in the option page.
    • ...
    From 995bc4a4856c9a941232adc255d15c9e31e83a7b Mon Sep 17 00:00:00 2001 From: Mic Date: Sun, 22 Sep 2024 21:28:32 +0200 Subject: [PATCH 037/119] Update CHANGELOG.md -> tags updated from pre to i --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 82c98c42..d4665973 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@
    • [ChatGPT Web] Removed the option to force the ChatGPT4 model over ChatGPT3.5, since it was useless now.
    • [OpenAI Comp API] Added a new integration method to use a local LLM via an API compatible with OpenAI's API specifications [#126].
    • -
    • Custom Prompts storage space incremented to 5MB, using
      storage.local
      . Added also the total occupied space at the bottom of the Custom Prompts page [#129].
    • +
    • Custom Prompts storage space incremented to 5MB, using storage.local. Added also the total occupied space at the bottom of the Custom Prompts page [#129].
    • [ChatGPT Web] Updated the information in the option page.
    • ...
    From 65e123c08a61a27f993b669042185739e1c0ece6 Mon Sep 17 00:00:00 2001 From: mic Date: Sun, 22 Sep 2024 21:34:14 +0200 Subject: [PATCH 038/119] popup menu colors improved --- popup/mzta-popup.css | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/popup/mzta-popup.css b/popup/mzta-popup.css index 09503173..19b39bd4 100644 --- a/popup/mzta-popup.css +++ b/popup/mzta-popup.css @@ -1,10 +1,10 @@ body { - background-color: rgb(122, 180, 255); + background-color: #FAFAFA; font-size: 14px; } #mzta_search_banner{ - background-color: rgb(122, 180, 255); + background-color: #FAFAFA; color:black; width: fit-content; height: fit-content; @@ -32,7 +32,7 @@ body { margin-top: 1.5em; border: none; z-index: 1000; - background-color: #fff; + background-color: #FAFAFA; width: 10em; overflow-y: auto; } @@ -54,16 +54,16 @@ body { @media (prefers-color-scheme: dark) { body{ - background-color: #27272a; + background-color: #2c2c2c; } #mzta_search_input { - background-color: #27272a; + background-color: #2c2c2c; color: #ffffff; } #mzta_search_banner{ - background-color: #27272a; + background-color: #2c2c2c; color:#ffffff; } From f4d51a95407698aa5b9f4b7cc676b86417a153db Mon Sep 17 00:00:00 2001 From: mic Date: Sun, 22 Sep 2024 21:39:58 +0200 Subject: [PATCH 039/119] popup css improved --- popup/mzta-popup.css | 3 +++ 1 file changed, 3 insertions(+) diff --git a/popup/mzta-popup.css b/popup/mzta-popup.css index 19b39bd4..820b76a0 100644 --- a/popup/mzta-popup.css +++ b/popup/mzta-popup.css @@ -1,6 +1,8 @@ body { background-color: #FAFAFA; font-size: 14px; + padding: 0; + margin:3px; } #mzta_search_banner{ @@ -35,6 +37,7 @@ body { background-color: #FAFAFA; width: 10em; overflow-y: auto; + padding: 0; } .mzta_autocomplete-item { From c9bd836af2535fd8e8e7fb970c4db51bec3c4a63 Mon Sep 17 00:00:00 2001 From: mic Date: Sun, 22 Sep 2024 21:55:55 +0200 Subject: [PATCH 040/119] popup menu graphics fixed. see #130 --- popup/mzta-popup.css | 9 +++++++-- popup/mzta-popup.html | 1 + popup/mzta-popup.js | 4 ++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/popup/mzta-popup.css b/popup/mzta-popup.css index 820b76a0..ee31b6ca 100644 --- a/popup/mzta-popup.css +++ b/popup/mzta-popup.css @@ -11,11 +11,12 @@ body { width: fit-content; height: fit-content; display: flex; + flex-direction: column; justify-content: center; align-items: center; position: relative; width: 10em; - max-height: 12em; + max-height: 13em; min-height: 1em; padding: 0; } @@ -29,9 +30,13 @@ body { z-index: 1001; font-size: 13px; } + + ._spacer_div{ + width: 100%; + height: 2.1em; + } #mzta_autocomplete-items { - margin-top: 1.5em; border: none; z-index: 1000; background-color: #FAFAFA; diff --git a/popup/mzta-popup.html b/popup/mzta-popup.html index 2563afd2..061214a8 100644 --- a/popup/mzta-popup.html +++ b/popup/mzta-popup.html @@ -9,6 +9,7 @@
    +
     
    diff --git a/popup/mzta-popup.js b/popup/mzta-popup.js index bd26dc24..ace65e57 100644 --- a/popup/mzta-popup.js +++ b/popup/mzta-popup.js @@ -36,6 +36,7 @@ async function searchPrompt(allPrompts, tabId, tabType){ let input = document.getElementById('mzta_search_input'); let autocompleteList = document.getElementById('mzta_autocomplete-items'); + let _spacer_div = document.getElementById('_spacer_div'); let banner = document.getElementById('mzta_search_banner'); // Initialize variables to track focus and selection @@ -66,6 +67,7 @@ async function searchPrompt(allPrompts, tabId, tabType){ if (filteredData.length === 0) { autocompleteList.style.display = 'none'; + _spacer_div.style.display = 'none'; return; } @@ -95,12 +97,14 @@ async function searchPrompt(allPrompts, tabId, tabType){ selectedId = item.id; // Store the selected item's ID console.log('>>>>>>>>>>>>> mousedown selectedId:', selectedId); autocompleteList.style.display = 'none'; + _spacer_div.style.display = 'none'; }); autocompleteList.appendChild(itemDiv); }); autocompleteList.style.display = 'block'; + _spacer_div.style.display = 'block'; }); // Add a keydown event listener to handle arrow navigation and selection From 44fa9b552f184b904a30661c8a192d49e89ab938 Mon Sep 17 00:00:00 2001 From: mic Date: Sun, 22 Sep 2024 22:00:14 +0200 Subject: [PATCH 041/119] typo fixed. --- mzta-background.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mzta-background.js b/mzta-background.js index f7d35795..69953c6d 100644 --- a/mzta-background.js +++ b/mzta-background.js @@ -195,7 +195,7 @@ messenger.runtime.onMessage.addListener(async (message, sender, sendResponse) => case 'shortcut_do_prompt': taLog.log("Executing shortcut, promptId: " + message.promptId); menus.executeMenuAction(message.promptId); - brea + break; default: break; } From 7f43d0dd20e8f18497c2859f7e2841a52b5e6aa7 Mon Sep 17 00:00:00 2001 From: mic Date: Sun, 22 Sep 2024 22:16:09 +0200 Subject: [PATCH 042/119] popup menu correctly working via shortcut and via mouse click. see #130 --- mzta-background.js | 28 +++++++++++++++++++++++++--- popup/mzta-loading.svg | 10 ++++++++++ popup/mzta-popup.css | 2 +- popup/mzta-popup.html | 3 ++- popup/mzta-popup.js | 5 +++++ 5 files changed, 43 insertions(+), 5 deletions(-) create mode 100644 popup/mzta-loading.svg diff --git a/mzta-background.js b/mzta-background.js index 69953c6d..1f4c3643 100644 --- a/mzta-background.js +++ b/mzta-background.js @@ -90,6 +90,20 @@ async function handleShortcut(tab) { if(!["mail", "messageCompose","messageDisplay"].includes(tab.type)){ return; } + switch (tab.type) { + case "mail": + case "messageDisplay": + browser.messageDisplayAction.openPopup(); + break; + case "messageCompose": + browser.composeAction.openPopup(); + break; + default: + break; + } +} + +async function preparePopupMenu(tab) { await taStore.setSessionData("lastShortcutTabId", tab.id); await taStore.setSessionData("lastShortcutTabType", tab.type); await taStore.setSessionData("lastShortcutPromptsData", menus.shortcutMenu); @@ -98,13 +112,10 @@ async function handleShortcut(tab) { case "mail": case "messageDisplay": taStore.setSessionData("lastShortcutFiltering", 1); - browser.messageDisplayAction.openPopup(); break; case "messageCompose": taStore.setSessionData("lastShortcutFiltering", 2); - browser.composeAction.openPopup(); break; - default: break; } @@ -187,14 +198,25 @@ messenger.runtime.onMessage.addListener(async (message, sender, sendResponse) => modified_html = await getOriginalBody(message.tabId); await setBody(message.tabId, original_html); await setBody(message.tabId, modified_html); + return true; break; case 'reload_menus': await menus.reload(); taLog.log("[ThunderAI] Reloaded menus"); + return true; break; case 'shortcut_do_prompt': taLog.log("Executing shortcut, promptId: " + message.promptId); menus.executeMenuAction(message.promptId); + return true; + break; + case 'popup_menu_ready': + let tabs = await browser.tabs.query({ active: true, currentWindow: true }); + if(tabs.length == 0){ + return Promise.resolve(false); + } + preparePopupMenu(tabs[0]); + return Promise.resolve(true); break; default: break; diff --git a/popup/mzta-loading.svg b/popup/mzta-loading.svg new file mode 100644 index 00000000..27b59d6a --- /dev/null +++ b/popup/mzta-loading.svg @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/popup/mzta-popup.css b/popup/mzta-popup.css index ee31b6ca..a99ee179 100644 --- a/popup/mzta-popup.css +++ b/popup/mzta-popup.css @@ -31,7 +31,7 @@ body { font-size: 13px; } - ._spacer_div{ + #_spacer_div{ width: 100%; height: 2.1em; } diff --git a/popup/mzta-popup.html b/popup/mzta-popup.html index 061214a8..a7ad4126 100644 --- a/popup/mzta-popup.html +++ b/popup/mzta-popup.html @@ -9,8 +9,9 @@
    -
     
    +
     
    +
    diff --git a/popup/mzta-popup.js b/popup/mzta-popup.js index ace65e57..b6bf7e1f 100644 --- a/popup/mzta-popup.js +++ b/popup/mzta-popup.js @@ -19,6 +19,9 @@ import { taStore } from "../js/mzta-store.js"; document.addEventListener('DOMContentLoaded', async () => { + let reponse = await browser.runtime.sendMessage({command: "popup_menu_ready"}); + console.log(">>>>>>>>>>>>>> reponse: " + JSON.stringify(reponse)); + let tabId = await taStore.getSessionData("lastShortcutTabId"); let tabType = await taStore.getSessionData("lastShortcutTabType"); let filtering = await taStore.getSessionData("lastShortcutFiltering"); @@ -36,6 +39,7 @@ async function searchPrompt(allPrompts, tabId, tabType){ let input = document.getElementById('mzta_search_input'); let autocompleteList = document.getElementById('mzta_autocomplete-items'); + let autocompleteListLoading = document.getElementById('mzta_autocomplete-items-loading'); let _spacer_div = document.getElementById('_spacer_div'); let banner = document.getElementById('mzta_search_banner'); @@ -103,6 +107,7 @@ async function searchPrompt(allPrompts, tabId, tabType){ autocompleteList.appendChild(itemDiv); }); + autocompleteListLoading.style.display = 'none'; autocompleteList.style.display = 'block'; _spacer_div.style.display = 'block'; }); From ac3d1f876140c6e6126429758972d336214c83d1 Mon Sep 17 00:00:00 2001 From: mic Date: Sun, 22 Sep 2024 22:27:44 +0200 Subject: [PATCH 043/119] added shortcut description --- manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifest.json b/manifest.json index ebd1464b..13f40295 100644 --- a/manifest.json +++ b/manifest.json @@ -47,7 +47,7 @@ }, "commands": { "_thunderai__do_action": { - "description": "" + "description": "Opens the ThunderAI prompts menu" } } } From 4021971102d8a91f99c216af3cbd7388cd3a5a3b Mon Sep 17 00:00:00 2001 From: mic Date: Sun, 22 Sep 2024 22:36:22 +0200 Subject: [PATCH 044/119] added an informative text about the shortcut in the options page. see #130 --- _locales/en/messages.json | 8 ++++++++ options/mzta-options.html | 8 ++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 3ccb5f74..afdba6c7 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -327,6 +327,14 @@ "message": "To use this integration, you need to set up a local server compatible with the OpenAI API, like LM Studio. Once the server is running, enter its address in the designated field within the application. To ensure proper communication between ThunderAI and the local server remember to set the CORS settings correctly.", "description": "" }, + "prefsInfoDesc_5": { + "message": "Remember that you can open the ThunderAI menu using the keyboard shortcut CTRL+ALT+A.", + "description": "" + }, + "prefsInfoDesc_6": { + "message": "You can change the shortcut clicking on the cogwheel icon at the top right of this page and choosing \"Manage Extension Shortcut\".", + "description": "" + }, "prefsDonation_1": { "message": "Do you like this addon?", "description": "" diff --git a/options/mzta-options.html b/options/mzta-options.html index 7105da96..9b9e9f4f 100644 --- a/options/mzta-options.html +++ b/options/mzta-options.html @@ -183,10 +183,14 @@

    __MSG_prefsInfoTitle__

    -

    __MSG_prefsInfoDesc_1__
    +

    + __MSG_prefsInfoDesc_1__
    __MSG_prefsInfoDesc_2__
    __MSG_prefsInfoDesc_3__
    - __MSG_prefsInfoDesc_4__

    + __MSG_prefsInfoDesc_4__ +
    __MSG_prefsInfoDesc_5__ +
    __MSG_prefsInfoDesc_6__
    +

    __MSG_TranslateText__ __MSG_TranslateLink__
    __MSG_prefsDonation_1__
    __MSG_prefsDonation_2__
    From 1c01cb23fd1cd59f61d190b84e51d6da5392fd21 Mon Sep 17 00:00:00 2001 From: mic Date: Sun, 22 Sep 2024 23:10:07 +0200 Subject: [PATCH 045/119] when clicking with the mouse send the prompt immediatly --- popup/mzta-popup.js | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/popup/mzta-popup.js b/popup/mzta-popup.js index b6bf7e1f..e1ea06fe 100644 --- a/popup/mzta-popup.js +++ b/popup/mzta-popup.js @@ -102,8 +102,19 @@ async function searchPrompt(allPrompts, tabId, tabType){ console.log('>>>>>>>>>>>>> mousedown selectedId:', selectedId); autocompleteList.style.display = 'none'; _spacer_div.style.display = 'none'; + sendPrompt(selectedId, tabId); }); + // Add a select_prompt event to select the item + itemDiv.addEventListener('select_prompt', function(e) { // Use select_prompt instead of click + e.preventDefault(); // Prevents the input from losing focus + input.value = item.label; + selectedId = item.id; // Store the selected item's ID + console.log('>>>>>>>>>>>>> select_prompt selectedId:', selectedId); + autocompleteList.style.display = 'none'; + _spacer_div.style.display = 'none'; + }); + autocompleteList.appendChild(itemDiv); }); @@ -129,8 +140,8 @@ async function searchPrompt(allPrompts, tabId, tabType){ const numIndex = (e.key === '0') ? 9 : parseInt(e.key, 10) - 1; if (items[numIndex]) { e.preventDefault(); // Prevent any default behavior - // Dispatch a mousedown event to simulate a click/select action - items[numIndex].dispatchEvent(new Event('mousedown')); + // Dispatch a select_prompt event to simulate a click/select action + items[numIndex].dispatchEvent(new Event('select_prompt')); return; // Exit after handling the number key } } @@ -153,18 +164,18 @@ async function searchPrompt(allPrompts, tabId, tabType){ // If an item is already selected, call sendPrompt with the selected ID e.preventDefault(); sendPrompt(selectedId, tabId); // Call your sendPrompt function - banner.remove(); // Remove the banner after sending the prompt + //banner.remove(); // Remove the banner after sending the prompt } else { // If no item is selected yet, select the highlighted item // Select the highlighted item, or the first item if none is highlighted e.preventDefault(); // Prevent form submission if inside a form if (currentFocus > -1) { if (items[currentFocus]) { - items[currentFocus].dispatchEvent(new Event('mousedown')); // Trigger the mousedown event + items[currentFocus].dispatchEvent(new Event('select_prompt')); // Trigger the select_prompt event } } else if (items.length > 0) { // If no item is highlighted, select the first item - items[0].dispatchEvent(new Event('mousedown')); + items[0].dispatchEvent(new Event('select_prompt')); } } } From 1f53f2773600bf0b493386f9c9359c137a6db3b4 Mon Sep 17 00:00:00 2001 From: mic Date: Sun, 22 Sep 2024 23:12:55 +0200 Subject: [PATCH 046/119] release notes updated --- CHANGELOG.md | 1 + options/mzta-release-notes.html | 1 + 2 files changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b42d5639..c7a29c98 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@
  • [OpenAI Comp API] Added a new integration method to use a local LLM via an API compatible with OpenAI's API specifications [#126].
  • Custom Prompts storage space incremented to 5MB, using
    storage.local
    . Added also the total occupied space at the bottom of the Custom Prompts page [#129].
  • [ChatGPT Web] Updated the information in the option page.
  • +
  • A new dynamic menu for selecting prompts has been added. In addition to clicking the ThunderAI button, you can now use the CTRL+ALT+A keyboard shortcut [#130].
  • ...
  • Version 2.1.4 - 11/09/2024

    diff --git a/options/mzta-release-notes.html b/options/mzta-release-notes.html index 1e7d9673..c6237a44 100644 --- a/options/mzta-release-notes.html +++ b/options/mzta-release-notes.html @@ -13,6 +13,7 @@
  • [OpenAI Comp API] Added a new integration method to use a local LLM via an API compatible with OpenAI's API specifications [#126].
  • Custom Prompts storage space incremented to 5MB, using
    storage.local
    . Added also the total occupied space at the bottom of the Custom Prompts page [#129].
  • [ChatGPT Web] Updated the information in the option page.
  • +
  • A new dynamic menu for selecting prompts has been added. In addition to clicking the ThunderAI button, you can now use the CTRL+ALT+A keyboard shortcut [#130].
  • ...
  • Version 2.1.4 - 11/09/2024

    From b942b2bf852df8783fa676bf4ea228845b453c76 Mon Sep 17 00:00:00 2001 From: mic Date: Sun, 22 Sep 2024 23:27:20 +0200 Subject: [PATCH 047/119] dynamic_menu_force_enter option added. see #130 --- _locales/en/messages.json | 8 ++++++++ options/mzta-options-default.js | 1 + options/mzta-options.html | 11 +++++++++++ 3 files changed, 20 insertions(+) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index afdba6c7..4e3f3763 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -554,5 +554,13 @@ "SearchPrompt": { "message": "Search a prompt", "description": "" + }, + "prefs_OptionText_dynamic_menu_force_enter": { + "message": "Menu: immediate prompt send", + "description": "" + }, + "prefs_OptionText_dynamic_menu_force_enter_info": { + "message": "If checked, using the keyboard shortcut CTRL+ALT+A will automatically send the hightlighted prompt from the menu. Otherwise, the prompt name will be displayed to the user, requiring another press of the Enter key to send it.", + "description": "" } } \ No newline at end of file diff --git a/options/mzta-options-default.js b/options/mzta-options-default.js index 0632dabf..66a10d57 100644 --- a/options/mzta-options-default.js +++ b/options/mzta-options-default.js @@ -29,4 +29,5 @@ export const prefs_default = { openai_comp_host: '', // For OpenAI Compatible API as LM-Studio openai_comp_model: '', openai_comp_chat_name: 'OpenAI Comp', + dynamic_menu_force_enter: false, } \ No newline at end of file diff --git a/options/mzta-options.html b/options/mzta-options.html index 9b9e9f4f..d76f9b84 100644 --- a/options/mzta-options.html +++ b/options/mzta-options.html @@ -59,6 +59,17 @@ + + + + + +