-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.js
44 lines (37 loc) · 1.64 KB
/
popup.js
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
document.addEventListener('DOMContentLoaded', function() {
const filterToggle = document.getElementById('filterToggle');
const statusText = document.getElementById('statusText');
const blockedCount = document.getElementById('blockedCount');
const totalBlocked = document.getElementById('totalBlocked');
const settingsBtn = document.getElementById('settingsBtn');
// Load saved state
function loadState() {
chrome.storage.sync.get(['filterEnabled', 'blockedToday', 'totalBlocked'], function(data) {
filterToggle.checked = data.filterEnabled !== undefined ? data.filterEnabled : true;
statusText.textContent = filterToggle.checked ? 'Filter is ON' : 'Filter is OFF';
blockedCount.textContent = data.blockedToday || 0;
totalBlocked.textContent = data.totalBlocked || 0;
console.log('Popup state loaded:', data);
});
}
loadState();
// Toggle filter
filterToggle.addEventListener('change', function() {
const isEnabled = filterToggle.checked;
statusText.textContent = isEnabled ? 'Filter is ON' : 'Filter is OFF';
chrome.storage.sync.set({filterEnabled: isEnabled});
// Notify background script
chrome.runtime.sendMessage({action: "toggleFilter", enabled: isEnabled});
console.log('Filter toggled:', isEnabled);
});
// Open settings page
settingsBtn.addEventListener('click', function() {
chrome.runtime.openOptionsPage();
});
// Update stats
function updateStats() {
loadState();
}
// Update stats every 5 seconds
setInterval(updateStats, 5000);
});