@@ -19,6 +19,52 @@ export const grok: Chatbot = {
1919 check_for_element ( )
2020 } )
2121 } ,
22+ set_model : async ( chat ) => {
23+ const model = chat . model
24+ if ( model && CHATBOTS [ 'Grok' ] . models && model in CHATBOTS [ 'Grok' ] . models ) {
25+ const model_selector_trigger = document . querySelector (
26+ 'button#model-select-trigger'
27+ ) as HTMLButtonElement
28+ if ( ! model_selector_trigger ) {
29+ report_initialization_error ( {
30+ function_name : 'set_model' ,
31+ log_message : 'Model selector trigger not found'
32+ } )
33+ return
34+ }
35+
36+ const model_label = CHATBOTS [ 'Grok' ] . models [ model ] . label
37+ const target_label_lower = model_label . toLowerCase ( )
38+
39+ model_selector_trigger . click ( )
40+ await new Promise ( ( r ) => requestAnimationFrame ( r ) )
41+
42+ const menu_items = Array . from (
43+ document . querySelectorAll (
44+ '[data-radix-menu-content] [role="menuitemradio"]'
45+ )
46+ )
47+ let found = false
48+ for ( const item of menu_items ) {
49+ const text = item . textContent ?. trim ( ) . toLowerCase ( )
50+ if ( text && text . includes ( target_label_lower ) ) {
51+ const is_checked = item . getAttribute ( 'aria-checked' ) == 'true'
52+ if ( ! is_checked ) {
53+ ; ( item as HTMLElement ) . click ( )
54+ }
55+ found = true
56+ break
57+ }
58+ }
59+ if ( ! found ) {
60+ report_initialization_error ( {
61+ function_name : 'set_model' ,
62+ log_message : `Model option for "${ model_label } " not found`
63+ } )
64+ }
65+ await new Promise ( ( r ) => requestAnimationFrame ( r ) )
66+ }
67+ } ,
2268 set_options : async ( chat ) => {
2369 const options = chat . options
2470 if ( ! options ) return
0 commit comments