@@ -25,6 +25,23 @@ const show_options_modal = async (function_name: string) => {
2525 }
2626 options_button . click ( )
2727 await new Promise ( ( r ) => requestAnimationFrame ( r ) )
28+
29+ const advanced_settings_button = Array . from (
30+ document . querySelectorAll ( 'div[role="dialog"] button' )
31+ ) . find (
32+ ( button ) => button . textContent ?. trim ( ) == 'Advanced Settings'
33+ ) as HTMLButtonElement
34+
35+ if ( ! advanced_settings_button ) {
36+ report_initialization_error ( {
37+ function_name,
38+ log_message : 'Advanced settings button not found'
39+ } )
40+ return false
41+ }
42+
43+ advanced_settings_button . click ( )
44+ await new Promise ( ( r ) => requestAnimationFrame ( r ) )
2845 return true
2946}
3047
@@ -74,10 +91,11 @@ export const openrouter: Chatbot = {
7491 await close_options_modal ( 'enter_system_instructions' )
7592 return
7693 }
77- const custom_system_instructions_button =
78- textarea . parentElement ?. parentElement ?. querySelector (
79- 'div > button:last-child'
80- )
94+ const custom_system_instructions_button = Array . from (
95+ document . querySelectorAll ( 'div[role="dialog"] button' )
96+ ) . find (
97+ ( button ) => button . textContent ?. trim ( ) == 'Custom'
98+ ) as HTMLButtonElement
8199 if ( ! custom_system_instructions_button ) {
82100 report_initialization_error ( {
83101 function_name : 'enter_system_instructions' ,
@@ -86,11 +104,29 @@ export const openrouter: Chatbot = {
86104 await close_options_modal ( 'enter_system_instructions' )
87105 return
88106 }
89- ; ( custom_system_instructions_button as HTMLElement ) ? .click ( )
107+ custom_system_instructions_button . click ( )
90108 await new Promise ( ( r ) => requestAnimationFrame ( r ) )
91- textarea . focus ( )
92- textarea . value = system_instructions
93- textarea . blur ( )
109+
110+ const active_textarea = document . querySelector (
111+ 'div[role="dialog"] textarea'
112+ ) as HTMLTextAreaElement
113+ if ( ! active_textarea ) {
114+ report_initialization_error ( {
115+ function_name : 'enter_system_instructions' ,
116+ log_message : 'System instructions textarea disappeared'
117+ } )
118+ await close_options_modal ( 'enter_system_instructions' )
119+ return
120+ }
121+
122+ active_textarea . focus ( )
123+ const nativeTextAreaValueSetter = Object . getOwnPropertyDescriptor (
124+ window . HTMLTextAreaElement . prototype ,
125+ 'value'
126+ ) ?. set
127+ nativeTextAreaValueSetter ?. call ( active_textarea , system_instructions )
128+ active_textarea . dispatchEvent ( new Event ( 'input' , { bubbles : true } ) )
129+ active_textarea . blur ( )
94130 await close_options_modal ( 'enter_system_instructions' )
95131 } ,
96132 set_options : async ( chat ) => {
@@ -104,7 +140,7 @@ export const openrouter: Chatbot = {
104140 // Only some models support this option
105141 if ( reasoning_toggle ) {
106142 if ( options . includes ( 'disable-reasoning' ) ) {
107- if ( reasoning_toggle . getAttribute ( 'data-state' ) == ' checked') {
143+ if ( reasoning_toggle . hasAttribute ( 'data-checked' ) ) {
108144 reasoning_toggle . click ( )
109145 }
110146 }
@@ -156,7 +192,12 @@ export const openrouter: Chatbot = {
156192 return
157193 }
158194 temperature_input . focus ( )
159- temperature_input . value = temperature . toString ( )
195+ const nativeInputValueSetter = Object . getOwnPropertyDescriptor (
196+ window . HTMLInputElement . prototype ,
197+ 'value'
198+ ) ?. set
199+ nativeInputValueSetter ?. call ( temperature_input , temperature . toString ( ) )
200+ temperature_input . dispatchEvent ( new Event ( 'input' , { bubbles : true } ) )
160201 temperature_input . blur ( )
161202 await close_options_modal ( 'set_temperature' )
162203 } ,
@@ -202,7 +243,12 @@ export const openrouter: Chatbot = {
202243 return
203244 }
204245 top_p_input . focus ( )
205- top_p_input . value = top_p . toString ( )
246+ const nativeInputValueSetter = Object . getOwnPropertyDescriptor (
247+ window . HTMLInputElement . prototype ,
248+ 'value'
249+ ) ?. set
250+ nativeInputValueSetter ?. call ( top_p_input , top_p . toString ( ) )
251+ top_p_input . dispatchEvent ( new Event ( 'input' , { bubbles : true } ) )
206252 top_p_input . blur ( )
207253 await close_options_modal ( 'set_top_p' )
208254 } ,
@@ -221,7 +267,7 @@ export const openrouter: Chatbot = {
221267
222268 const reasoning_button = Array . from ( dialog . querySelectorAll ( 'button' ) ) . find (
223269 ( button ) =>
224- [ 'Minimal' , 'Low' , 'Medium' , 'High' ] . includes (
270+ [ 'None' , ' Minimal', 'Low' , 'Medium' , 'High' , 'XHigh' , 'Max '] . includes (
225271 button . textContent ?. trim ( ) || ''
226272 )
227273 ) as HTMLButtonElement
@@ -231,25 +277,29 @@ export const openrouter: Chatbot = {
231277 return
232278 }
233279
234- if ( reasoning_button . textContent != reasoning_effort ) {
280+ if (
281+ reasoning_button . textContent ?. trim ( ) . toLowerCase ( ) !==
282+ reasoning_effort . toLowerCase ( )
283+ ) {
235284 reasoning_button . click ( )
236285 await new Promise ( ( resolve ) => setTimeout ( resolve , 500 ) ) // Opening animation must finish
237- const dropdown = document . querySelector (
238- 'div[data-radix-popper-content-wrapper]'
239- )
240- if ( ! dropdown ) {
286+
287+ const options = document . querySelectorAll ( 'div[role="option"]' )
288+ if ( options . length === 0 ) {
241289 report_initialization_error ( {
242290 function_name : 'set_reasoning_effort' ,
243- log_message : 'Reasoning effort dropdown not found'
291+ log_message : 'Reasoning effort options not found'
244292 } )
245293 await close_options_modal ( 'set_reasoning_effort' )
246294 return
247295 }
248296
249- const options = dropdown . querySelectorAll ( 'div[role="option"]' )
250297 let found = false
251298 for ( const option of Array . from ( options ) ) {
252- if ( option . textContent . toLowerCase ( ) == reasoning_effort ) {
299+ if (
300+ option . textContent ?. trim ( ) . toLowerCase ( ) ===
301+ reasoning_effort . toLowerCase ( )
302+ ) {
253303 ; ( option as HTMLElement ) . click ( )
254304 found = true
255305 break
0 commit comments