File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -100,18 +100,21 @@ async function getInput(inputQuery) {
100100}
101101
102102async function overwriteAccessToken ( ) {
103- if ( location . hostname !== 'chat.openai.com' || location . pathname !== '/api/auth/session' ) return
104-
105- const response = document . querySelector ( 'pre' ) . textContent
103+ if ( location . hostname !== 'chat.openai.com' ) return
106104
107105 let data
108- try {
109- data = JSON . parse ( response )
110- } catch ( error ) {
111- console . error ( 'json error' , error )
112- return
106+ if ( location . pathname === '/api/auth/session' ) {
107+ const response = document . querySelector ( 'pre' ) . textContent
108+ try {
109+ data = JSON . parse ( response )
110+ } catch ( error ) {
111+ console . error ( 'json error' , error )
112+ }
113+ } else {
114+ const resp = await fetch ( 'https://chat.openai.com/api/auth/session' )
115+ data = await resp . json ( ) . catch ( ( ) => ( { } ) )
113116 }
114- if ( data . accessToken ) {
117+ if ( data && data . accessToken ) {
115118 await setAccessToken ( data . accessToken )
116119 console . log ( data . accessToken )
117120 }
You can’t perform that action at this time.
0 commit comments