Skip to content

Commit 5db0fd6

Browse files
committed
Remove the "without_submission" parameter and related functionality from chat initialization across all components
1 parent efe9a70 commit 5db0fd6

34 files changed

Lines changed: 279 additions & 428 deletions

File tree

‎packages/browser/src/background/message-handler.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ const process_next_chat = async () => {
8181
options: current_chat_message.options
8282
},
8383
client_id: current_chat_message.client_id,
84-
without_submission: current_chat_message.without_submission,
8584
raw_instructions: current_chat_message.raw_instructions,
8685
mode: current_chat_message.mode
8786
}

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

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -345,13 +345,13 @@ export const ai_studio: Chatbot = {
345345
top_p_element.value = top_p.toString()
346346
top_p_element.dispatchEvent(new Event('change', { bubbles: true }))
347347
},
348-
enter_message_and_send: async (params) => {
348+
enter_message: async (params) => {
349349
const input_element = document.querySelector(
350350
'textarea[formcontrolname="promptText"]'
351351
) as HTMLTextAreaElement
352352
if (!input_element) {
353353
report_initialization_error({
354-
function_name: 'enter_message_and_send',
354+
function_name: 'enter_message',
355355
log_message: 'Message input textarea not found'
356356
})
357357
return
@@ -376,20 +376,6 @@ export const ai_studio: Chatbot = {
376376
})
377377

378378
await close_panel()
379-
380-
if (params.without_submission) return
381-
382-
const send_button = document.querySelector(
383-
'ms-run-button > button'
384-
) as HTMLElement
385-
if (!send_button) {
386-
report_initialization_error({
387-
function_name: 'enter_message_and_send',
388-
log_message: 'Send button not found'
389-
})
390-
return
391-
}
392-
send_button.click()
393379
},
394380
inject_apply_response_button: (
395381
client_id: number,

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,21 @@ export const chatgpt: Chatbot = {
116116
}
117117
}
118118
},
119+
enter_message: async (params) => {
120+
const input_element = document.querySelector(
121+
'div#prompt-textarea'
122+
) as HTMLTextAreaElement
123+
if (!input_element) {
124+
report_initialization_error({
125+
function_name: 'enter_message',
126+
log_message: 'Message input textarea not found for ChatGPT'
127+
})
128+
return
129+
}
130+
input_element.innerText = params.message
131+
input_element.dispatchEvent(new Event('input', { bubbles: true }))
132+
input_element.dispatchEvent(new Event('change', { bubbles: true }))
133+
},
119134
inject_apply_response_button: (
120135
client_id: number,
121136
raw_instructions?: string,

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

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,13 @@ export const claude: Chatbot = {
1010
wait_until_ready: async () => {
1111
await new Promise((resolve) => {
1212
const check_for_element = () => {
13-
if (document.querySelector('body[style="pointer-events: auto;"]')) {
13+
if (
14+
(
15+
document.querySelector(
16+
'main > div > div:last-child'
17+
) as HTMLDivElement
18+
).textContent
19+
) {
1420
resolve(null)
1521
} else {
1622
setTimeout(check_for_element, 100)
@@ -105,14 +111,14 @@ export const claude: Chatbot = {
105111
}
106112
}
107113
},
108-
enter_message_and_send: async (params) => {
114+
enter_message: async (params) => {
109115
const input_element = document.querySelector(
110116
'div[contenteditable=true]'
111117
) as HTMLElement
112118

113119
if (!input_element) {
114120
report_initialization_error({
115-
function_name: 'enter_message_and_send',
121+
function_name: 'enter_message',
116122
log_message: 'Message input not found'
117123
})
118124
return
@@ -121,25 +127,6 @@ export const claude: Chatbot = {
121127
input_element.innerText = params.message
122128
input_element.dispatchEvent(new Event('input', { bubbles: true }))
123129
input_element.dispatchEvent(new Event('change', { bubbles: true }))
124-
await new Promise((r) => setTimeout(r, 500))
125-
126-
if (params.without_submission) return
127-
128-
const submit_button = Array.from(
129-
document.querySelectorAll('fieldset button')
130-
).find((button) =>
131-
button.querySelector(
132-
'path[d="M208.49,120.49a12,12,0,0,1-17,0L140,69V216a12,12,0,0,1-24,0V69L64.49,120.49a12,12,0,0,1-17-17l72-72a12,12,0,0,1,17,0l72,72A12,12,0,0,1,208.49,120.49Z"]'
133-
)
134-
) as HTMLButtonElement
135-
if (!submit_button) {
136-
report_initialization_error({
137-
function_name: 'enter_message_and_send',
138-
log_message: 'Submit button not found'
139-
})
140-
return
141-
}
142-
submit_button.click()
143130
},
144131
inject_apply_response_button: (
145132
client_id: number,

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

Lines changed: 2 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -19,97 +19,20 @@ export const copilot: Chatbot = {
1919
check_for_element()
2020
})
2121
},
22-
set_model: async (chat) => {
23-
const model = chat.model
24-
if (!model) return
25-
26-
const model_selector_button = document.querySelector(
27-
'button[data-testid="composer-chat-mode-smart-button"]'
28-
) as HTMLButtonElement
29-
if (!model_selector_button) {
30-
report_initialization_error({
31-
function_name: 'set_model',
32-
log_message: 'Model selector button not found'
33-
})
34-
return
35-
}
36-
37-
const model_label_to_find = CHATBOTS['Copilot'].models?.[model]?.label
38-
if (!model_label_to_find) return
39-
40-
// The current model text is inside the button
41-
if (model_selector_button.textContent?.includes(model_label_to_find)) {
42-
return
43-
}
44-
45-
model_selector_button.click()
46-
await new Promise((r) => requestAnimationFrame(r))
47-
48-
const options_container = document.querySelector('div[id="popoverPortal"]')
49-
if (!options_container) {
50-
report_initialization_error({
51-
function_name: 'set_model',
52-
log_message: 'Model options container not found'
53-
})
54-
// click again to close
55-
model_selector_button.click()
56-
return
57-
}
58-
59-
const options = options_container.querySelectorAll(
60-
'button[role="menuitem"]'
61-
)
62-
63-
let found = false
64-
for (const option of Array.from(options)) {
65-
if (option.textContent?.includes(model_label_to_find)) {
66-
;(option as HTMLElement).click()
67-
found = true
68-
break
69-
}
70-
}
71-
72-
if (!found) {
73-
report_initialization_error({
74-
function_name: 'set_model',
75-
log_message: `Model option "${model_label_to_find}" not found`
76-
})
77-
// click again to close dropdown
78-
model_selector_button.click()
79-
}
80-
81-
await new Promise((r) => requestAnimationFrame(r))
82-
},
83-
enter_message_and_send: async (params) => {
22+
enter_message: async (params) => {
8423
const input_element = document.querySelector(
8524
'textarea'
8625
) as HTMLTextAreaElement
8726
if (!input_element) {
8827
report_initialization_error({
89-
function_name: 'enter_message_and_send',
28+
function_name: 'enter_message',
9029
log_message: 'Message input textarea not found for Copilot'
9130
})
9231
return
9332
}
9433
input_element.value = params.message
9534
input_element.dispatchEvent(new Event('input', { bubbles: true }))
9635
input_element.dispatchEvent(new Event('change', { bubbles: true }))
97-
await new Promise((r) => requestAnimationFrame(r))
98-
99-
if (params.without_submission) return
100-
101-
const send_button = document.querySelector(
102-
'button[data-testid="submit-button"]'
103-
) as HTMLElement
104-
105-
if (!send_button || send_button.hasAttribute('disabled')) {
106-
report_initialization_error({
107-
function_name: 'enter_message_and_send',
108-
log_message: 'Send button not found or disabled for Copilot'
109-
})
110-
return
111-
}
112-
send_button.click()
11336
},
11437
inject_apply_response_button: (
11538
client_id: number,

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

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ import { report_initialization_error } from '../utils/report-initialization-erro
99
export const deepseek: Chatbot = {
1010
set_options: async (chat) => {
1111
const deep_think_button = Array.from(
12-
document.querySelectorAll('button')
12+
document.querySelectorAll('div[role="button"]')
1313
).find(
1414
(button) =>
1515
button.textContent == 'DeepThink' || button.textContent == '深度思考'
16-
)
16+
) as HTMLButtonElement
1717
if (!deep_think_button) {
1818
report_initialization_error({
1919
function_name: 'set_options',
@@ -22,10 +22,12 @@ export const deepseek: Chatbot = {
2222
return
2323
}
2424

25-
const search_button = Array.from(document.querySelectorAll('button')).find(
25+
const search_button = Array.from(
26+
document.querySelectorAll('div[role="button"]')
27+
).find(
2628
(button) =>
2729
button.textContent == 'Search' || button.textContent == '联网搜索'
28-
)
30+
) as HTMLButtonElement
2931
if (!search_button) {
3032
report_initialization_error({
3133
function_name: 'set_options',
@@ -66,6 +68,21 @@ export const deepseek: Chatbot = {
6668
}
6769
await new Promise((r) => requestAnimationFrame(r))
6870
},
71+
enter_message: async (params) => {
72+
const input_element = document.querySelector(
73+
'textarea'
74+
) as HTMLTextAreaElement
75+
if (!input_element) {
76+
report_initialization_error({
77+
function_name: 'deepseek.enter_message',
78+
log_message: 'Message input textarea not found'
79+
})
80+
return
81+
}
82+
input_element.value = params.message
83+
input_element.dispatchEvent(new Event('input', { bubbles: true }))
84+
input_element.dispatchEvent(new Event('change', { bubbles: true }))
85+
},
6986
inject_apply_response_button: (
7087
client_id: number,
7188
raw_instructions?: string,

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,21 @@ export const doubao: Chatbot = {
100100
}
101101
}
102102
},
103+
enter_message: async (params) => {
104+
const input_element = document.querySelector(
105+
'textarea'
106+
) as HTMLTextAreaElement
107+
if (!input_element) {
108+
report_initialization_error({
109+
function_name: 'doubao.enter_message',
110+
log_message: 'Message input textarea not found'
111+
})
112+
return
113+
}
114+
input_element.value = params.message
115+
input_element.dispatchEvent(new Event('input', { bubbles: true }))
116+
input_element.dispatchEvent(new Event('change', { bubbles: true }))
117+
},
103118
inject_apply_response_button: (
104119
client_id: number,
105120
raw_instructions?: string,

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,22 @@ export const gemini: Chatbot = {
134134
}
135135
}
136136
},
137+
enter_message: async (params) => {
138+
const input_element = document.querySelector(
139+
'div[contenteditable="true"]'
140+
) as HTMLElement
141+
if (!input_element) {
142+
report_initialization_error({
143+
function_name: 'gemini.enter_message',
144+
log_message: 'Message input not found'
145+
})
146+
return
147+
}
148+
149+
input_element.innerText = params.message
150+
input_element.dispatchEvent(new Event('input', { bubbles: true }))
151+
input_element.dispatchEvent(new Event('change', { bubbles: true }))
152+
},
137153
inject_apply_response_button: (
138154
client_id: number,
139155
raw_instructions?: string,

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

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -81,33 +81,21 @@ export const github_copilot: Chatbot = {
8181

8282
await new Promise((r) => requestAnimationFrame(r))
8383
},
84-
enter_message_and_send: async (params) => {
84+
enter_message: async (params) => {
8585
const input_element = document.querySelector(
8686
'textarea'
8787
) as HTMLTextAreaElement
8888
if (!input_element) {
8989
report_initialization_error({
90-
function_name: 'enter_message_and_send',
90+
function_name: 'enter_message',
9191
log_message: 'Message input textarea not found for GitHub Copilot'
9292
})
9393
return
9494
}
9595
input_element.value = params.message
9696
input_element.dispatchEvent(new Event('input', { bubbles: true }))
9797
input_element.dispatchEvent(new Event('change', { bubbles: true }))
98-
await new Promise((r) => requestAnimationFrame(r))
99-
100-
if (params.without_submission) return
101-
102-
const enter_event = new KeyboardEvent('keydown', {
103-
key: 'Enter',
104-
code: 'Enter',
105-
keyCode: 13,
106-
which: 13,
107-
bubbles: true,
108-
cancelable: true
109-
})
110-
input_element.dispatchEvent(enter_event)
98+
input_element.focus()
11199
},
112100
inject_apply_response_button: (
113101
client_id: number,

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,24 @@ export const grok: Chatbot = {
8888
break
8989
}
9090
}
91-
await new Promise((r) => requestAnimationFrame(r))
91+
await new Promise((r) => setTimeout(r, 250))
92+
},
93+
enter_message: async (params) => {
94+
const input_element = document.querySelector(
95+
'div[contenteditable="true"]'
96+
) as HTMLElement
97+
if (!input_element) {
98+
report_initialization_error({
99+
function_name: 'grok.enter_message',
100+
log_message: 'Message input not found'
101+
})
102+
return
103+
}
104+
105+
input_element.textContent = params.message
106+
input_element.dispatchEvent(new Event('input', { bubbles: true }))
107+
input_element.dispatchEvent(new Event('change', { bubbles: true }))
108+
input_element.focus()
92109
},
93110
inject_apply_response_button: (
94111
client_id: number,

0 commit comments

Comments
 (0)