Skip to content

Commit 72638b8

Browse files
committed
merge all button
1 parent d81a103 commit 72638b8

3 files changed

Lines changed: 92 additions & 0 deletions

File tree

tab-extension/manager.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,17 @@ <h1>Tab Manager</h1>
1616
</div>
1717
</div>
1818
<div class="header-right">
19+
<button id="mergeAllBtn" class="btn btn-merge" title="Merge all tabs into current window">
20+
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
21+
<path d="M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16z"></path>
22+
<polyline points="7.5 4.21 12 6.81 16.5 4.21"></polyline>
23+
<polyline points="7.5 19.79 7.5 14.6 3 12"></polyline>
24+
<polyline points="21 12 16.5 14.6 16.5 19.79"></polyline>
25+
<polyline points="3.27 6.96 12 12.01 20.73 6.96"></polyline>
26+
<line x1="12" y1="22.08" x2="12" y2="12"></line>
27+
</svg>
28+
Merge All
29+
</button>
1930
<div class="search-container">
2031
<svg class="search-icon" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
2132
<circle cx="11" cy="11" r="8"></circle>

tab-extension/manager.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ function setupEventListeners() {
4141
searchQuery = e.target.value.toLowerCase();
4242
renderWindows();
4343
});
44+
45+
const mergeAllBtn = document.getElementById('mergeAllBtn');
46+
mergeAllBtn.addEventListener('click', mergeAllWindows);
4447
}
4548

4649
// Render all windows
@@ -391,6 +394,64 @@ async function moveSelectedTabs(fromWindowId, toWindowId) {
391394
}
392395
}
393396

397+
// Merge all tabs from all windows into the current window
398+
async function mergeAllWindows() {
399+
if (allWindows.length <= 1) {
400+
return; // Nothing to merge
401+
}
402+
403+
// Disable the button during merge
404+
const mergeBtn = document.getElementById('mergeAllBtn');
405+
mergeBtn.disabled = true;
406+
mergeBtn.textContent = 'Merging...';
407+
408+
try {
409+
// Get all tabs from all windows except the current window
410+
const tabsToMove = [];
411+
412+
for (const window of allWindows) {
413+
if (window.id !== currentWindowId) {
414+
tabsToMove.push(...window.tabs.map(tab => tab.id));
415+
}
416+
}
417+
418+
// Move all tabs to the current window
419+
for (const tabId of tabsToMove) {
420+
await chrome.tabs.move(tabId, { windowId: currentWindowId, index: -1 });
421+
}
422+
423+
// Close empty windows
424+
for (const window of allWindows) {
425+
if (window.id !== currentWindowId) {
426+
try {
427+
await chrome.windows.remove(window.id);
428+
} catch (e) {
429+
// Window might already be closed
430+
console.log('Window already closed:', window.id);
431+
}
432+
}
433+
}
434+
435+
setTimeout(loadWindows, 200);
436+
} finally {
437+
// Re-enable the button
438+
setTimeout(() => {
439+
mergeBtn.disabled = false;
440+
mergeBtn.innerHTML = `
441+
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
442+
<path d="M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16z"></path>
443+
<polyline points="7.5 4.21 12 6.81 16.5 4.21"></polyline>
444+
<polyline points="7.5 19.79 7.5 14.6 3 12"></polyline>
445+
<polyline points="21 12 16.5 14.6 16.5 19.79"></polyline>
446+
<polyline points="3.27 6.96 12 12.01 20.73 6.96"></polyline>
447+
<line x1="12" y1="22.08" x2="12" y2="12"></line>
448+
</svg>
449+
Merge All
450+
`;
451+
}, 300);
452+
}
453+
}
454+
394455
// Extract top-level domain from hostname
395456
function getTopLevelDomain(url) {
396457
try {

tab-extension/styles.css

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ header {
3535
gap: 24px;
3636
}
3737

38+
.header-right {
39+
display: flex;
40+
align-items: center;
41+
gap: 12px;
42+
}
43+
3844
.logo {
3945
display: flex;
4046
align-items: center;
@@ -210,6 +216,20 @@ header {
210216
cursor: not-allowed;
211217
}
212218

219+
.btn-merge {
220+
background: #10b981;
221+
color: white;
222+
font-weight: 500;
223+
}
224+
225+
.btn-merge:hover {
226+
background: #059669;
227+
}
228+
229+
.btn-merge:active {
230+
background: #047857;
231+
}
232+
213233
.tabs-table {
214234
width: 100%;
215235
}

0 commit comments

Comments
 (0)