@@ -781,6 +781,58 @@ function start(browser) {
781781 } ) ;
782782 } ) ;
783783 } ;
784+ self . createTabGroup = function ( message , sender , sendResponse ) {
785+ chrome . tabs . group ( { tabIds : [ sender . tab . id ] , groupId : message . groupId } , function ( groupId ) {
786+ if ( message . title || message . color ) {
787+ chrome . tabGroups . update ( groupId , {
788+ title : message . title ,
789+ color : message . color
790+ } ) ;
791+ }
792+ } ) ;
793+ } ;
794+ self . ungroupTab = function ( message , sender , sendResponse ) {
795+ chrome . tabs . ungroup ( [ sender . tab . id ] ) ;
796+ } ;
797+ self . collapseGroup = function ( message , sender , sendResponse ) {
798+ chrome . tabGroups . update ( message . groupId , { collapsed : message . collapsed } ) ;
799+ } ;
800+ self . getTabGroups = function ( message , sender , sendResponse ) {
801+ chrome . tabGroups . query ( { } , function ( groups ) {
802+ let activeGroup = - 1 ;
803+ // retrieve all tabs of each group
804+ chrome . tabs . query ( { } , function ( tabs ) {
805+ const tabsInGroup = { } ;
806+ tabs . forEach ( function ( tab ) {
807+ if ( tab . groupId && tab . groupId !== chrome . tabGroups . TAB_GROUP_ID_NONE ) {
808+ if ( ! tabsInGroup [ tab . groupId ] ) {
809+ tabsInGroup [ tab . groupId ] = [ ] ;
810+ }
811+ if ( tab . id === sender . tab . id ) {
812+ activeGroup = tab . groupId ;
813+ }
814+ tabsInGroup [ tab . groupId ] . push ( {
815+ id : tab . id ,
816+ title : tab . title ,
817+ url : tab . url ,
818+ active : tab . active ,
819+ index : tab . index
820+ } ) ;
821+ }
822+ } ) ;
823+
824+ groups = groups . filter ( ( g ) => ! g . hermit ) ;
825+ groups . forEach ( function ( group ) {
826+ group . tabs = tabsInGroup [ group . id ] || [ ] ;
827+ group . active = group . id === activeGroup ;
828+ } ) ;
829+
830+ _response ( message , sendResponse , {
831+ groups : groups
832+ } ) ;
833+ } ) ;
834+ } ) ;
835+ } ;
784836 self . togglePinTab = function ( message , sender , sendResponse ) {
785837 getActiveTab ( function ( tab ) {
786838 return chrome . tabs . update ( tab . id , {
0 commit comments