I made it in the beginning for gmail, but now I want it to work for other websites like google slides or notes. But, the extension isn’t picking up for scams on any other website besides email? I tried everything, and asked ChatGPT, but nothing worked.
**The extension works when the user highlights the text and clicks the extension in the toolbar, but only on gmail and not any other urls.
I tried managing the extension, but it is set to every URL. Even the JSON is set to “ALL URLS”. Yet, even after saving and reloading, the extension only works on GMAIL.
//manifest.json
{
"manifest_version": 2,
"version": "1.0",
"name": "Email Scam Detector",
"permissions": ["activeTab", "contextMenus"],
"background": {
"scripts": ["background.js"],
"persistent": false
},
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["main.js"]
}
],
"browser_action": {
"default_popup": "popup.html"
}
}
//main.js
document.addEventListener('mouseup', function() {
let selectedText = window.getSelection().toString().trim();
if (selectedText.length > 0) {
chrome.runtime.sendMessage({text: selectedText}, function(response) {
console.log(response);
});
}
});
//background.js
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
const scamKeywords = [
"urgent", "immediately", "bank account", "login", "password", "verify",
"click here", "suspended", "lottery", "prize", "winner", "inheritance",
"funds", "Nigerian prince", "transfer", "limited time", "offer", "risk-free", "validate",
"Customer", "Friend", "Sir", "Ma'am", "Trusted customer"
];
let keywordCount = scamKeywords.reduce((count, keyword) => {
if (request.text.toLowerCase().includes(keyword)) {
count += 1;
}
return count;
}, 0);
let isScam = keywordCount >= 2;
sendResponse({isScam: isScam});
});
//popup.html
<!DOCTYPE html>
<html>
<head>
<title>Email Scam Detector</title>
<style>
body {
font-family: Arial, sans-serif;
width: 250px;
padding: 10px;
background-color: #f9f9f9;
}
h1 {
font-size: 16px;
margin-bottom: 10px;
text-align: center;
}
.result {
margin-top: 20px;
padding: 10px;
border-radius: 5px;
text-align: center;
}
.safe {
background-color: #d4edda;
color: #155724;
}
.scam {
background-color: #f8d7da;
color: #721c24;
}
</style>
</head>
<body>
<h1>Email Scam Detector</h1>
<div id="result" class="result">Highlight text to analyze</div>
<script src="popup.js"></script>
</body>
</html>
//popup.js
chrome.tabs.executeScript({
code: "window.getSelection().toString();"
}, function(selection) {
let selectedText = selection[0].trim();
if (selectedText.length > 0) {
chrome.runtime.sendMessage({text: selectedText}, function(response) {
let resultDiv = document.getElementById('result');
if (response.isScam) {
resultDiv.innerHTML = "⚠️ This text might be a scam!";
resultDiv.className = 'result scam';
} else {
resultDiv.innerHTML = "✅ This text seems safe.";
resultDiv.className = 'result safe';
}
});
}
});