Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifest_version": 3,
"name": "TabStack",
"short_name": "TabStack",
"version": "1.3.0",
"version": "1.4.0",
"description": "Automatically clusters same-site tabs into native collapsible groups, expands only active stacks, and saves memory.",
"permissions": [
"tabs",
Expand Down
57 changes: 56 additions & 1 deletion src/background/grouper.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,53 @@
import { getSettings } from '../shared/storage.js';
import { extractDomain, formatDomainTitle, getDomainColor } from './utils.js';

/**
* Name TabStack gives a domain's stack, without the tab count suffix
* @param {string} domain
* @param {object} settings
* @returns {string}
*/
function getStackTitle(domain, settings) {
return settings.customDomainNames?.[domain] || formatDomainTitle(domain);
}

/**
* Finds the groups TabStack created in a window. A group counts as TabStack's when its title is the
* stack name for the domain of one of its tabs, optionally followed by a " (n)" tab count. Titles
* survive browser restarts (group ids don't), and a group the user creates or renames won't match.
* @param {number} windowId
* @param {chrome.tabs.Tab[]} tabs All tabs in the window
* @param {object} settings
* @returns {Promise<Set<number>>}
*/
async function getManagedGroupIds(windowId, tabs, settings) {
const groups = await chrome.tabGroups.query({ windowId });

const domainsByGroup = new Map();
for (const tab of tabs) {
if (tab.groupId === chrome.tabGroups.TAB_GROUP_ID_NONE) continue;
const domain = extractDomain(tab.url || tab.pendingUrl, settings.domainMode);
if (!domain) continue;
if (!domainsByGroup.has(tab.groupId)) {
domainsByGroup.set(tab.groupId, new Set());
}
domainsByGroup.get(tab.groupId).add(domain);
}

const managed = new Set();
for (const group of groups) {
const baseTitle = (group.title || '').replace(/ \(\d+\)$/, '');
const domains = domainsByGroup.get(group.id) || [];
for (const domain of domains) {
if (getStackTitle(domain, settings) === baseTitle) {
managed.add(group.id);
break;
}
}
}
return managed;
}

/**
* Automatically groups tabs by domain in the specified window
* @param {number} windowId
Expand All @@ -22,10 +69,18 @@ export async function groupTabsInWindow(windowId, force = false) {
// Filter out pinned tabs and whitelisted domains
const whitelist = new Set((settings.whitelistDomains || []).map(d => d.toLowerCase().trim()));
const domainToTabs = new Map();
const preserveExisting = settings.preserveExistingGroups !== false;
const managedGroupIds = preserveExisting ? await getManagedGroupIds(windowId, tabs, settings) : null;

for (const tab of tabs) {
if (tab.pinned) continue;

// If preserving existing groups, leave groups the user made or renamed untouched.
// Tabs in TabStack's own stacks still count, so new same-site tabs join them instead of forming a duplicate stack.
if (preserveExisting && tab.groupId !== chrome.tabGroups.TAB_GROUP_ID_NONE && !managedGroupIds.has(tab.groupId)) {
continue;
}

const domain = extractDomain(tab.url || tab.pendingUrl, settings.domainMode);
if (!domain) continue;

Expand Down Expand Up @@ -65,7 +120,7 @@ export async function groupTabsInWindow(windowId, force = false) {
}

// Format title
let title = settings.customDomainNames?.[domain] || formatDomainTitle(domain);
let title = getStackTitle(domain, settings);
if (settings.showTabCountInTitle) {
title = `${title} (${domainTabs.length})`;
}
Expand Down
33 changes: 33 additions & 0 deletions src/options/options.css
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,39 @@ body {
max-width: 75%;
}

.setting-title-with-badge {
display: flex;
align-items: center;
gap: 8px;
}

.info-badge-wrapper {
display: inline-flex;
align-items: center;
justify-content: center;
color: var(--text-dim);
cursor: pointer;
padding: 2px;
border-radius: 50%;
transition: color 0.15s ease;
}

.info-badge-wrapper:hover {
color: #f59e0b;
}

.badge-recommended {
font-size: 10px;
font-weight: 600;
padding: 2px 7px;
border-radius: 12px;
text-transform: uppercase;
letter-spacing: 0.4px;
background: rgba(34, 197, 94, 0.12);
color: #22c55e;
border: 1px solid rgba(34, 197, 94, 0.25);
}

.setting-title {
font-size: 13px;
font-weight: 600;
Expand Down
24 changes: 22 additions & 2 deletions src/options/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,32 @@ <h2>General & Grouping</h2>

<div class="setting-row">
<div class="setting-info">
<label class="setting-title" for="optAutoGroup">Enable Auto-Stacking</label>
<span class="setting-subtitle">Automatically cluster newly opened tabs by domain in real time.</span>
<div class="setting-title-with-badge">
<label class="setting-title" for="optAutoGroup">Enable Auto-Stacking</label>
<div class="info-badge-wrapper" title="Caution: Auto-Stack automatically organizes and groups tabs in real time in the background as you browse or open new tabs.">
<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round">
<circle cx="12" cy="12" r="10"></circle>
<line x1="12" y1="16" x2="12" y2="12"></line>
<line x1="12" y1="8" x2="12.01" y2="8"></line>
</svg>
</div>
</div>
<span class="setting-subtitle">Automatically cluster newly opened tabs by domain in real time. <strong style="color: #f59e0b;">(Caution: runs continuously in background)</strong></span>
</div>
<input type="checkbox" id="optAutoGroup" class="switch">
</div>

<div class="setting-row">
<div class="setting-info">
<div class="setting-title-with-badge">
<label class="setting-title" for="optPreserveGroups">Preserve Existing Tab Groups</label>
<span class="badge-recommended">Recommended</span>
</div>
<span class="setting-subtitle">Auto-Stack only groups loose tabs and adds them to its own stacks. Tab groups you create or rename are never touched, modified, or merged.</span>
</div>
<input type="checkbox" id="optPreserveGroups" class="switch">
</div>

<div class="setting-row">
<div class="setting-info">
<label class="setting-title" for="optAccordion">Accordion / Focus Mode</label>
Expand Down
6 changes: 5 additions & 1 deletion src/options/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { initTheme, setTheme } from '../shared/theme.js';
// DOM Elements
const optTheme = document.getElementById('optTheme');
const optAutoGroup = document.getElementById('optAutoGroup');
const optPreserveGroups = document.getElementById('optPreserveGroups');
const optAccordion = document.getElementById('optAccordion');
const optMinTabs = document.getElementById('optMinTabs');
const optDomainMode = document.getElementById('optDomainMode');
Expand Down Expand Up @@ -51,6 +52,7 @@ async function init() {
function populateForm(settings) {
if (optTheme) optTheme.value = settings.theme || 'system';
optAutoGroup.checked = !!settings.autoGroupEnabled;
if (optPreserveGroups) optPreserveGroups.checked = settings.preserveExistingGroups !== false;
optAccordion.checked = !!settings.accordionMode;
optMinTabs.value = String(settings.minTabsToGroup || 2);
optDomainMode.value = settings.domainMode || 'root';
Expand Down Expand Up @@ -80,6 +82,7 @@ function setupListeners() {
const updated = {
theme: optTheme ? optTheme.value : 'system',
autoGroupEnabled: optAutoGroup.checked,
preserveExistingGroups: optPreserveGroups ? optPreserveGroups.checked : true,
accordionMode: optAccordion.checked,
minTabsToGroup: parseInt(optMinTabs.value, 10),
domainMode: optDomainMode.value,
Expand All @@ -102,8 +105,9 @@ function setupListeners() {
chrome.runtime.sendMessage({ type: MESSAGE_TYPES.SETTINGS_UPDATED });
};

[optAutoGroup, optAccordion, optMinTabs, optDomainMode, optShowCount, optRamSaver, optDiscardTimeout,
[optAutoGroup, optPreserveGroups, optAccordion, optMinTabs, optDomainMode, optShowCount, optRamSaver, optDiscardTimeout,
optSnapshotClosed, optSnapshotsEnabled, optSnapshotInterval, optSnapshotKeep]
.filter(Boolean)
.forEach(el => el.addEventListener('change', autoSaveHandler));

// Snapshot backup handlers
Expand Down
162 changes: 160 additions & 2 deletions src/popup/popup.css
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@

body {
width: 400px;
height: 590px;
height: 600px;
background-color: var(--bg-base);
color: var(--text-main);
font-family: var(--font-family);
Expand Down Expand Up @@ -284,14 +284,92 @@ body {
cursor: pointer;
}

.toggle-row-item {
display: flex;
align-items: center;
gap: 8px;
}

.toggle-title-with-info {
display: flex;
align-items: center;
gap: 4px;
}

.toggle-title {
font-size: 11px;
font-weight: 500;
color: var(--text-muted);
cursor: pointer;
}

.toggle-row:hover .toggle-title,
.toggle-title-with-info:hover .toggle-title {
color: var(--text-main);
}

.info-icon-wrap {
position: relative;
display: inline-flex;
align-items: center;
justify-content: center;
cursor: pointer;
color: var(--text-dim);
padding: 1px;
border-radius: 50%;
transition: color 0.15s ease, background-color 0.15s ease;
}

.toggle-row:hover .toggle-title {
.info-icon-wrap:hover,
.info-icon-wrap:focus-visible,
.info-icon-wrap.active {
color: var(--text-main);
background-color: var(--bg-card-hover);
}

.info-popover {
position: absolute;
top: calc(100% + 8px);
left: -8px;
width: 230px;
background: var(--bg-card);
border: 1px solid var(--border-medium);
border-radius: var(--radius-md);
padding: 10px 12px;
box-shadow: 0 10px 25px rgba(0, 0, 0, 0.45);
z-index: 1000;
opacity: 0;
visibility: hidden;
transform: translateY(-4px);
transition: opacity 0.18s ease, transform 0.18s ease, visibility 0.18s;
pointer-events: none;
}

.info-icon-wrap:hover .info-popover,
.info-icon-wrap:focus-visible .info-popover,
.info-icon-wrap.active .info-popover {
opacity: 1;
visibility: visible;
transform: translateY(0);
pointer-events: auto;
}

.info-popover-title {
display: flex;
align-items: center;
gap: 5px;
font-size: 11px;
font-weight: 600;
color: #f59e0b;
margin-bottom: 4px;
}

.info-popover p {
font-size: 10.5px;
line-height: 1.4;
color: var(--text-muted);
margin: 0;
text-align: left;
}

.toggle-divider {
Expand All @@ -300,6 +378,86 @@ body {
background: var(--border-subtle);
}

/* Smart Group Protection Card */
.protection-card {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin: 0 18px 8px;
padding: 8px 12px;
background: var(--bg-surface);
border: 1px solid var(--border-subtle);
border-radius: var(--radius-md);
transition: border-color 0.15s ease, background-color 0.15s ease;
}

.protection-card:hover {
border-color: var(--border-medium);
}

.protection-main {
flex: 1;
min-width: 0;
text-align: left;
}

.protection-title-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 6px;
margin-bottom: 2px;
}

.protection-badge-group {
display: flex;
align-items: center;
gap: 6px;
}

.protection-shield-icon {
color: #22c55e;
flex-shrink: 0;
transition: color 0.15s ease;
}

.protection-title {
font-size: 11.5px;
font-weight: 600;
color: var(--text-main);
letter-spacing: -0.1px;
}

.badge-protection-status {
font-size: 9px;
font-weight: 600;
padding: 1px 6px;
border-radius: 10px;
text-transform: uppercase;
letter-spacing: 0.3px;
transition: all 0.15s ease;
}

.badge-protection-status.active {
background: rgba(34, 197, 94, 0.12);
color: #22c55e;
border: 1px solid rgba(34, 197, 94, 0.25);
}

.badge-protection-status.inactive {
background: rgba(239, 68, 68, 0.1);
color: #ef4444;
border: 1px solid rgba(239, 68, 68, 0.2);
}

.protection-desc {
font-size: 10.5px;
color: var(--text-muted);
line-height: 1.35;
margin: 0;
}

/* Minimalist Switch */
.switch {
appearance: none;
Expand Down
Loading
Loading