diff --git a/_locales/en/messages.json b/_locales/en/messages.json new file mode 100644 index 00000000..57dbdf4c --- /dev/null +++ b/_locales/en/messages.json @@ -0,0 +1,111 @@ +{ + "extensionDescription": { + "message": "Use ChatGPT to enhance you emails!", + "description": "Description of the extension." + }, + + "menu_title": { + "message": "AI", + "description": "" + }, + + "prompt_lang": { + "message": "Replay in ", + "description": "" + }, + + "prompt_translate_lang": { + "message": "english.", + "description": "" + }, + + "prompt_reply": { + "message": "Reply to this", + "description": "" + }, + + "prompt_rewrite_polite": { + "message": "Rewrite polite", + "description": "" + }, + + "prompt_rewrite_formal": { + "message": "Rewrite formal", + "description": "" + }, + + "prompt_classify": { + "message": "Classify", + "description": "" + }, + + "prompt_summarize_this": { + "message": "Summarize this", + "description": "" + }, + + "prompt_translate_this": { + "message": "Translate this", + "description": "" + }, + + "prompt_selection_needed": { + "message": "To proceed, you need to select some text!", + "description": "" + }, + + "chatgpt_win_working": { + "message": "Work in progress...", + "description": "" + }, + + "chatgpt_win_job_completed": { + "message": "Completed!", + "description": "" + }, + + "chatgpt_win_get_answer": { + "message": "Use last answer", + "description": "" + }, + + "chatgpt_win_close": { + "message": "Close", + "description": "" + }, + + "prefsInfoTitle": { + "message": "Important Information", + "description": "" + }, + + "prefsInfoDesc_1": { + "message": "It's not always possibile to get the right file type from the email received by Sharepoint or OneDrive.", + "description": "" + }, + + "prefsInfoDesc_2": { + "message": "If this extension can't understand the file type, it will show four buttons: one to use Word, one to use Excel, one to use PowerPoint and one to open the file in the browser.", + "description": "" + }, + + "prefsInfoDesc_3": { + "message": "The option to force to use Microsoft Edge is for a scenario where you do not use Edge as the default browser, but is the browser used with your Business account.", + "description": "" + }, + + "prefsDonation_1": { + "message": "Do you like this addon?", + "description": "" + }, + + "prefsDonation_2": { + "message": "Consider to make a donation!", + "description": "" + }, + + "backToOptionsText": { + "message": "Options", + "description": "" + } +} diff --git a/_locales/it/messages.json b/_locales/it/messages.json new file mode 100644 index 00000000..d18de435 --- /dev/null +++ b/_locales/it/messages.json @@ -0,0 +1,111 @@ +{ + "extensionDescription": { + "message": "Apri un condiviso di un file di SharePoint o OneDrive direttamente con l'applicazione corretta, invece che il browser.", + "description": "Descrizione dell'estensione." + }, + + "menu_title": { + "message": "IA", + "description": "" + }, + + "prompt_lang": { + "message": "Rispondi in ", + "description": "" + }, + + "prompt_translate_lang": { + "message": "italiano.", + "description": "" + }, + + "prompt_reply": { + "message": "Rispondi", + "description": "" + }, + + "prompt_rewrite_polite": { + "message": "Riscrivi cortese", + "description": "" + }, + + "prompt_rewrite_formal": { + "message": "Riscrivi formale", + "description": "" + }, + + "prompt_classify": { + "message": "Classifica", + "description": "" + }, + + "prompt_summarize_this": { + "message": "Riassumi", + "description": "" + }, + + "prompt_translate_this": { + "message": "Traduci", + "description": "" + }, + + "prompt_selection_needed": { + "message": "Per procedere è necessario che selezioni del testo!", + "description": "" + }, + + "chatgpt_win_working": { + "message": "Elaborazione in corso...", + "description": "" + }, + + "chatgpt_win_job_completed": { + "message": "Completato!", + "description": "" + }, + + "chatgpt_win_get_answer": { + "message": "Usa l'ultima risposta", + "description": "" + }, + + "chatgpt_win_close": { + "message": "Chiudi", + "description": "" + }, + + "prefsInfoTitle": { + "message": "Informazioni Importanti", + "description": "" + }, + + "prefsInfoDesc_1": { + "message": "Non è sempre possibile capire il tupo di file dalla mail ricevuta da SharePoint o OneDrive.", + "description": "" + }, + + "prefsInfoDesc_2": { + "message": "Se questa estensione non riesce a riconoscere il tipo del file, mostrerà quattro pulsanti: uno per usare Word, uno per Excel, uno per PowerPoint e uno per aprire il link nel browser.", + "description": "" + }, + + "prefsInfoDesc_3": { + "message": "L'opzione di forzare l'apertura in Microsoft Edge è per lo scenario in cui non stai usando Edge come browser predefinito, ma è il browser con il tuo account aziendale.", + "description": "" + }, + + "prefsDonation_1": { + "message": "Ti piace questo componente aggiuntivo?", + "description": "" + }, + + "prefsDonation_2": { + "message": "Considera di fare una donazione!", + "description": "" + }, + + "backToOptionsText": { + "message": "Opzioni", + "description": "" + } +} diff --git a/images/icon-16px.png b/images/icon-16px.png new file mode 100644 index 00000000..430ae54c Binary files /dev/null and b/images/icon-16px.png differ diff --git a/images/icon-32px.png b/images/icon-32px.png new file mode 100644 index 00000000..31d486e7 Binary files /dev/null and b/images/icon-32px.png differ diff --git a/images/icon.png b/images/icon.png new file mode 100644 index 00000000..c9e85fcd Binary files /dev/null and b/images/icon.png differ diff --git a/js/mzta-chatgpt.js b/js/mzta-chatgpt.js new file mode 100644 index 00000000..b535e2e2 --- /dev/null +++ b/js/mzta-chatgpt.js @@ -0,0 +1,156 @@ +// Original methods derived from https://github.com/KudoAI/chatgpt.js/blob/7eb8463cd61143fa9e1d5a8ec3c14d3c1b286e54/chatgpt.js +// Using a full string to inject it in the chatgpt page to avoid any security error + +export const mzta_script = ` +async function chatgpt_sendMsg(msg, method ='') { + const textArea = document.querySelector('form textarea'), + sendButton = document.querySelector('form button[class*="bottom"]'); + textArea.value = msg; + textArea.dispatchEvent(new Event('input', { bubbles: true })); // enable send button + const delaySend = setInterval(() => { + if (!sendButton?.hasAttribute('disabled')) { // send msg + method.toLowerCase() == 'click' ? sendButton.click() + : textArea.dispatchEvent(new KeyboardEvent('keydown', { keyCode: 13, bubbles: true })); + clearInterval(delaySend); + } + }, 25); +} + +async function chatgpt_isIdle() { + return new Promise(resolve => { + const intervalId = setInterval(() => { + if (chatgpt_getRegenerateButton()) { + clearInterval(intervalId); resolve(true); +}}, 100);});} + +function chatgpt_getRegenerateButton() { + for (const mainSVG of document.querySelectorAll('main svg')) { + if (mainSVG.querySelector('path[d*="M4.5 2.5C5.05228"]')) // regen icon found + return mainSVG.parentNode.parentNode; + } +} + +async function chatgpt_getFromDOM(pos) { + const responseDivs = document.querySelectorAll('div[data-testid*="conversation-turn"]:nth-child(odd)'), + strPos = pos.toString().toLowerCase(); + let response = ''; + if (responseDivs.length) { + if (/last|final/.test(strPos)) // get last response + response = responseDivs[responseDivs.length - 1].textContent; + else { // get nth response + const nthOfResponse = ( + + // Calculate base number + Number.isInteger(pos) ? pos : // do nothing for integers + /^\d+/.test(strPos) ? /^\d+/.exec(strPos)[0] : // extract first digits for strings w/ them + ( // convert words to integers for digitless strings + /^(?:1|one|fir)(?:st)?$/.test(strPos) ? 1 + : /^(?:2|tw(?:o|en|el(?:ve|f))|seco)(?:nd|t[yi])?(?:e?th)?$/.test(strPos) ? 2 + : /^(?:3|th(?:ree|ir?))(?:rd|teen|t[yi])?(?:e?th)?$/.test(strPos) ? 3 + : /^(?:4|fou?r)(?:teen|t[yi])?(?:e?th)?$/.test(strPos) ? 4 + : /^(?:5|fi(?:ve|f))(?:teen|t[yi])?(?:e?th)?$/.test(strPos) ? 5 + : /^(?:6|six)(?:teen|t[yi])?(?:e?th)?$/.test(strPos) ? 6 + : /^(?:7|seven)(?:teen|t[yi])?(?:e?th)?$/.test(strPos) ? 7 + : /^(?:8|eight?)(?:teen|t[yi])?(?:e?th)?$/.test(strPos) ? 8 + : /^(?:9|nine?)(?:teen|t[yi])?(?:e?th)?$/.test(strPos) ? 9 + : /^(?:10|ten)(?:th)?$/.test(strPos) ? 10 : 1 ) + + // Transform base number if suffixed + * ( /(ty|ieth)$/.test(strPos) ? 10 : 1 ) // x 10 if -ty/ieth + + ( /teen(th)?$/.test(strPos) ? 10 : 0 ) // + 10 if -teen/teenth + + ); + response = responseDivs[nthOfResponse - 1].textContent; + } + response = response.replace(/^ChatGPTChatGPT/, ''); // strip sender name + } + return response; +} + +function chatpgt_scrollToBottom () { + try { document.querySelector('button[class*="cursor"][class*="bottom"]').click(); } + catch (err) { console.error('', err); } +} + +function addCustomDiv(prompt_action,tabId) { + // Create