Skip to content

Commit ec193b9

Browse files
committed
Update Grok chatbot DOM selectors and interaction logic
- [Pasted text] dropdown opened though: [Pasted text] - [Pasted text] - find by looking for butotn with given svg path [Pasted text] - when model selector is aleady on correct model, it should not be clicked, e.g. here is on Fast already [Pasted text]
1 parent f594c7d commit ec193b9

1 file changed

Lines changed: 30 additions & 11 deletions

File tree

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

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

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,24 @@ export const grok: Chatbot = {
3636
const model_label = CHATBOTS['Grok'].models[model].label
3737
const target_label_lower = model_label.toLowerCase()
3838

39+
const current_text =
40+
model_selector_trigger.textContent?.toLowerCase() || ''
41+
const current_aria =
42+
model_selector_trigger.getAttribute('aria-label')?.toLowerCase() || ''
43+
44+
if (
45+
current_text.includes(target_label_lower) ||
46+
current_aria.includes(target_label_lower)
47+
) {
48+
return
49+
}
50+
3951
model_selector_trigger.click()
4052
await new Promise((r) => requestAnimationFrame(r))
4153

4254
const menu_items = Array.from(
4355
document.querySelectorAll(
44-
'[data-radix-menu-content] [role="menuitemradio"]'
56+
'[role="menuitemradio"], [role="menuitemcheckbox"]'
4557
)
4658
)
4759
let found = false
@@ -71,17 +83,26 @@ export const grok: Chatbot = {
7183
const supported_options = CHATBOTS['Grok'].supported_options
7284
for (const option of options) {
7385
if (option === 'private' && supported_options?.['private']) {
74-
const private_link = document.querySelector(
75-
'a[href="/c#private"]'
76-
) as HTMLAnchorElement
77-
if (!private_link) {
86+
const private_button = Array.from(
87+
document.querySelectorAll('button')
88+
).find((btn) =>
89+
btn.querySelector(
90+
'path[d="M2.24 11.64 L2.24 21.28 Q2.24 21.76 2.72 21.76 L12.4 21.76 A10.16 10.16 0 1 0 2.24 11.64 Z"]'
91+
)
92+
)
93+
if (!private_button) {
7894
report_initialization_error({
7995
function_name: 'set_options',
80-
log_message: 'Private mode link not found'
96+
log_message: 'Private mode button not found'
8197
})
8298
return
8399
}
84-
private_link.click()
100+
101+
const is_pressed =
102+
private_button.getAttribute('aria-pressed') === 'true'
103+
if (!is_pressed) {
104+
private_button.click()
105+
}
85106
}
86107
}
87108
},
@@ -128,10 +149,8 @@ export const grok: Chatbot = {
128149
observe_for_responses({
129150
chatbot_name: 'Grok',
130151
is_generating: () =>
131-
!!document.querySelector(
132-
'path[d="M4 9.2v5.6c0 1.116 0 1.673.11 2.134a4 4 0 0 0 2.956 2.956c.46.11 1.018.11 2.134.11h5.6c1.116 0 1.673 0 2.134-.11a4 4 0 0 0 2.956-2.956c.11-.46.11-1.018.11-2.134V9.2c0-1.116 0-1.673-.11-2.134a4 4 0 0 0-2.956-2.955C16.474 4 15.916 4 14.8 4H9.2c-1.116 0-1.673 0-2.134.11a4 4 0 0 0-2.955 2.956C4 7.526 4 8.084 4 9.2Z"]'
133-
),
134-
footer_selector: 'div.items-start div.action-buttons > div',
152+
!!document.querySelector('div[data-testid="composer-stop"]'),
153+
footer_selector: 'div[role="article"] + div > div[role="toolbar"]',
135154
add_buttons: params.inject_button ? add_buttons : undefined
136155
})
137156
}

0 commit comments

Comments
 (0)