From c384c13c0c0fecc2996bc347e0551c37a21a458f Mon Sep 17 00:00:00 2001 From: qrayy Date: Fri, 4 Sep 2026 08:56:26 +0500 Subject: [PATCH 1/2] feat(group-preservation): add toggle to protect existing groups and add autostack caution tooltip --- manifest.json | 2 +- src/background/grouper.js | 6 ++ src/options/options.css | 33 ++++++++ src/options/options.html | 24 +++++- src/options/options.js | 6 +- src/popup/popup.css | 162 +++++++++++++++++++++++++++++++++++++- src/popup/popup.html | 41 +++++++++- src/popup/popup.js | 56 +++++++++++++ src/shared/constants.js | 1 + 9 files changed, 322 insertions(+), 9 deletions(-) diff --git a/manifest.json b/manifest.json index 3da9a2d..df06ba6 100644 --- a/manifest.json +++ b/manifest.json @@ -2,7 +2,7 @@ "manifest_version": 3, "name": "TabStack", "short_name": "TabStack", - "version": "1.1.0", + "version": "1.2.0", "description": "Automatically clusters same-site tabs into native collapsible groups, expands only active stacks, and saves memory.", "permissions": [ "tabs", diff --git a/src/background/grouper.js b/src/background/grouper.js index c163e08..7559c2b 100644 --- a/src/background/grouper.js +++ b/src/background/grouper.js @@ -22,10 +22,16 @@ 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; for (const tab of tabs) { if (tab.pinned) continue; + // If preserving existing groups, only consider ungrouped tabs (leave existing/custom groups untouched) + if (preserveExisting && tab.groupId !== chrome.tabGroups.TAB_GROUP_ID_NONE && tab.groupId > 0) { + continue; + } + const domain = extractDomain(tab.url || tab.pendingUrl, settings.domainMode); if (!domain) continue; diff --git a/src/options/options.css b/src/options/options.css index 274b969..fb7cdbd 100644 --- a/src/options/options.css +++ b/src/options/options.css @@ -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; diff --git a/src/options/options.html b/src/options/options.html index d3e2948..f8f52e9 100644 --- a/src/options/options.html +++ b/src/options/options.html @@ -65,12 +65,32 @@

General & Grouping

- - Automatically cluster newly opened tabs by domain in real time. +
+ +
+ + + + + +
+
+ Automatically cluster newly opened tabs by domain in real time. (Caution: runs continuously in background)
+
+
+
+ + Recommended +
+ Only group tabs that are currently ungrouped. Existing or custom tab groups will never be touched, modified, or merged. +
+ +
+
diff --git a/src/options/options.js b/src/options/options.js index e6717b1..555e391 100644 --- a/src/options/options.js +++ b/src/options/options.js @@ -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'); @@ -40,6 +41,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'; @@ -63,6 +65,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, @@ -79,7 +82,8 @@ 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] + .filter(Boolean) .forEach(el => el.addEventListener('change', autoSaveHandler)); // Whitelist Handlers diff --git a/src/popup/popup.css b/src/popup/popup.css index 0d5aa29..c345d2c 100644 --- a/src/popup/popup.css +++ b/src/popup/popup.css @@ -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); @@ -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 { @@ -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; diff --git a/src/popup/popup.html b/src/popup/popup.html index efeaf16..a53c673 100644 --- a/src/popup/popup.html +++ b/src/popup/popup.html @@ -77,10 +77,26 @@
-
+ +
+
+
+
+ + + + Preserve Existing Groups +
+ Protected +
+

Only clusters ungrouped tabs. Existing or custom groups are protected and will never be modified or merged.

+
+ +
+
diff --git a/src/popup/popup.js b/src/popup/popup.js index 8ffd609..7f276f0 100644 --- a/src/popup/popup.js +++ b/src/popup/popup.js @@ -26,6 +26,11 @@ const statRamSaved = document.getElementById('statRamSaved'); const toggleAutoGroup = document.getElementById('toggleAutoGroup'); const toggleAccordion = document.getElementById('toggleAccordion'); const toggleRamSaver = document.getElementById('toggleRamSaver'); +const togglePreserveGroups = document.getElementById('togglePreserveGroups'); +const badgeProtectionStatus = document.getElementById('badgeProtectionStatus'); +const descProtection = document.getElementById('descProtection'); +const groupProtectionCard = document.getElementById('groupProtectionCard'); +const autoStackInfoBtn = document.getElementById('autoStackInfoBtn'); const searchContainer = document.getElementById('searchContainer'); const searchInput = document.getElementById('searchInput'); @@ -79,6 +84,11 @@ async function init() { toggleAutoGroup.checked = !!currentSettings.autoGroupEnabled; toggleAccordion.checked = !!currentSettings.accordionMode; toggleRamSaver.checked = !!currentSettings.autoDiscardEnabled; + if (togglePreserveGroups) { + const isPreserve = currentSettings.preserveExistingGroups !== false; + togglePreserveGroups.checked = isPreserve; + updatePreserveGroupsUI(isPreserve); + } // Event Listeners setupEventListeners(); @@ -94,6 +104,21 @@ function updateThemeButtonsActiveState(theme) { }); } +function updatePreserveGroupsUI(isActive) { + if (!badgeProtectionStatus || !descProtection) return; + if (isActive) { + badgeProtectionStatus.textContent = 'Protected'; + badgeProtectionStatus.className = 'badge-protection-status active'; + groupProtectionCard?.classList.add('active'); + descProtection.textContent = 'Only clusters ungrouped tabs. Existing or custom groups are protected and will never be modified or merged.'; + } else { + badgeProtectionStatus.textContent = 'Off'; + badgeProtectionStatus.className = 'badge-protection-status inactive'; + groupProtectionCard?.classList.remove('active'); + descProtection.textContent = 'Group protection disabled. Auto-Stack will merge tabs matching the same domain across all groups.'; + } +} + /** * Register live Chromium tab and tabGroup listeners so popup updates in real-time */ @@ -128,6 +153,19 @@ function setupRealtimeListeners() { * Register all event handlers */ function setupEventListeners() { + // Auto-Stack Info Button caution notice popover + autoStackInfoBtn?.addEventListener('click', (e) => { + e.stopPropagation(); + e.preventDefault(); + autoStackInfoBtn.classList.toggle('active'); + }); + + document.addEventListener('click', (e) => { + if (!e.target.closest('#autoStackInfoBtn')) { + autoStackInfoBtn?.classList.remove('active'); + } + }); + // Theme segmented buttons themeControl?.querySelectorAll('.theme-btn').forEach(btn => { btn.addEventListener('click', async () => { @@ -176,6 +214,17 @@ function setupEventListeners() { await refreshData(); }); + // Preserve Existing Groups Toggle + togglePreserveGroups?.addEventListener('change', async (e) => { + const isEnabled = e.target.checked; + await setSetting('preserveExistingGroups', isEnabled); + updatePreserveGroupsUI(isEnabled); + showToast(isEnabled + ? '🛡️ Existing groups protected (Only ungrouped tabs stack)' + : '⚠️ Group protection OFF (Tabs may merge into same-site stacks)' + ); + }); + // Navigation tab switching tabNavLive.addEventListener('click', () => switchView('live')); tabNavStash.addEventListener('click', () => switchView('stash')); @@ -259,6 +308,13 @@ async function refreshData() { allGroups = groups; currentSettings = settings; + // Sync preserve groups toggle if changed externally + if (togglePreserveGroups && document.activeElement !== togglePreserveGroups) { + const isPreserve = settings.preserveExistingGroups !== false; + togglePreserveGroups.checked = isPreserve; + updatePreserveGroupsUI(isPreserve); + } + // Detect active tab domain for 1-click whitelist button const activeTab = tabs.find(t => t.active); currentActiveDomain = activeTab ? extractDomain(activeTab.url || activeTab.pendingUrl, settings.domainMode) : null; diff --git a/src/shared/constants.js b/src/shared/constants.js index 7aeb3b8..64fe979 100644 --- a/src/shared/constants.js +++ b/src/shared/constants.js @@ -16,6 +16,7 @@ export const CHROMIUM_COLORS = [ export const DEFAULT_SETTINGS = { theme: 'system', // 'system' | 'light' | 'dark' autoGroupEnabled: false, // Off by default + preserveExistingGroups: true, // Only group ungrouped tabs; leave existing groups untouched accordionMode: true, // Auto-expand active group, collapse all other groups minTabsToGroup: 2, // Minimum tabs from same domain to form a group (e.g. 2 tabs) domainMode: 'root', // 'root' (e.g., github.com) or 'subdomain' (e.g., docs.github.com) From 480c9cc7a2f65a0bb4b75ed6accb1df757608920 Mon Sep 17 00:00:00 2001 From: qrayy Date: Thu, 8 Oct 2026 21:08:28 +0500 Subject: [PATCH 2/2] fix(group-preservation): let new tabs join TabStack's own stacks With Preserve Existing Groups on, the grouper skipped every grouped tab, including stacks TabStack made itself. A new same-site tab then stayed loose (below minTabsToGroup) or formed a duplicate stack, and tab counts in titles went stale. Treat a group as TabStack's when its title is the stack name for one of its tabs' domains (with an optional " (n)" count). Titles survive browser restarts, and groups the user creates or renames still never match. Co-Authored-By: Claude Opus 5.5 --- src/background/grouper.js | 55 ++++++++++++++++++++++++++++++++++++--- src/options/options.html | 2 +- src/popup/popup.html | 2 +- src/popup/popup.js | 4 +-- 4 files changed, 56 insertions(+), 7 deletions(-) diff --git a/src/background/grouper.js b/src/background/grouper.js index 7559c2b..95f8adb 100644 --- a/src/background/grouper.js +++ b/src/background/grouper.js @@ -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>} + */ +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 @@ -23,12 +70,14 @@ export async function groupTabsInWindow(windowId, force = false) { 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, only consider ungrouped tabs (leave existing/custom groups untouched) - if (preserveExisting && tab.groupId !== chrome.tabGroups.TAB_GROUP_ID_NONE && tab.groupId > 0) { + // 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; } @@ -71,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})`; } diff --git a/src/options/options.html b/src/options/options.html index d4ce2e7..b8d8bc6 100644 --- a/src/options/options.html +++ b/src/options/options.html @@ -87,7 +87,7 @@

General & Grouping

Recommended
- Only group tabs that are currently ungrouped. Existing or custom tab groups will never be touched, modified, or merged. + 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.
diff --git a/src/popup/popup.html b/src/popup/popup.html index 99ce5b1..cb7fdf5 100644 --- a/src/popup/popup.html +++ b/src/popup/popup.html @@ -121,7 +121,7 @@ Protected -

Only clusters ungrouped tabs. Existing or custom groups are protected and will never be modified or merged.

+

Only stacks loose tabs into TabStack's own groups. Groups you create or rename are never modified or merged.