@@ -7,47 +7,43 @@ import {
77import { report_initialization_error } from '../utils/report-initialization-error'
88
99const show_options_modal = async ( function_name : string ) => {
10- const options_button = Array . from (
11- document . querySelectorAll ( 'main > div > div > div.flex-col button' )
12- ) . find ( ( button ) => {
13- const path = button . querySelector ( 'path' )
14- return (
15- path ?. getAttribute ( 'd' ) ==
16- 'M12 6.75a.75.75 0 1 1 0-1.5.75.75 0 0 1 0 1.5ZM12 12.75a.75.75 0 1 1 0-1.5.75.75 0 0 1 0 1.5ZM12 18.75a.75.75 0 1 1 0-1.5.75.75 0 0 1 0 1.5Z'
17- )
18- } ) as HTMLButtonElement
19- if ( ! options_button ) {
10+ const model_button = document . querySelector (
11+ 'div[role="button"][aria-haspopup="dialog"]'
12+ ) as HTMLDivElement
13+ if ( ! model_button ) {
2014 report_initialization_error ( {
2115 function_name,
22- log_message : 'Options button not found'
16+ log_message : 'Model button not found'
2317 } )
2418 return false
2519 }
26- options_button . click ( )
20+ model_button . click ( )
2721 await new Promise ( ( r ) => requestAnimationFrame ( r ) )
28-
2922 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-
23+ document . querySelectorAll ( '[data-side="bottom"] button' )
24+ ) . find ( ( button ) => {
25+ const path = button . querySelector ( 'path' )
26+ return (
27+ path ?. getAttribute ( 'd' ) ==
28+ 'M10.5 6h9.75M10.5 6a1.5 1.5 0 1 1-3 0m3 0a1.5 1.5 0 1 0-3 0M3.75 6H7.5m3 12h9.75m-9.75 0a1.5 1.5 0 0 1-3 0m3 0a1.5 1.5 0 0 0-3 0m-3.75 0H7.5m9-6h3.75m-3.75 0a1.5 1.5 0 0 1-3 0m3 0a1.5 1.5 0 0 0-3 0m-9.75 0h9.75'
29+ )
30+ } ) as HTMLButtonElement
3531 if ( ! advanced_settings_button ) {
3632 report_initialization_error ( {
3733 function_name,
3834 log_message : 'Advanced settings button not found'
3935 } )
4036 return false
4137 }
42-
4338 advanced_settings_button . click ( )
39+
4440 await new Promise ( ( r ) => requestAnimationFrame ( r ) )
4541 return true
4642}
4743
4844const close_options_modal = async ( function_name : string ) => {
4945 const close_button = document . querySelector (
50- 'div[role ="dialog"] button [data-slot="dialog-close"] '
46+ '[data-slot ="dialog-viewport "] [data-base-ui-focusable][data-open] > button '
5147 ) as HTMLButtonElement
5248 if ( ! close_button ) {
5349 report_initialization_error ( {
@@ -129,30 +125,12 @@ export const openrouter: Chatbot = {
129125 active_textarea . blur ( )
130126 await close_options_modal ( 'enter_system_instructions' )
131127 } ,
132- set_options : async ( chat ) => {
133- const options = chat . options
134- if ( ! options ) return
135- if ( ! ( await show_options_modal ( 'set_options' ) ) ) return
136- const reasoning_toggle = document . querySelector (
137- 'button[id^="toggle-reasoning-char-"]'
138- ) as HTMLButtonElement
139-
140- // Only some models support this option
141- if ( reasoning_toggle ) {
142- if ( options . includes ( 'disable-reasoning' ) ) {
143- if ( reasoning_toggle . hasAttribute ( 'data-checked' ) ) {
144- reasoning_toggle . click ( )
145- }
146- }
147- }
148-
149- await close_options_modal ( 'set_options' )
150- } ,
151128 set_reasoning_effort : async ( chat ) => {
152- const reasoning_effort = chat . reasoning_effort
153- if ( ! reasoning_effort ) return
129+ if ( ! chat . reasoning_effort ) return
154130 if ( ! ( await show_options_modal ( 'set_reasoning_effort' ) ) ) return
155- const dialog = document . querySelector ( 'div[role="dialog"]' )
131+ const dialog = document . querySelector (
132+ '[data-slot="dialog-viewport"] [data-base-ui-focusable][data-open]'
133+ )
156134 if ( ! dialog ) {
157135 report_initialization_error ( {
158136 function_name : 'set_reasoning_effort' ,
@@ -175,10 +153,10 @@ export const openrouter: Chatbot = {
175153
176154 if (
177155 reasoning_button . textContent ?. trim ( ) . toLowerCase ( ) !==
178- reasoning_effort . toLowerCase ( )
156+ chat . reasoning_effort . toLowerCase ( )
179157 ) {
180158 reasoning_button . click ( )
181- await new Promise ( ( resolve ) => setTimeout ( resolve , 500 ) ) // Opening animation must finish
159+ await new Promise ( ( r ) => requestAnimationFrame ( r ) )
182160
183161 const options = document . querySelectorAll ( 'div[role="option"]' )
184162 if ( options . length === 0 ) {
@@ -194,7 +172,7 @@ export const openrouter: Chatbot = {
194172 for ( const option of Array . from ( options ) ) {
195173 if (
196174 option . textContent ?. trim ( ) . toLowerCase ( ) ===
197- reasoning_effort . toLowerCase ( )
175+ chat . reasoning_effort . toLowerCase ( )
198176 ) {
199177 ; ( option as HTMLElement ) . click ( )
200178 found = true
@@ -205,7 +183,7 @@ export const openrouter: Chatbot = {
205183 if ( ! found ) {
206184 report_initialization_error ( {
207185 function_name : 'set_reasoning_effort' ,
208- log_message : `Reasoning effort option "${ reasoning_effort } " not found`
186+ log_message : `Reasoning effort option "${ chat . reasoning_effort } " not found`
209187 } )
210188 }
211189 }
0 commit comments