Skip to content

Commit 73df562

Browse files
committed
Update Mistral chatbot UI selectors and mode toggling logic
- at all times click mode toggler and select between fast and think in the dropdown (fast is first menuitem, think is second menuitem). Dropdown mounted at body: [Pasted text] - replace [Fragment] with mouse down event - this [Fragment] and mode_toggler.click doesn;t work, suggest other approach ├── apps │ └── browser │ └── src │ └── content-scripts │ └── send-prompt-content-script │ └── chatbots │ └── mistral.ts └── packages └── shared └── src └── constants └── chatbots.ts
1 parent 20dadc0 commit 73df562

1 file changed

Lines changed: 35 additions & 18 deletions

File tree

  • apps/browser/src/content-scripts/send-prompt-content-script/chatbots

‎apps/browser/src/content-scripts/send-prompt-content-script/chatbots/mistral.ts‎

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@ export const mistral: Chatbot = {
2121
},
2222
set_options: async (chat) => {
2323
const options = chat.options
24-
if (!options) return
2524

2625
if (
27-
options.includes('incognito') &&
26+
options?.includes('incognito') &&
2827
!window.location.pathname.includes('/incognito')
2928
) {
3029
const incognito_button = document.querySelector(
@@ -41,36 +40,57 @@ export const mistral: Chatbot = {
4140
}
4241
}
4342

44-
const think_button_icon_path = document.querySelector(
45-
'path[d="M9 18h6"]'
43+
const mode_toggler_icon_path = document.querySelector(
44+
'form path[d="M16 10.5L12 14.5L8 10.5"]'
4645
) as SVGPathElement
4746

48-
if (!think_button_icon_path) {
47+
if (!mode_toggler_icon_path) {
4948
report_initialization_error({
5049
function_name: 'set_options',
5150
log_message: 'Think button icon not found'
5251
})
5352
return
5453
}
5554

56-
const think_button = think_button_icon_path.closest(
55+
const mode_toggler = mode_toggler_icon_path.closest(
5756
'button'
5857
) as HTMLButtonElement
5958

60-
if (!think_button) {
59+
if (!mode_toggler) {
6160
report_initialization_error({
6261
function_name: 'set_options',
6362
log_message: 'Think button not found'
6463
})
6564
return
6665
}
6766

68-
const should_be_on = options.includes('think')
69-
const is_on = think_button.getAttribute('data-state') == 'on'
67+
mode_toggler.dispatchEvent(new MouseEvent('pointerdown', { bubbles: true }))
68+
await new Promise((resolve) => requestAnimationFrame(resolve))
7069

71-
if (should_be_on != is_on) {
72-
think_button.click()
73-
await new Promise((r) => requestAnimationFrame(r))
70+
const menuitems = document.querySelectorAll('div[role="menuitem"]')
71+
72+
if (options?.includes('think')) {
73+
const think_item = menuitems[1] as HTMLElement
74+
if (think_item) {
75+
think_item.click()
76+
await new Promise((resolve) => requestAnimationFrame(resolve))
77+
} else {
78+
report_initialization_error({
79+
function_name: 'set_options',
80+
log_message: 'Think menu item not found'
81+
})
82+
}
83+
} else {
84+
const fast_item = menuitems[0] as HTMLElement
85+
if (fast_item) {
86+
fast_item.click()
87+
await new Promise((resolve) => requestAnimationFrame(resolve))
88+
} else {
89+
report_initialization_error({
90+
function_name: 'set_options',
91+
log_message: 'Fast menu item not found'
92+
})
93+
}
7494
}
7595
},
7696
enter_message: async (params) => {
@@ -95,13 +115,10 @@ export const mistral: Chatbot = {
95115
client_id: params.client_id,
96116
raw_instructions: params.raw_instructions,
97117
footer,
98-
get_chat_turn: (f) =>
99-
f.parentElement?.parentElement?.querySelector(
100-
'div[data-message-part-type="answer"]'
101-
) as HTMLElement,
118+
get_chat_turn: (f) => f.parentElement!.parentElement!,
102119
perform_copy: (f) => {
103120
const copy_button = f.querySelector(
104-
'button:last-child'
121+
'button:nth-child(6)'
105122
) as HTMLElement
106123
if (!copy_button) {
107124
report_initialization_error({
@@ -124,7 +141,7 @@ export const mistral: Chatbot = {
124141
}
125142

126143
const footer_selector =
127-
'div[data-message-author-role="assistant"] > div:last-child > div:last-child > div:last-child'
144+
'div[data-message-author-role="assistant"] > div + div > div:last-child > div:first-child'
128145

129146
requestAnimationFrame(() => {
130147
observe_for_responses({

0 commit comments

Comments
 (0)