├── .gitignore ├── .github └── FUNDING.yml ├── icon.png ├── icon16.png ├── icon48.png ├── icon128.png ├── styles.css ├── manifest.json ├── LICENSE ├── popup.js ├── popup.html ├── contentScript.js ├── CODE_OF_CONDUCT.md └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: hummusonrails 2 | -------------------------------------------------------------------------------- /icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hummusonrails/chatgpt-gmail-suggestions-chrome-extension/HEAD/icon.png -------------------------------------------------------------------------------- /icon16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hummusonrails/chatgpt-gmail-suggestions-chrome-extension/HEAD/icon16.png -------------------------------------------------------------------------------- /icon48.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hummusonrails/chatgpt-gmail-suggestions-chrome-extension/HEAD/icon48.png -------------------------------------------------------------------------------- /icon128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hummusonrails/chatgpt-gmail-suggestions-chrome-extension/HEAD/icon128.png -------------------------------------------------------------------------------- /styles.css: -------------------------------------------------------------------------------- 1 | body { 2 | font-family: Arial, sans-serif; 3 | padding: 15px; 4 | } 5 | 6 | .settings-section { 7 | background-color: #f2f2f2; 8 | padding: 10px; 9 | margin-bottom: 10px; 10 | } 11 | 12 | .review-button { 13 | background-color: #4CAF50; 14 | color: white; 15 | border: none; 16 | padding: 10px 15px; 17 | cursor: pointer; 18 | margin-top: 10px; 19 | font-weight: bold; 20 | } 21 | 22 | .review-button:hover { 23 | background-color: #3f9a40; 24 | } 25 | -------------------------------------------------------------------------------- /manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "manifest_version": 3, 3 | "name": "ChatGPT Email Reviewer", 4 | "author": "Ben Greenberg", 5 | "homepage_url": "https://github.com/hummusonrails/chatgpt-gmail-suggestions-chrome-extension", 6 | "version": "1.1", 7 | "description": "Review and improve email style in Gmail drafts with ChatGPT", 8 | "permissions": [ 9 | "activeTab", 10 | "storage" 11 | ], 12 | "host_permissions": [ 13 | "https://*.google.com/*" 14 | ], 15 | "action": { 16 | "default_icon": { 17 | "16": "icon16.png", 18 | "48": "icon48.png", 19 | "128": "icon128.png" 20 | }, 21 | "default_popup": "popup.html", 22 | "default_title": "ChatGPT Email Reviewer" 23 | }, 24 | "content_scripts": [ 25 | { 26 | "matches": ["https://mail.google.com/*"], 27 | "js": ["contentScript.js"] 28 | } 29 | ], 30 | "icons": { 31 | "16": "icon16.png", 32 | "48": "icon48.png", 33 | "128": "icon128.png" 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Ben Greenberg 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /popup.js: -------------------------------------------------------------------------------- 1 | const apiKeyInput = document.getElementById('apiKeyInput'); 2 | const signatureDelimiterInput = document.getElementById('signatureDelimiter'); 3 | const editApiKeyButton = document.getElementById('editApiKeyButton'); 4 | const saveButton = document.getElementById('saveButton'); 5 | 6 | saveButton.addEventListener("click", () => { 7 | const apiKey = apiKeyInput.value; 8 | const signatureDelimiter = signatureDelimiterInput.value; 9 | chrome.storage.sync.set({ apiKey, signatureDelimiter }, () => { 10 | alert("API key and signature delimiter saved."); 11 | apiKeyInput.readOnly = true; 12 | apiKeyInput.type = 'password'; 13 | }); 14 | }); 15 | 16 | document.getElementById("reviewButton").addEventListener("click", () => { 17 | const selectedStyles = Array.from(document.querySelectorAll('input[name="style"]:checked')).map(input => input.value); 18 | 19 | chrome.tabs.query({ active: true, currentWindow: true }, tabs => { 20 | chrome.tabs.sendMessage(tabs[0].id, { action: "reviewEmail", styles: selectedStyles }); 21 | }); 22 | }); 23 | 24 | chrome.storage.sync.get(["apiKey", "signatureDelimiter"], result => { 25 | apiKeyInput.value = result.apiKey || ''; 26 | 27 | if (result.signatureDelimiter) { 28 | signatureDelimiterInput.value = result.signatureDelimiter; 29 | } 30 | }); 31 | 32 | editApiKeyButton.addEventListener('click', () => { 33 | apiKeyInput.readOnly = false; 34 | apiKeyInput.type = 'text'; 35 | apiKeyInput.focus(); 36 | }); 37 | -------------------------------------------------------------------------------- /popup.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 |

ChatGPT Email Reviewer

8 |
9 |

Enter your OpenAI API key:

10 | 11 | 12 |

Enter the delimiter for your signature:

13 | 14 | 15 |
16 |

Select a writing style:

17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 | 28 | 29 |

Support this work by sponsoring me on GitHub

30 | 31 | 32 | -------------------------------------------------------------------------------- /contentScript.js: -------------------------------------------------------------------------------- 1 | function getEmailBody(signatureDelimiter) { 2 | const selector = "div[aria-label='Message Body'], div[aria-label='Message text'], div.editable"; 3 | const element = document.querySelector(selector); 4 | if (element) { 5 | let emailText = element.innerHTML; 6 | if (signatureDelimiter && emailText.includes(signatureDelimiter)) { 7 | emailText = emailText.substring(0, emailText.indexOf(signatureDelimiter)).trim(); 8 | } 9 | return emailText; 10 | } 11 | 12 | return null; 13 | } 14 | 15 | 16 | async function sendToChatGPT(text, styles, apiKey, signatureDelimiter) { 17 | const response = await fetch('https://api.openai.com/v1/chat/completions', { 18 | method: 'POST', 19 | headers: { 20 | 'Content-Type': 'application/json', 21 | 'Authorization': `Bearer ${apiKey}` 22 | }, 23 | body: JSON.stringify({ 24 | messages: [{"role": "user", "content": `Review and provide suggestions for the following email draft combining the following styles or only a single style if only one is provided: ${styles.join(', ')}. Please return only the revised email text without suggesting a subject. Email draft: ${text}`}], 25 | model: "gpt-3.5-turbo", 26 | max_tokens: 150, 27 | n: 1, 28 | stop: null, 29 | temperature: 0.8 30 | }) 31 | }); 32 | 33 | const data = await response.json(); 34 | if (data.choices && data.choices.length > 0) { 35 | displaySuggestions(data.choices[0].message.content, signatureDelimiter); 36 | } else { 37 | console.log("No suggestions received"); 38 | } 39 | } 40 | 41 | function displaySuggestions(suggestions, signatureDelimiter) { 42 | const selector = "div[aria-label='Message Body'], div[aria-label='Message text'], div.editable"; 43 | const element = document.querySelector(selector); 44 | if (element) { 45 | let newText = suggestions.trim(); 46 | newText = newText.replace(/\n/g, '
'); 47 | if (signatureDelimiter) { 48 | const signatureIndex = element.innerHTML.indexOf(signatureDelimiter); 49 | if (signatureIndex !== -1) { 50 | const signature = element.innerHTML.substring(signatureIndex); 51 | newText = newText + '

' + signature; 52 | } 53 | } 54 | 55 | if (element.getAttribute('contenteditable') === 'true') { 56 | element.focus(); 57 | document.execCommand('selectAll', false, null); 58 | document.execCommand('insertHTML', false, newText); 59 | } else { 60 | element.innerHTML = newText; 61 | } 62 | } 63 | } 64 | 65 | 66 | chrome.runtime.onMessage.addListener((request, sender, sendResponse) => { 67 | if (request.action === "reviewEmail") { 68 | const selectedStyles = request.styles; 69 | 70 | if (request) { 71 | chrome.storage.sync.get(["apiKey", "signatureDelimiter"], result => { 72 | if (result.apiKey) { 73 | const emailBody = getEmailBody(result.signatureDelimiter); 74 | sendToChatGPT(emailBody, selectedStyles, result.apiKey, result.signatureDelimiter).then(() => { 75 | sendResponse({ success: true }); 76 | }).catch(() => { 77 | sendResponse({ success: false }); 78 | }); 79 | } else { 80 | alert("Please enter and save your OpenAI API key in the extension settings."); 81 | sendResponse({ success: false }); 82 | } 83 | }); 84 | } else { 85 | sendResponse({ success: false }); 86 | } 87 | 88 | return true; 89 | } 90 | }); 91 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation. 6 | 7 | ## Our Standards 8 | 9 | Examples of behavior that contributes to creating a positive environment include: 10 | 11 | - Using welcoming and inclusive language 12 | - Being respectful of differing viewpoints and experiences 13 | - Gracefully accepting constructive criticism 14 | - Focusing on what is best for the community 15 | - Showing empathy towards other community members 16 | 17 | Examples of unacceptable behavior by participants include: 18 | 19 | - The use of sexualized language or imagery and unwelcome sexual attention or advances 20 | - Trolling, insulting/derogatory comments, and personal or political attacks 21 | - Public or private harassment 22 | - Publishing others' private information, such as a physical or email address, without their explicit permission 23 | - Other conduct which could reasonably be considered inappropriate in a professional setting 24 | 25 | ## Our Responsibilities 26 | 27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. 28 | 29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. 30 | 31 | ## Scope 32 | 33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. 34 | 35 | ## Enforcement 36 | 37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at [INSERT EMAIL ADDRESS]. All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. 38 | 39 | Project contributors who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. 40 | 41 | ## Attribution 42 | 43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0, available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. 44 | 45 | [homepage]: https://www.contributor-covenant.org 46 | 47 | For answers to common questions about this code of conduct, see https://www.contributor-covenant.org/faq 48 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ChatGPT Email Reviewer 2 | 3 | [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT) 4 | [![Contributing](https://img.shields.io/badge/Contributing-Guidelines-blue)](CONTRIBUTING.md) 5 | [![Code of Conduct](https://img.shields.io/badge/Code%20of%20Conduct-Respectful-orange)](CODE_OF_CONDUCT.md) 6 | [![Visitors](https://visitor-badge.glitch.me/badge?page_id=hummusonrails.chatgpt-gmail-suggestions-chrome-extension)](https://github.com/hummusonrails/chatgpt-gmail-suggestions-chrome-extension) 7 | [![Made with Love](https://img.shields.io/badge/Made%20with-Love-ff69b4.svg)](https://shields.io/) 8 | 9 | This is a Chrome extension that integrates with Gmail to review email drafts using ChatGPT. The extension allows users to select different writing styles for their emails, such as friendly, business, authoritative, personal, casual, serious, and lighthearted. It then uses ChatGPT to analyze and provide suggestions for the email draft based on the chosen writing style. 10 | 11 | ## Installation 12 | To use this extension, you'll need to install it on your Google Chrome browser or any Chromium-based browser. Follow the steps below: 13 | 14 | Download or clone the project from GitHub: 15 | 16 | ```bash 17 | git clone https://github.com/hummusonrails/chatgpt-gmail-suggestions-chrome-extension 18 | ``` 19 | 20 | Open the Extensions page in Chrome by navigating to `chrome://extensions/`. 21 | 22 | Enable "Developer mode" in the top right corner of the Extensions page. 23 | 24 | Click the "Load unpacked" button and select the project directory that you cloned or downloaded. 25 | 26 | The extension is now installed and ready to use in your Gmail account. 27 | 28 | ### Configuration 29 | 30 | Before you can use the extension, you'll need to set up a few configuration variables: 31 | 32 | #### OpenAI API Key 33 | 34 | The extension uses the OpenAI API to analyze the email drafts and provide suggestions. To use the API, you'll need an API key from OpenAI. You can obtain an API key by [creating an account on the OpenAI website](https://beta.openai.com/signup/). 35 | 36 | To configure the API key, click the extension icon in your browser's toolbar and enter your OpenAI API key in the provided input field. After entering the API key, click the "Save Settings" button to save it for future use. 37 | 38 | #### Signature Delimiter 39 | 40 | If your email signature is automatically appended to your email drafts in Gmail, you can specify a delimiter to distinguish the signature from the main content of the email. The extension will use this delimiter to exclude the signature from the analysis. 41 | 42 | To configure the signature delimiter, click the extension icon in your browser's toolbar and enter the delimiter in the provided input field. Then click the "Save Settings" button. 43 | 44 | ## Usage 45 | 46 | To use the extension, compose a new email draft in Gmail. After writing the email draft, click the extension icon in your browser's toolbar. Select the desired writing style(s) for your email and click the "Review Email" button. 47 | 48 | The extension will analyze your email draft using ChatGPT and provide suggestions based on the chosen writing style. You can then choose to use the suggestions to improve your email draft. 49 | 50 | ## Code of Conduct 51 | 52 | Please note that this project is released with a [Contributor Code of Conduct](CODE_OF_CONDUCT.md). By participating in this project you agree to abide by its terms. 53 | 54 | ## License 55 | 56 | This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for more information. --------------------------------------------------------------------------------