Skip to content

Commit c69e81b

Browse files
committed
Refactor chatbot message submission functions to accept a parameters object instead of positional arguments, and update the Copilot content script to correctly implement
1 parent 6fb4af8 commit c69e81b

14 files changed

Lines changed: 156 additions & 161 deletions

File tree

‎packages/browser/src/content-scripts/send-prompt-content-script/chatbots/ai-studio.ts‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -367,10 +367,7 @@ export const ai_studio: Chatbot = {
367367
top_p_element.value = top_p.toString()
368368
top_p_element.dispatchEvent(new Event('change', { bubbles: true }))
369369
},
370-
enter_message_and_send: async (
371-
message: string,
372-
without_submission?: boolean
373-
) => {
370+
enter_message_and_send: async (params) => {
374371
const input_element = document.querySelector(
375372
'textarea'
376373
) as HTMLTextAreaElement
@@ -382,7 +379,7 @@ export const ai_studio: Chatbot = {
382379
})
383380
return
384381
}
385-
input_element.value = message
382+
input_element.value = params.message
386383
input_element.dispatchEvent(new Event('input', { bubbles: true }))
387384
input_element.dispatchEvent(new Event('change', { bubbles: true }))
388385
await new Promise((r) => requestAnimationFrame(r))
@@ -403,7 +400,7 @@ export const ai_studio: Chatbot = {
403400

404401
await close_panel()
405402

406-
if (without_submission) return
403+
if (params.without_submission) return
407404

408405
const send_button = document.querySelector(
409406
'ms-run-button > button'

‎packages/browser/src/content-scripts/send-prompt-content-script/chatbots/claude.ts‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,7 @@ export const claude: Chatbot = {
111111
}
112112
}
113113
},
114-
enter_message_and_send: async (
115-
message: string,
116-
without_submission?: boolean
117-
) => {
114+
enter_message_and_send: async (params) => {
118115
const input_element = document.querySelector(
119116
'div[contenteditable=true]'
120117
) as HTMLElement
@@ -128,12 +125,12 @@ export const claude: Chatbot = {
128125
return
129126
}
130127

131-
input_element.innerText = message
128+
input_element.innerText = params.message
132129
input_element.dispatchEvent(new Event('input', { bubbles: true }))
133130
input_element.dispatchEvent(new Event('change', { bubbles: true }))
134131
await new Promise((r) => setTimeout(r, 500))
135132

136-
if (without_submission) return
133+
if (params.without_submission) return
137134

138135
const submit_button = Array.from(
139136
document.querySelectorAll('fieldset button')

‎packages/browser/src/content-scripts/send-prompt-content-script/chatbots/copilot.ts‎

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,16 @@ import {
1111

1212
export const copilot: Chatbot = {
1313
wait_until_ready: async () => {
14-
await new Promise((resolve) => setTimeout(resolve, 1000))
14+
await new Promise((resolve) => {
15+
const check_for_element = () => {
16+
if (document.querySelector('textarea')) {
17+
resolve(null)
18+
} else {
19+
setTimeout(check_for_element, 100)
20+
}
21+
}
22+
check_for_element()
23+
})
1524
},
1625
set_model: async (model?: string) => {
1726
if (!model) return
@@ -77,10 +86,7 @@ export const copilot: Chatbot = {
7786

7887
await new Promise((r) => requestAnimationFrame(r))
7988
},
80-
enter_message_and_send: async (
81-
message: string,
82-
without_submission?: boolean
83-
) => {
89+
enter_message_and_send: async (params) => {
8490
const input_element = document.querySelector(
8591
'textarea'
8692
) as HTMLTextAreaElement
@@ -92,12 +98,12 @@ export const copilot: Chatbot = {
9298
})
9399
return
94100
}
95-
input_element.value = message
101+
input_element.value = params.message
96102
input_element.dispatchEvent(new Event('input', { bubbles: true }))
97103
input_element.dispatchEvent(new Event('change', { bubbles: true }))
98104
await new Promise((r) => requestAnimationFrame(r))
99105

100-
if (without_submission) return
106+
if (params.without_submission) return
101107

102108
const send_button = document.querySelector(
103109
'button[data-testid="submit-button"]'

‎packages/browser/src/content-scripts/send-prompt-content-script/chatbots/kimi.ts‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,7 @@ export const kimi: Chatbot = {
2121
check_for_element()
2222
})
2323
},
24-
enter_message_and_send: async (
25-
message: string,
26-
without_submission?: boolean
27-
) => {
24+
enter_message_and_send: async (params) => {
2825
const input_element = document.querySelector(
2926
'div[contenteditable=true]'
3027
) as HTMLElement
@@ -42,11 +39,11 @@ export const kimi: Chatbot = {
4239
bubbles: true,
4340
cancelable: true,
4441
inputType: 'insertText',
45-
data: message
42+
data: params.message
4643
})
4744
)
4845

49-
if (without_submission) return
46+
if (params.without_submission) return
5047

5148
await new Promise<void>((resolve) => {
5249
const check_button_state = () => {

‎packages/browser/src/content-scripts/send-prompt-content-script/chatbots/meta.ts‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@ export const meta: Chatbot = {
2828
check_for_element()
2929
})
3030
},
31-
enter_message_and_send: async (
32-
message: string,
33-
without_submission?: boolean
34-
) => {
31+
enter_message_and_send: async (params) => {
3532
const input_element = document.querySelector(
3633
'div[contenteditable=true]'
3734
) as HTMLElement
@@ -50,11 +47,11 @@ export const meta: Chatbot = {
5047
bubbles: true,
5148
cancelable: true,
5249
inputType: 'insertText',
53-
data: message
50+
data: params.message
5451
})
5552
)
5653

57-
if (without_submission) return
54+
if (params.without_submission) return
5855

5956
try {
6057
await new Promise<void>((resolve, reject) => {

‎packages/browser/src/content-scripts/send-prompt-content-script/chatbots/perplexity.ts‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ export const perplexity: Chatbot = {
2525
check_for_element()
2626
})
2727
},
28-
enter_message_and_send: async (
29-
message: string,
30-
without_submission?: boolean
31-
) => {
32-
let instructions = message
33-
if (message.includes('<files>')) {
34-
instructions = message.split('<files>')[0].trim()
35-
const context = message.split('<files>')[1].split('</files>')[0].trim()
28+
enter_message_and_send: async (params) => {
29+
let instructions = params.message
30+
if (params.message.includes('<files>')) {
31+
instructions = params.message.split('<files>')[0].trim()
32+
const context = params.message
33+
.split('<files>')[1]
34+
.split('</files>')[0]
35+
.trim()
3636

3737
// Upload file
3838
const file_input = document.querySelector(
@@ -88,7 +88,7 @@ export const perplexity: Chatbot = {
8888

8989
await new Promise((r) => requestAnimationFrame(r))
9090

91-
if (without_submission) return
91+
if (params.without_submission) return
9292

9393
const submit_button = document.querySelector(
9494
'button[data-testid="submit-button"]'

‎packages/browser/src/content-scripts/send-prompt-content-script/chatbots/qwen.ts‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -144,14 +144,14 @@ export const qwen: Chatbot = {
144144
}
145145
}
146146
},
147-
enter_message_and_send: async (
148-
message: string,
149-
without_submission?: boolean
150-
) => {
151-
let instructions = message
152-
if (message.includes('<files>')) {
153-
instructions = message.split('<files>')[0].trim()
154-
const context = message.split('<files>')[1].split('</files>')[0].trim()
147+
enter_message_and_send: async (params) => {
148+
let instructions = params.message
149+
if (params.message.includes('<files>')) {
150+
instructions = params.message.split('<files>')[0].trim()
151+
const context = params.message
152+
.split('<files>')[1]
153+
.split('</files>')[0]
154+
.trim()
155155

156156
// Upload file
157157
const file_input = document.querySelector(
@@ -201,7 +201,7 @@ export const qwen: Chatbot = {
201201
input_element.dispatchEvent(new Event('change', { bubbles: true }))
202202
await new Promise((r) => requestAnimationFrame(r))
203203

204-
if (without_submission) return
204+
if (params.without_submission) return
205205

206206
// Submit
207207
const submit_button = document.querySelector(

‎packages/browser/src/content-scripts/send-prompt-content-script/send-prompt-content-script.ts‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ export const get_textarea_element = () => {
130130
[ai_studio_url]: 'textarea',
131131
[gemini_url]: 'div[contenteditable="true"]',
132132
[openrouter_url]: 'textarea',
133-
[meta_url]: 'div[contenteditable="true"]',
134133
[chatgpt_url]: 'div#prompt-textarea',
135134
[copilot_url]: 'textarea',
136135
[grok_url]: 'textarea',
@@ -237,10 +236,10 @@ const initialize_chat = async (params: {
237236
await chatbot.set_options(params.chat.options || [])
238237
}
239238
if (chatbot?.enter_message_and_send) {
240-
await chatbot.enter_message_and_send(
241-
params.message,
242-
params.without_submission
243-
)
239+
await chatbot.enter_message_and_send({
240+
message: params.message,
241+
without_submission: params.without_submission
242+
})
244243
} else {
245244
await enter_message_and_send({
246245
input_element: get_textarea_element(),

‎packages/browser/src/content-scripts/send-prompt-content-script/types/chatbot.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ export type Chatbot = {
1111
client_id: number,
1212
raw_instructions?: string
1313
) => void
14-
enter_message_and_send?: (
15-
message: string,
14+
enter_message_and_send?: (params: {
15+
message: string
1616
without_submission?: boolean
17-
) => Promise<void>
17+
}) => Promise<void>
1818
}

‎packages/browser/src/manifest.json‎

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,24 @@
2525
{
2626
"matches": [
2727
"https://aistudio.google.com/prompts/new_chat",
28-
"https://gemini.google.com/app",
29-
"https://gemini.google.com/u/*/app",
30-
"https://openrouter.ai/chat*",
3128
"https://chatgpt.com/",
32-
"https://copilot.microsoft.com/",
3329
"https://claude.ai/new",
34-
"https://grok.com/",
30+
"https://copilot.microsoft.com/",
3531
"https://chat.deepseek.com/",
32+
"https://www.doubao.com/chat/",
33+
"https://gemini.google.com/app",
34+
"https://gemini.google.com/u/*/app",
35+
"https://grok.com/",
36+
"https://www.kimi.com/",
3637
"https://chat.mistral.ai/chat",
37-
"https://www.meta.ai/",
38+
"http://openwebui/",
39+
"https://openrouter.ai/chat*",
40+
"https://www.perplexity.ai/",
3841
"https://chat.qwen.ai/",
42+
"https://chat.together.ai/",
3943
"https://yuanbao.tencent.com/chat*",
40-
"https://www.doubao.com/chat/",
41-
"https://www.perplexity.ai/",
42-
"https://www.kimi.com/",
4344
"https://chat.z.ai/",
44-
"https://chat.together.ai/",
45-
"http://localhost/",
46-
"http://openwebui/"
45+
"http://localhost/"
4746
],
4847
"js": ["send-prompt-content-script.js"]
4948
}

0 commit comments

Comments
 (0)