-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.js
55 lines (46 loc) · 2.14 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
54
55
// Fetch the data from chrome.storage.local
chrome.storage.local.get(['visited', 'hyperlinks'], (data) => {
let siteCount = Object.keys(data.visited || {}).length; // Number of unique sites visited
let linkCount = 0;
for (let site in data.hyperlinks || {}) {
linkCount += data.hyperlinks[site].length;
}
document.getElementById('siteCount').textContent = siteCount;
document.getElementById('linkCount').textContent = linkCount;
});
document.getElementById('detailsBtn').addEventListener('click', () => {
// Open a new tab to display details
chrome.tabs.create({ url: 'details.html' });
});
document.getElementById('resetBtn').addEventListener('click', () => {
if (confirm("Are you sure you want to reset all data?")) {
// Reset the data
chrome.storage.local.set({ 'visited': {}, 'hyperlinks': {} }, () => {
if (chrome.runtime.lastError) {
console.error("Error during reset:", chrome.runtime.lastError);
} else {
console.log("Data reset successfully");
document.getElementById('siteCount').textContent = 0;
document.getElementById('linkCount').textContent = 0;
}
});
}
});
document.getElementById('pauseBtn').addEventListener('click', () => {
chrome.storage.local.get('isTrackingPaused', ({ isTrackingPaused }) => {
// Toggle the tracking state
const newState = !isTrackingPaused;
chrome.storage.local.set({ 'isTrackingPaused': newState }, () => {
if (chrome.runtime.lastError) {
console.error("Error toggling tracking state:", chrome.runtime.lastError);
} else {
console.log("Tracking state toggled successfully");
// Update button label according to the new state
document.getElementById('pauseBtn').textContent = newState ? "Resume Tracking" : "Pause Tracking";
}
});
});
});
chrome.storage.local.get('isTrackingPaused', ({ isTrackingPaused }) => {
document.getElementById('pauseBtn').textContent = isTrackingPaused ? "Resume Tracking" : "Pause Tracking";
});