-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
53 lines (45 loc) · 1.82 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
45
46
47
48
49
50
51
52
53
// Toggle Ad Blocker Logic
document.getElementById('toggle').addEventListener('change', function() {
const enabled = this.checked;
chrome.storage.sync.set({ adblockEnabled: enabled }, function() {
chrome.runtime.sendMessage({ type: 'toggleAdBlocker', enabled: enabled });
});
});
// Restore toggle state on load
chrome.storage.sync.get('adblockEnabled', function(data) {
document.getElementById('toggle').checked = data.adblockEnabled || false;
});
// Clear Cookies Logic
document.getElementById('clearCookies').addEventListener('click', function() {
// Get the current active tab
chrome.tabs.query({ active: true, currentWindow: true }, function(tabs) {
let url = new URL(tabs[0].url);
let domain = url.hostname;
// Get all cookies for the domain
chrome.cookies.getAll({ domain: domain }, function(cookies) {
console.log("Cookies before deletion:", cookies);
for (let cookie of cookies) {
// Delete each cookie
chrome.cookies.remove({
url: "https://" + domain + cookie.path,
name: cookie.name
});
}
// Update cookie count after clearing
setTimeout(updateCookieCount, 1000);
});
});
});
// Function to update cookie count
function updateCookieCount() {
chrome.tabs.query({ active: true, currentWindow: true }, function(tabs) {
let url = new URL(tabs[0].url);
let domain = url.hostname;
// Get all cookies for the domain
chrome.cookies.getAll({ domain: domain }, function(cookies) {
document.getElementById('cookieCount').innerText = `Active cookies: ${cookies.length}`;
});
});
}
// Initialize cookie count when popup loads
updateCookieCount();