-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.js
35 lines (29 loc) · 1.1 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
document.getElementById('groupNow').addEventListener('click', () => {
chrome.runtime.sendMessage({ action: 'groupTabs' });
});
document.getElementById('openSettings').addEventListener('click', () => {
chrome.runtime.openOptionsPage();
});
function updateStats() {
chrome.tabs.query({currentWindow: true}, (tabs) => {
const totalTabs = tabs.length;
let groupedTabs = 0;
const groups = new Set();
tabs.forEach(tab => {
if (tab.groupId !== chrome.tabs.TAB_ID_NONE) {
groupedTabs++;
groups.add(tab.groupId);
}
});
document.getElementById('totalTabs').textContent = totalTabs;
document.getElementById('groupedTabs').textContent = groupedTabs;
document.getElementById('groupCount').textContent = groups.size;
});
}
// Update stats when popup is opened
document.addEventListener('DOMContentLoaded', updateStats);
// Listen for tab updates and refresh stats
chrome.tabs.onUpdated.addListener(updateStats);
chrome.tabs.onRemoved.addListener(updateStats);
chrome.tabGroups.onCreated.addListener(updateStats);
chrome.tabGroups.onRemoved.addListener(updateStats);