Skip to content

Commit c8c72f2

Browse files
committed
Simplify reasoning effort toggle logic in the Gemini content script to directly check and update extended thinking status
- Gemini's UI has changed in regards to reasoning effort. It's no longer in a nested menu. It is always initially un-checked. Check by click on the "extended thinking" button [Pasted text] - fix incoginto enabling for the updated HTML. This works: document.querySelector('temp-chat-button button').click()
1 parent 48e3f1b commit c8c72f2

1 file changed

Lines changed: 14 additions & 34 deletions

File tree

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

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

Lines changed: 14 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -110,48 +110,29 @@ export const gemini: Chatbot = {
110110
return
111111
}
112112

113-
const thinking_level_item = Array.from(
113+
const all_menu_items = Array.from(
114114
menu_content.querySelectorAll('gem-menu-item')
115-
).find(
116-
(item) => item.getAttribute('value') == 'thinking_level'
117-
) as HTMLElement
118-
119-
if (!thinking_level_item) {
120-
document.dispatchEvent(
121-
new KeyboardEvent('keydown', { key: 'Escape', bubbles: true })
122-
)
123-
return
124-
}
115+
)
125116

126-
const current_level = thinking_level_item
127-
.querySelector('.sublabel')
128-
?.textContent?.trim()
117+
const extended_thinking_item = all_menu_items.find(
118+
(item) =>
119+
item.querySelector('.label')?.textContent?.trim().toLowerCase() ==
120+
'extended thinking'
121+
) as HTMLElement
129122

130-
if (current_level?.toLowerCase() == reasoning_effort.toLowerCase()) {
123+
if (!extended_thinking_item) {
131124
document.dispatchEvent(
132125
new KeyboardEvent('keydown', { key: 'Escape', bubbles: true })
133126
)
134127
return
135128
}
136129

137-
thinking_level_item.click()
138-
await new Promise((resolve) => requestAnimationFrame(resolve))
139-
140-
const all_menu_items = Array.from(
141-
document.querySelectorAll('gem-menu-item')
142-
)
143-
let found = false
144-
for (const option of all_menu_items) {
145-
const label_element = option.querySelector('.label')
146-
const text = label_element?.textContent?.trim().toLowerCase()
147-
if (text == reasoning_effort.toLowerCase()) {
148-
;(option as HTMLElement).click()
149-
found = true
150-
break
151-
}
152-
}
130+
const is_extended = extended_thinking_item.classList.contains('selected')
131+
const target_is_extended = reasoning_effort.toLowerCase() == 'extended'
153132

154-
if (!found) {
133+
if (is_extended !== target_is_extended) {
134+
extended_thinking_item.click()
135+
} else {
155136
document.dispatchEvent(
156137
new KeyboardEvent('keydown', { key: 'Escape', bubbles: true })
157138
)
@@ -167,8 +148,7 @@ export const gemini: Chatbot = {
167148
options.includes('temporary-chat') &&
168149
supported_options?.['temporary-chat']
169150
) {
170-
const temp_chat_button_selector =
171-
'button[data-test-id="temp-chat-button"]'
151+
const temp_chat_button_selector = 'temp-chat-button button'
172152
let temp_chat_button = document.querySelector(
173153
temp_chat_button_selector
174154
) as HTMLButtonElement

0 commit comments

Comments
 (0)