File tree Expand file tree Collapse file tree 4 files changed +55
-5
lines changed Expand file tree Collapse file tree 4 files changed +55
-5
lines changed Original file line number Diff line number Diff line change @@ -126,6 +126,19 @@ Browser.runtime.onMessage.addListener(async (message) => {
126
126
}
127
127
} )
128
128
129
+ Browser . commands . onCommand . addListener ( async ( command ) => {
130
+ const currentTab = ( await Browser . tabs . query ( { active : true , currentWindow : true } ) ) [ 0 ]
131
+ const message = {
132
+ itemId : command ,
133
+ selectionText : '' ,
134
+ useMenuPosition : false ,
135
+ }
136
+ Browser . tabs . sendMessage ( currentTab . id , {
137
+ type : 'CREATE_CHAT' ,
138
+ data : message ,
139
+ } )
140
+ } )
141
+
129
142
function refreshMenu ( ) {
130
143
Browser . contextMenus . removeAll ( ) . then ( ( ) => {
131
144
const menuId = 'ChatGPTBox-Menu'
@@ -164,10 +177,11 @@ function refreshMenu() {
164
177
const message = {
165
178
itemId : info . menuItemId . replace ( menuId , '' ) ,
166
179
selectionText : info . selectionText ,
180
+ useMenuPosition : true ,
167
181
}
168
182
console . debug ( 'menu clicked' , message )
169
183
Browser . tabs . sendMessage ( tab . id , {
170
- type : 'CREATE_MENU ' ,
184
+ type : 'CREATE_CHAT ' ,
171
185
data : message ,
172
186
} )
173
187
} )
Original file line number Diff line number Diff line change @@ -218,7 +218,7 @@ async function prepareForRightClickMenu() {
218
218
} )
219
219
220
220
Browser . runtime . onMessage . addListener ( async ( message ) => {
221
- if ( message . type === 'CREATE_MENU ' ) {
221
+ if ( message . type === 'CREATE_CHAT ' ) {
222
222
const data = message . data
223
223
let prompt = ''
224
224
if ( data . itemId in toolsConfig ) {
@@ -228,7 +228,9 @@ async function prepareForRightClickMenu() {
228
228
if ( prompt ) prompt = cropText ( `Reply in ${ await getPreferredLanguage ( ) } .\n` + prompt )
229
229
}
230
230
231
- const position = { x : menuX , y : menuY }
231
+ const position = data . useMenuPosition
232
+ ? { x : menuX , y : menuY }
233
+ : { x : window . innerWidth / 2 - 300 , y : window . innerHeight / 2 - 200 }
232
234
const container = createElementAtPosition ( position . x , position . y )
233
235
container . className = 'chatgptbox-toolbar-container-not-queryable'
234
236
render (
Original file line number Diff line number Diff line change 14
14
" https://*.bing.com/"
15
15
],
16
16
"permissions" : [
17
+ " commands" ,
17
18
" cookies" ,
18
19
" storage" ,
19
20
" contextMenus"
47
48
" <all_urls>"
48
49
]
49
50
}
50
- ]
51
+ ],
52
+ "commands" : {
53
+ "newChat" : {
54
+ "suggested_key" : {
55
+ "default" : " Ctrl+B" ,
56
+ "mac" : " MacCtrl+B"
57
+ },
58
+ "description" : " Create a new chat"
59
+ },
60
+ "summarizePage" : {
61
+ "suggested_key" : {
62
+ "default" : " Alt+B" ,
63
+ "mac" : " Alt+B"
64
+ },
65
+ "description" : " Summarize this page"
66
+ }
67
+ }
51
68
}
Original file line number Diff line number Diff line change 10
10
"128" : " logo.png"
11
11
},
12
12
"permissions" : [
13
+ " commands" ,
13
14
" cookies" ,
14
15
" storage" ,
15
16
" contextMenus" ,
40
41
],
41
42
"web_accessible_resources" : [
42
43
" *.png"
43
- ]
44
+ ],
45
+ "commands" : {
46
+ "newChat" : {
47
+ "suggested_key" : {
48
+ "default" : " Ctrl+B" ,
49
+ "mac" : " MacCtrl+B"
50
+ },
51
+ "description" : " Create a new chat"
52
+ },
53
+ "summarizePage" : {
54
+ "suggested_key" : {
55
+ "default" : " Alt+B" ,
56
+ "mac" : " Alt+B"
57
+ },
58
+ "description" : " Summarize this page"
59
+ }
60
+ }
44
61
}
You can’t perform that action at this time.
0 commit comments