Skip to content

Commit 452f18e

Browse files
committed
Refactor Grok model selection logic to handle multiple selector buttons, ensure exact model label matching, add a delay for stability, and enable URL override support for Grok
1 parent 318459a commit 452f18e

3 files changed

Lines changed: 14 additions & 7 deletions

File tree

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export const grok: Chatbot = {
1818
}
1919
check_for_element()
2020
})
21+
await new Promise((r) => setTimeout(r, 500))
2122
},
2223
set_options: async (options?: string[]) => {
2324
if (!options) return
@@ -41,21 +42,23 @@ export const grok: Chatbot = {
4142
set_model: async (model?: string) => {
4243
if (!model) return
4344

44-
const model_selector_button = document.querySelector(
45+
const model_selector_buttons = document.querySelectorAll(
4546
'button[id="model-select-trigger"]'
46-
) as HTMLButtonElement
47-
if (!model_selector_button) {
47+
) as NodeListOf<HTMLButtonElement>
48+
if (!model_selector_buttons || model_selector_buttons.length == 0) {
4849
report_initialization_error({
4950
function_name: 'set_model',
5051
log_message: 'Model selector button not found'
5152
})
5253
return
5354
}
5455

56+
const model_selector_button =
57+
model_selector_buttons[model_selector_buttons.length - 1]
5558
const model_label_to_find = CHATBOTS['Grok'].models?.[model]?.label
5659
if (!model_label_to_find) return
5760

58-
if (model_selector_button.textContent?.includes(model_label_to_find)) {
61+
if (model_selector_button.textContent == model_label_to_find) {
5962
return
6063
}
6164

@@ -64,9 +67,10 @@ export const grok: Chatbot = {
6467
)
6568
await new Promise((r) => setTimeout(r, 150))
6669

67-
const dropdown = document.querySelector(
70+
const dropdowns = document.querySelectorAll(
6871
'div[data-radix-popper-content-wrapper]'
69-
) as HTMLDivElement
72+
) as NodeListOf<HTMLDivElement>
73+
const dropdown = dropdowns[dropdowns.length - 1]
7074
if (!dropdown) {
7175
report_initialization_error({
7276
function_name: 'set_model',

‎packages/browser/src/manifest.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"https://gemini.google.com/app",
3434
"https://gemini.google.com/u/*/app",
3535
"https://github.com/copilot/*",
36-
"https://grok.com/",
36+
"https://grok.com/*",
3737
"https://huggingface.co/chat/",
3838
"https://lmarena.ai/",
3939
"https://www.kimi.com/",

‎packages/shared/src/constants/chatbots.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ export const CHATBOTS = {
127127
} as Chatbot,
128128
Grok: {
129129
url: 'https://grok.com/',
130+
supports_url_override: true,
131+
url_override_label: 'Project URL',
132+
url_override_disabled_options: ['private'],
130133
supported_options: { private: 'Private' },
131134
models: {
132135
auto: { label: 'Auto' },

0 commit comments

Comments
 (0)