1<html> 2 <head> 3 <script> 4 var targetWindow = null; 5 var tabCount = 0; 6 7 function start(tab) { 8 chrome.windows.getCurrent(getWindows); 9 } 10 11 function getWindows(win) { 12 targetWindow = win; 13 chrome.tabs.getAllInWindow(targetWindow.id, getTabs); 14 } 15 16 function getTabs(tabs) { 17 tabCount = tabs.length; 18 // We require all the tab information to be populated. 19 chrome.windows.getAll({"populate" : true}, moveTabs); 20 } 21 22 function moveTabs(windows) { 23 var numWindows = windows.length; 24 var tabPosition = tabCount; 25 26 for (var i = 0; i < numWindows; i++) { 27 var win = windows[i]; 28 29 if (targetWindow.id != win.id) { 30 var numTabs = win.tabs.length; 31 32 for (var j = 0; j < numTabs; j++) { 33 var tab = win.tabs[j]; 34 35 // Move the tab into the window that triggered the browser action. 36 chrome.tabs.move(tab.id, 37 {"windowId": targetWindow.id, "index": tabPosition}); 38 39 tabPosition++; 40 } 41 } 42 } 43 } 44 45 // Set up a click handler so that we can merge all the windows. 46 chrome.browserAction.onClicked.addListener(start); 47 </script> 48 </head> 49</html>