File size: 1,882 Bytes
5a72624
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Background service worker
console.log('Phishing Detector: Background service worker started');

// Initialize storage and context menu
chrome.runtime.onInstalled.addListener(() => {
  chrome.storage.local.set({
    sitesChecked: 0,
    threatsBlocked: 0,
    autoCheck: false
  });
  
  // Create context menu (check if API is available)
  if (chrome.contextMenus) {
    chrome.contextMenus.create({
      id: 'checkLink',
      title: 'Check this link for phishing',
      contexts: ['link']
    });
  }
  
  console.log('Extension installed successfully');
});

// Listen for messages from content scripts and popup
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
  if (request.action === 'checkPage') {
    // Handle page check request
    console.log('Checking page:', request.url);
    sendResponse({ status: 'checking' });
  }
  
  return true;
});

// Show notification
function showNotification(title, message, isWarning = false) {
  chrome.notifications.create({
    type: 'basic',
    iconUrl: isWarning ? 'icons/icon128.png' : 'icons/icon128.png',
    title: title,
    message: message,
    priority: isWarning ? 2 : 1
  });
}

// Listen for tab updates (optional - for auto-checking)
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
  if (changeInfo.status === 'complete' && tab.url) {
    chrome.storage.local.get(['autoCheck'], (result) => {
      if (result.autoCheck) {
        // Auto-check the page
        console.log('Auto-checking:', tab.url);
      }
    });
  }
});

// Context menu click handler
if (chrome.contextMenus) {
  chrome.contextMenus.onClicked.addListener((info, tab) => {
    if (info.menuItemId === 'checkLink') {
      console.log('Checking link:', info.linkUrl);
      showNotification('Phishing Check', 'Checking link...', false);
      // You can implement link checking logic here
    }
  });
}