Skip to content

Commit cf76bf0

Browse files
feat: Add PWA and Chrome extension to scam detection AI
1 parent ca92faf commit cf76bf0

File tree

9 files changed

+155
-0
lines changed

9 files changed

+155
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
chrome.runtime.onInstalled.addListener(() => {
2+
chrome.contextMenus.create({
3+
id: "analyzeText",
4+
title: "Analyze for Scams",
5+
contexts: ["selection"]
6+
});
7+
});
8+
9+
chrome.contextMenus.onClicked.addListener((info, tab) => {
10+
if (info.menuItemId === "analyzeText") {
11+
fetch('http://localhost:5000/analyze', {
12+
method: 'POST',
13+
headers: {
14+
'Content-Type': 'application/x-www-form-urlencoded',
15+
},
16+
body: `message_text=${encodeURIComponent(info.selectionText)}`
17+
})
18+
.then(response => response.text())
19+
.then(data => {
20+
chrome.storage.local.set({ analysisResult: data });
21+
})
22+
.catch(error => {
23+
console.error('Error:', error);
24+
chrome.storage.local.set({ analysisResult: 'Error analyzing text.' });
25+
});
26+
}
27+
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"manifest_version": 3,
3+
"name": "Scam Detection AI",
4+
"version": "1.0",
5+
"description": "Analyzes selected text for scams.",
6+
"permissions": [
7+
"activeTab",
8+
"contextMenus"
9+
],
10+
"background": {
11+
"service_worker": "background.js"
12+
},
13+
"action": {
14+
"default_popup": "popup.html"
15+
}
16+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Scam Detection AI</title>
5+
<style>
6+
body { width: 300px; font-family: sans-serif; }
7+
textarea { width: 100%; height: 100px; }
8+
</style>
9+
</head>
10+
<body>
11+
<h1>Scam Detection AI</h1>
12+
<textarea id="textToAnalyze" placeholder="Text to analyze..."></textarea>
13+
<button id="analyzeButton">Analyze</button>
14+
<div id="result"></div>
15+
<script src="popup.js"></script>
16+
</body>
17+
</html>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
document.addEventListener('DOMContentLoaded', () => {
2+
chrome.storage.local.get(['analysisResult'], (result) => {
3+
if (result.analysisResult) {
4+
document.getElementById('result').innerHTML = result.analysisResult;
5+
chrome.storage.local.remove(['analysisResult']);
6+
}
7+
});
8+
});
9+
10+
document.getElementById('analyzeButton').addEventListener('click', () => {
11+
const text = document.getElementById('textToAnalyze').value;
12+
fetch('http://localhost:5000/analyze', {
13+
method: 'POST',
14+
headers: {
15+
'Content-Type': 'application/x-www-form-urlencoded',
16+
},
17+
body: `message_text=${encodeURIComponent(text)}`
18+
})
19+
.then(response => response.text())
20+
.then(data => {
21+
document.getElementById('result').innerHTML = data;
22+
})
23+
.catch(error => {
24+
console.error('Error:', error);
25+
document.getElementById('result').innerText = 'Error analyzing text.';
26+
});
27+
});
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// This is a placeholder for your PWA's javascript.
2+
console.log("Scam Detection AI PWA is running.");
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "Scam Detection AI",
3+
"short_name": "Scam AI",
4+
"start_url": "/",
5+
"display": "standalone",
6+
"background_color": "#ffffff",
7+
"theme_color": "#000000",
8+
"icons": [
9+
{
10+
"src": "images/icon-192.png",
11+
"sizes": "192x192",
12+
"type": "image/png"
13+
},
14+
{
15+
"src": "images/icon-512.png",
16+
"sizes": "512x512",
17+
"type": "image/png"
18+
}
19+
]
20+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/* This is a placeholder for your PWA's styles. */
2+
body {
3+
background-color: #f0f0f0;
4+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
const CACHE_NAME = 'scam-detection-ai-cache-v1';
2+
const urlsToCache = [
3+
'/',
4+
'/static/styles.css', // Assuming you'll have a stylesheet
5+
'/static/app.js' // Assuming you'll have some javascript
6+
];
7+
8+
self.addEventListener('install', event => {
9+
event.waitUntil(
10+
caches.open(CACHE_NAME)
11+
.then(cache => {
12+
console.log('Opened cache');
13+
return cache.addAll(urlsToCache);
14+
})
15+
);
16+
});
17+
18+
self.addEventListener('fetch', event => {
19+
event.respondWith(
20+
caches.match(event.request)
21+
.then(response => {
22+
if (response) {
23+
return response;
24+
}
25+
return fetch(event.request);
26+
}
27+
)
28+
);
29+
});

collections/scam-detection-ai/templates/index.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,19 @@
44
<meta charset="UTF-8">
55
<meta name="viewport" content="width=device-width, initial-scale=1.0">
66
<title>Scam Detection AI</title>
7+
<link rel="stylesheet" href="/static/styles.css">
8+
<link rel="manifest" href="/static/manifest.json">
9+
<script>
10+
if ('serviceWorker' in navigator) {
11+
window.addEventListener('load', () => {
12+
navigator.serviceWorker.register('/static/sw.js').then(registration => {
13+
console.log('ServiceWorker registration successful with scope: ', registration.scope);
14+
}, err => {
15+
console.log('ServiceWorker registration failed: ', err);
16+
});
17+
});
18+
}
19+
</script>
720
<style>
821
body { font-family: sans-serif; margin: 2em; }
922
.container { max-width: 800px; margin: auto; }

0 commit comments

Comments
 (0)