@@ -19,6 +19,12 @@ const onClickMenu = (info, tab) => {
1919 type : 'CREATE_CHAT' ,
2020 data : message ,
2121 } )
22+ } else if ( message . itemId . startsWith ( 'custom_' ) ) {
23+ // Handle custom selection tools
24+ Browser . tabs . sendMessage ( currentTab . id , {
25+ type : 'CREATE_CHAT' ,
26+ data : message ,
27+ } )
2228 } else if ( message . itemId in menuConfig ) {
2329 if ( menuConfig [ message . itemId ] . action ) {
2430 menuConfig [ message . itemId ] . action ( true , tab )
@@ -37,7 +43,8 @@ export function refreshMenu() {
3743 if ( Browser . contextMenus . onClicked . hasListener ( onClickMenu ) )
3844 Browser . contextMenus . onClicked . removeListener ( onClickMenu )
3945 Browser . contextMenus . removeAll ( ) . then ( async ( ) => {
40- if ( ( await getUserConfig ( ) ) . hideContextMenu ) return
46+ const userConfig = await getUserConfig ( )
47+ if ( userConfig . hideContextMenu ) return
4148
4249 await getPreferredLanguageKey ( ) . then ( ( lang ) => {
4350 changeLanguage ( lang )
@@ -62,15 +69,32 @@ export function refreshMenu() {
6269 contexts : [ 'selection' ] ,
6370 type : 'separator' ,
6471 } )
72+
73+ // Add default selection tools that are active
6574 for ( const index in defaultConfig . selectionTools ) {
6675 const key = defaultConfig . selectionTools [ index ]
6776 const desc = defaultConfig . selectionToolsDesc [ index ]
68- Browser . contextMenus . create ( {
69- id : menuId + key ,
70- parentId : menuId ,
71- title : t ( desc ) ,
72- contexts : [ 'selection' ] ,
73- } )
77+ if ( userConfig . activeSelectionTools . includes ( key ) ) {
78+ Browser . contextMenus . create ( {
79+ id : menuId + key ,
80+ parentId : menuId ,
81+ title : t ( desc ) ,
82+ contexts : [ 'selection' ] ,
83+ } )
84+ }
85+ }
86+
87+ // Add custom selection tools that are active
88+ for ( let i = 0 ; i < userConfig . customSelectionTools . length ; i ++ ) {
89+ const tool = userConfig . customSelectionTools [ i ]
90+ if ( tool . active && tool . name ) {
91+ Browser . contextMenus . create ( {
92+ id : menuId + 'custom_' + i ,
93+ parentId : menuId ,
94+ title : tool . name ,
95+ contexts : [ 'selection' ] ,
96+ } )
97+ }
7498 }
7599
76100 Browser . contextMenus . onClicked . addListener ( onClickMenu )
0 commit comments