├── background.js ├── content.js ├── icon.png ├── manifest.json ├── popup.html └── popup.js /background.js: -------------------------------------------------------------------------------- 1 | // Listen for messages from the content script 2 | chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) { 3 | if (request.type === "processText") { 4 | // Check if the text contains the word "hello" 5 | if (request.text.includes("hello")) { 6 | // Modify the text to say "hello world" 7 | var modifiedText = request.text.replace("hello", "hello world"); 8 | 9 | // Send the modified text back to the content script 10 | sendResponse({ 11 | text: modifiedText, 12 | }); 13 | } 14 | } 15 | }); 16 | 17 | chrome.commands.onCommand.addListener(function (command) { 18 | if (command === "suggest-change") { 19 | chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) { 20 | chrome.tabs.sendMessage(tabs[0].id, { text: "hello" }); 21 | }); 22 | } 23 | }); 24 | -------------------------------------------------------------------------------- /content.js: -------------------------------------------------------------------------------- 1 | // Replace "hello" with "zork" in the body of the draft message 2 | function replaceHelloWithZork() { 3 | // Retrieve the draft message 4 | gapi.client.gmail.users.drafts 5 | .get({ 6 | userId: "me", 7 | id: draftId, 8 | }) 9 | .then((response) => { 10 | const draftMessage = response.result; 11 | // Modify the body of the draft message 12 | draftMessage.body = draftMessage.body.replace("hello", "zork"); 13 | // Update the draft message with the modified body 14 | gapi.client.gmail.users.drafts 15 | .update({ 16 | userId: "me", 17 | id: draftId, 18 | resource: draftMessage, 19 | }) 20 | .then((response) => { 21 | console.log("Draft message updated"); 22 | }); 23 | }); 24 | } 25 | 26 | // Set an interval to check for the presence of the textarea element used for the body of the email in Gmail 27 | setInterval(() => { 28 | // Check if the textarea element is present 29 | if (document.querySelector('[aria-label="Message Body"]')) { 30 | // If the textarea element is present, call the replaceHelloWithZork function 31 | replaceHelloWithZork(); 32 | } 33 | }, 1000); // Check for the presence of the textarea element every 1000 milliseconds (1 second) 34 | -------------------------------------------------------------------------------- /icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrentConley/emailWriter/1231992a2d7bf218408884d88faf431b04bf42de/icon.png -------------------------------------------------------------------------------- /manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "manifest_version": 3, 3 | "name": "Text Editing Extension", 4 | "description": "An extension that allows you to read and write text on a page", 5 | "version": "1.0", 6 | "permissions": ["contentSettings", "activeTab", "declarativeContent", "tabs"], 7 | "background": { 8 | "service_worker": "background.js" 9 | }, 10 | "content_scripts": [ 11 | { 12 | "matches": ["https://mail.google.com/*"], 13 | "js": ["content.js"] 14 | } 15 | ], 16 | "commands": { 17 | "suggest-change": { 18 | "suggested_key": { 19 | "default": "Alt+Shift+C" 20 | }, 21 | "description": "Suggest a change" 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /popup.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 |Click the button below to send a message to the content script:
9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /popup.js: -------------------------------------------------------------------------------- 1 | // Get the 'hello-button' element and add a click listener 2 | document.getElementById("hello-button").addEventListener("click", function () { 3 | // Send a message to the content script 4 | chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) { 5 | chrome.tabs.sendMessage(tabs[0].id, { text: "hello" }); 6 | }); 7 | }); 8 | --------------------------------------------------------------------------------