@@ -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
395456function getTopLevelDomain ( url ) {
396457 try {
0 commit comments