Skip to content

Commit 8549d68

Browse files
committed
Adapt content scripts for Grok and OpenRouter to accommodate recent UI updates and feature changes
1 parent 8fd59b3 commit 8549d68

5 files changed

Lines changed: 34 additions & 57 deletions

File tree

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

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export const grok: Chatbot = {
1717
wait_until_ready: async () => {
1818
await new Promise((resolve) => {
1919
const check_for_element = () => {
20-
if (document.querySelector('button[aria-label="Think"]')) {
20+
if (document.querySelector('textarea')) {
2121
resolve(null)
2222
} else {
2323
setTimeout(check_for_element, 100)
@@ -35,41 +35,34 @@ export const grok: Chatbot = {
3535
'a[href="/chat#private"]'
3636
) as HTMLAnchorElement
3737
private_link.click()
38-
} else if (option == 'think' && supported_options['think']) {
39-
const think_button = document.querySelector(
40-
'button[aria-label="Think"]'
41-
) as HTMLButtonElement
42-
if (think_button) {
43-
think_button.click()
44-
}
4538
}
4639
}
4740
},
4841
set_model: async (model?: string) => {
4942
if (!model) return
43+
5044
const model_selector_button = document.querySelector(
51-
'form > div > div > div:last-child > div > div:last-child > button'
45+
'button[id="model-select-trigger"]'
5246
) as HTMLButtonElement
53-
if (!model_selector_button) return
5447

55-
const model_name_to_find = (CHATBOTS['Grok'].models as any)[model]?.label
56-
if (!model_name_to_find) return
48+
const model_label_to_find = (CHATBOTS['Grok'].models as any)[model]?.label
49+
if (!model_label_to_find) return
5750

58-
if (model_selector_button.textContent == model_name_to_find) return
51+
if (model_selector_button.textContent?.includes(model_label_to_find)) {
52+
return
53+
}
5954

6055
model_selector_button.click()
6156
await new Promise((r) => requestAnimationFrame(r))
6257

6358
const dropdown = document.querySelector(
6459
'div[data-radix-popper-content-wrapper]'
65-
)
66-
if (!dropdown) return
67-
68-
const menu_items = dropdown.querySelectorAll('div[role="menuitem"]')
60+
) as HTMLDivElement
6961

70-
for (const item of Array.from(menu_items)) {
71-
if (item.textContent?.includes(model_name_to_find)) {
72-
;(item as HTMLElement).click()
62+
const options = dropdown.querySelectorAll('div[role="option"]')
63+
for (const option of Array.from(options)) {
64+
if (option.textContent?.startsWith(model_label_to_find)) {
65+
;(option as HTMLElement).click()
7366
break
7467
}
7568
}

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

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,15 @@ export const openrouter: Chatbot = {
4040
options_button.click()
4141
await new Promise((r) => requestAnimationFrame(r))
4242
const textarea = document.querySelector(
43-
'div[data-headlessui-portal] textarea'
43+
'div[role="dialog"] textarea'
4444
) as HTMLTextAreaElement
4545
textarea.focus()
4646
textarea.value = system_instructions
4747
textarea.dispatchEvent(new Event('change', { bubbles: true }))
4848
textarea.blur()
49-
const close_button = Array.from(
50-
document.querySelectorAll('div[data-headlessui-portal] button')
51-
).find((button) => {
52-
const path = button.querySelector('path')
53-
return (
54-
path?.getAttribute('d') ==
55-
'm9.75 9.75 4.5 4.5m0-4.5-4.5 4.5M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z'
56-
)
57-
}) as HTMLButtonElement
49+
const close_button = document.querySelector(
50+
'div[role="dialog"] button[data-slot="dialog-close"]'
51+
) as HTMLButtonElement
5852
close_button.click()
5953
},
6054
set_temperature: async (temperature?: number) => {
@@ -71,15 +65,15 @@ export const openrouter: Chatbot = {
7165
options_button.click()
7266
await new Promise((r) => requestAnimationFrame(r))
7367
const sampling_parameters_button = Array.from(
74-
document.querySelectorAll('div[data-headlessui-portal] button')
68+
document.querySelectorAll('div[role="dialog"] button')
7569
).find(
7670
(button) => button.textContent?.trim() == 'Sampling Parameters'
7771
) as HTMLButtonElement
7872
sampling_parameters_button.click()
7973
await new Promise((r) => requestAnimationFrame(r))
8074
const temperature_div = Array.from(
8175
document.querySelectorAll(
82-
'div[data-headlessui-portal] div.flex.justify-between.text-sm'
76+
'div[role="dialog"] div.flex.justify-between.text-sm'
8377
)
8478
).find((div) => div.textContent?.trim() == 'Temperature') as HTMLElement
8579
const temperature_input = temperature_div.querySelector(
@@ -89,15 +83,9 @@ export const openrouter: Chatbot = {
8983
temperature_input.value = temperature.toString()
9084
temperature_input.dispatchEvent(new Event('change', { bubbles: true }))
9185
temperature_input.blur()
92-
const close_button = Array.from(
93-
document.querySelectorAll('div[data-headlessui-portal] button')
94-
).find((button) => {
95-
const path = button.querySelector('path')
96-
return (
97-
path?.getAttribute('d') ==
98-
'm9.75 9.75 4.5 4.5m0-4.5-4.5 4.5M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z'
99-
)
100-
}) as HTMLButtonElement
86+
const close_button = document.querySelector(
87+
'div[role="dialog"] button[data-slot="dialog-close"]'
88+
) as HTMLButtonElement
10189
close_button.click()
10290
},
10391
set_top_p: async (top_p?: number) => {
@@ -114,31 +102,25 @@ export const openrouter: Chatbot = {
114102
options_button.click()
115103
await new Promise((r) => requestAnimationFrame(r))
116104
const sampling_parameters_button = Array.from(
117-
document.querySelectorAll('div[data-headlessui-portal] button')
105+
document.querySelectorAll('div[role="dialog"] button')
118106
).find(
119107
(button) => button.textContent?.trim() == 'Sampling Parameters'
120108
) as HTMLButtonElement
121109
sampling_parameters_button.click()
122110
await new Promise((r) => requestAnimationFrame(r))
123111
const top_p_div = Array.from(
124112
document.querySelectorAll(
125-
'div[data-headlessui-portal] div.flex.justify-between.text-sm'
113+
'div[role="dialog"] div.flex.justify-between.text-sm'
126114
)
127115
).find((div) => div.textContent?.trim() == 'Top P') as HTMLElement
128116
const top_p_input = top_p_div.querySelector('input') as HTMLInputElement
129117
top_p_input.focus()
130118
top_p_input.value = top_p.toString()
131119
top_p_input.dispatchEvent(new Event('change', { bubbles: true }))
132120
top_p_input.blur()
133-
const close_button = Array.from(
134-
document.querySelectorAll('div[data-headlessui-portal] button')
135-
).find((button) => {
136-
const path = button.querySelector('path')
137-
return (
138-
path?.getAttribute('d') ==
139-
'm9.75 9.75 4.5 4.5m0-4.5-4.5 4.5M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z'
140-
)
141-
}) as HTMLButtonElement
121+
const close_button = document.querySelector(
122+
'div[role="dialog"] button[data-slot="dialog-close"]'
123+
) as HTMLButtonElement
142124
close_button.click()
143125
},
144126
inject_apply_response_button: (client_id: number) => {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ export const get_textarea_element = () => {
126126
[openrouter_url]: 'textarea',
127127
[meta_url]: 'div[contenteditable="true"]',
128128
[chatgpt_url]: 'div#prompt-textarea',
129+
[grok_url]: 'textarea',
129130
[deepseek_url]: 'textarea',
130131
[mistral_url]: 'div[contenteditable="true"]',
131132
[yuanbao_url]: 'div[contenteditable="true"]',

packages/browser/src/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"name": "Code Web Chat Connector",
55
"short_name": "CWC",
66
"description": "Initialize 15+ free chatbots with your code and instructions. Parse websites into markdown to include in context.",
7-
"version": "1.25.0",
7+
"version": "1.26.0",
88
"homepage_url": "https://github.com/robertpiosik/CodeWebChat",
99
"icons": {
1010
"16": "icons/icon-16.png",

packages/shared/src/constants/chatbots.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,13 @@ export const CHATBOTS = {
133133
supports_user_provided_port: false,
134134
supports_thinking_budget: false,
135135
default_system_instructions: '',
136-
supported_options: { think: 'Think', private: 'Private' },
136+
supported_options: { private: 'Private' },
137137
default_top_p: 0,
138138
models: {
139-
'grok-3': { label: 'Grok 3' },
140-
'grok-4': { label: 'Grok 4' },
141-
'grok-4-heavy': { label: 'Grok 4 Heavy' }
139+
auto: { label: 'Auto' },
140+
fast: { label: 'Fast' },
141+
expert: { label: 'Expert' },
142+
heavy: { label: 'Heavy' }
142143
}
143144
},
144145
Kimi: {

0 commit comments

Comments
 (0)