chrome.runtime.onMessage.addListener((message, sender, sendResponse) => { if (message.type === "phishing-detected") { const emails = message.emails; let notificationTitle = "You are safe!"; let notificationMessage = "No phishing emails detected."; const phishingEmails = emails.filter((email) => email.suspicious); if (phishingEmails.length > 0) { notificationTitle = "You are in danger!"; notificationMessage = `Detected ${phishingEmails.length} suspicious emails.`; chrome.windows.create( { url: "notification.html", type: "popup", width: 400, height: 400, }, function (window) { chrome.storage.local.set({ notificationTitle: notificationTitle, notificationMessage: notificationMessage, phishingEmails: phishingEmails, }); } ); } else { chrome.windows.create( { url: "notification.html", type: "popup", width: 300, height: 200, }, function (window) { chrome.storage.local.set({ notificationTitle: notificationTitle, notificationMessage: notificationMessage, phishingEmails: [], }); } ); } } else if (message.type === "mark-safe") { chrome.storage.local.get( ["email", "password", "emailService"], function (result) { const emailService = result.emailService; const emailId = message.emailId; fetch(`http://localhost:5000/mark_safe/${emailId}`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ username: result.email, email: emailService, }), }) .then((response) => response.json()) .then((data) => console.log(data)) .catch((error) => console.error("Error:", error)); } ); } else if (message.type === "move-trash") { chrome.storage.local.get( ["email", "password", "emailService"], function (result) { const emailService = result.emailService; const emailId = message.emailId; if (emailService === "outlook") { fetch(`http://localhost:5000/delete-email`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ email_id: emailId, username: result.email, password: result.password, }), }) .then((response) => response.json()) .then((data) => console.log(data)) .catch((error) => console.error("Error:", error)); } else { fetch(`http://localhost:5000/move_trash/${emailId}`, { method: "POST", headers: { "Content-Type": "application/json", }, }) .then((response) => response.json()) .then((data) => console.log(data)) .catch((error) => console.error("Error:", error)); } } ); } });