diff --git a/Email Manager/background.js b/Email Manager/background.js new file mode 100644 index 00000000..f3dd0956 --- /dev/null +++ b/Email Manager/background.js @@ -0,0 +1,25 @@ +chrome.runtime.onInstalled.addListener(() => { + chrome.storage.sync.get('emails', (data) => { + if (!data.emails) { + chrome.storage.sync.set({ emails: [] }); + } + }); +}); + +chrome.runtime.onMessage.addListener((request, sender, sendResponse) => { + if (request.action === "storeEmail") { + chrome.storage.sync.get("emails", (data) => { + const emails = data.emails || []; + emails.push(request.email); + chrome.storage.sync.set({ emails: emails }, () => { + if (chrome.runtime.lastError) { + console.error('Error storing email:', chrome.runtime.lastError); + sendResponse({ success: false }); + } else { + sendResponse({ success: true }); + } + }); + }); + return true; // Indicates that the response is asynchronous + } +}); \ No newline at end of file diff --git a/Email Manager/content.js b/Email Manager/content.js new file mode 100644 index 00000000..c6fe0e51 --- /dev/null +++ b/Email Manager/content.js @@ -0,0 +1,71 @@ +(function() { + if (window.location.protocol === 'chrome:') { + console.log('Extension does not run on chrome:// pages'); + return; + } + + function storeEmail() { + // Get the email subject + const subjectElement = document.querySelector('input[name="subjectbox"]'); + const subject = subjectElement ? subjectElement.value : ''; + + // Get the email body + const bodyElement = document.querySelector('div[role="textbox"]'); + const body = bodyElement ? bodyElement.innerText : ''; + + // Get the recipient(s) + const recipientElements = document.querySelectorAll('div[aria-label="To"] span[email]'); + const recipients = Array.from(recipientElements).map(el => el.getAttribute('email')).join(', '); + + // Create the email object + const email = { + subject: subject, + body: body, + recipients: recipients, + date: new Date().toISOString() + }; + + // Send the email data to the background script + chrome.runtime.sendMessage({action: "storeEmail", email: email}, (response) => { + if (chrome.runtime.lastError) { + console.error('Error storing email:', chrome.runtime.lastError); + } else if (response && response.success) { + console.log('Email stored successfully'); + alert('Email stored successfully!'); + } + }); + } + + function addStoreButton() { + const composeBox = document.querySelector('.compose-header'); + if (composeBox && !composeBox.querySelector('#store-email-btn')) { + const storeButton = document.createElement('button'); + storeButton.id = 'store-email-btn'; + storeButton.textContent = 'Store Email'; + storeButton.style.cssText = ` + background-color: #1a73e8; + color: white; + border: none; + padding: 8px 16px; + margin-left: 8px; + border-radius: 4px; + cursor: pointer; + font-size: 14px; + `; + storeButton.onclick = storeEmail; + composeBox.appendChild(storeButton); + } + } + + const observer = new MutationObserver((mutations) => { + mutations.forEach((mutation) => { + if (mutation.addedNodes.length) { + addStoreButton(); + } + }); + }); + + observer.observe(document.body, { childList: true, subtree: true }); + + addStoreButton(); +})(); \ No newline at end of file diff --git a/Email Manager/manifest.json b/Email Manager/manifest.json new file mode 100644 index 00000000..38a6ae77 --- /dev/null +++ b/Email Manager/manifest.json @@ -0,0 +1,20 @@ +{ + "manifest_version": 2, + "name": "Email Manager", + "version": "1.0", + "description": "Store and manage important emails", + "permissions": ["storage", "activeTab", "tabs"], + "background": { + "scripts": ["background.js"], + "persistent": false + }, + "content_scripts": [ + { + "matches": ["*://mail.google.com/*"], + "js": ["content.js"] + } + ], + "browser_action": { + "default_popup": "popup.html" + } +} \ No newline at end of file diff --git a/Email Manager/popup.html b/Email Manager/popup.html new file mode 100644 index 00000000..4e6f3190 --- /dev/null +++ b/Email Manager/popup.html @@ -0,0 +1,100 @@ + + +
+ + +Error fetching emails. Please try again.
'; + return; + } + + const emails = data.emails || []; + if (emails.length === 0) { + emailList.innerHTML = 'No emails stored yet.
'; + return; + } + emails.forEach((email, index) => { + const emailDiv = document.createElement('div'); + emailDiv.className = 'email-item'; + emailDiv.innerHTML = ` +