@@ -116,7 +116,6 @@ const chatgpt = {
116116 isMobile = chatgpt . browser . isMobile ( )
117117
118118 const handlers = {
119-
120119 dismiss : {
121120 click ( event ) {
122121 if ( event . target == event . currentTarget || event . target . closest ( '[class*=-close-btn]' ) )
@@ -184,12 +183,12 @@ const chatgpt = {
184183 modalContainer . classList . add ( 'chatgpt-modal' ) // add class to main div
185184 const modal = document . createElement ( 'div' ) ,
186185 modalTitle = document . createElement ( 'h2' ) ,
187- modalMessage = document . createElement ( 'p' )
186+ modalMsg = document . createElement ( 'p' )
188187
189188 // Create/append/update modal style (if missing or outdated)
190189 const thisUpdated = 1739338889852 // timestamp of last edit for this file's `modalStyle`
191190 let modalStyle = document . querySelector ( '#chatgpt-modal-style' ) // try to select existing style
192- if ( ! modalStyle || parseInt ( modalStyle . getAttribute ( 'last-updated' ) , 10 ) < thisUpdated ) { // if missing or outdated
191+ if ( ! modalStyle || parseInt ( modalStyle . getAttribute ( 'last-updated' ) , 10 ) < thisUpdated ) { // if missing/ outdated
193192 if ( ! modalStyle ) { // outright missing, create/id/attr/append it first
194193 modalStyle = document . createElement ( 'style' ) ; modalStyle . id = 'chatgpt-modal-style'
195194 modalStyle . setAttribute ( 'last-updated' , thisUpdated . toString ( ) )
@@ -285,11 +284,11 @@ const chatgpt = {
285284 }
286285
287286 // Insert text into elems
288- modalTitle . textContent = title || '' ; modalMessage . innerText = msg || '' ; chatgpt . renderHTML ( modalMessage )
287+ modalTitle . textContent = title || '' ; modalMsg . innerText = msg || '' ; chatgpt . renderHTML ( modalMsg )
289288
290289 // Create/append buttons (if provided) to buttons div
291- const modalButtons = document . createElement ( 'div' )
292- modalButtons . classList . add ( 'modal-buttons' , 'no-mobile-tap-outline' )
290+ const modalBtns = document . createElement ( 'div' )
291+ modalBtns . classList . add ( 'modal-buttons' , 'no-mobile-tap-outline' )
293292 if ( btns ) { // are supplied
294293 if ( ! Array . isArray ( btns ) ) btns = [ btns ] // convert single button to array if necessary
295294 btns . forEach ( ( buttonFunc ) => { // create title-cased labels + attach listeners
@@ -299,17 +298,17 @@ const chatgpt = {
299298 . replace ( / ( [ A - Z ] ) / g, ' $1' ) // insert spaces
300299 . replace ( / ^ \w / , firstChar => firstChar . toUpperCase ( ) ) // capitalize first letter
301300 button . onclick = ( ) => { dismissAlert ( ) ; buttonFunc ( ) }
302- modalButtons . insertBefore ( button , modalButtons . firstChild )
301+ modalBtns . insertBefore ( button , modalBtns . firstChild )
303302 } )
304303 }
305304
306305 // Create/append OK/dismiss button to buttons div
307306 const dismissBtn = document . createElement ( 'button' )
308307 dismissBtn . textContent = btns ? 'Dismiss' : 'OK'
309- modalButtons . insertBefore ( dismissBtn , modalButtons . firstChild )
308+ modalBtns . insertBefore ( dismissBtn , modalBtns . firstChild )
310309
311310 // Highlight primary button
312- modalButtons . lastChild . classList . add ( 'primary-modal-btn' )
311+ modalBtns . lastChild . classList . add ( 'primary-modal-btn' )
313312
314313 // Create/append checkbox (if provided) to checkbox group div
315314 const checkboxDiv = document . createElement ( 'div' )
@@ -326,7 +325,7 @@ const chatgpt = {
326325 + checkboxFunc . name . slice ( 1 ) // format remaining chars
327326 . replace ( / ( [ A - Z ] ) / g, ( match , letter ) => ' ' + letter . toLowerCase ( ) ) // insert spaces, convert to lowercase
328327 . replace ( / \b ( \w + ) n t \b / gi, '$1n\'t' ) // insert apostrophe in 'nt' suffixes
329- . trim ( ) // trim leading/trailing spaces
328+ . trim ( ) // leading/trailing spaces
330329
331330 checkboxDiv . append ( checkboxInput ) ; checkboxDiv . append ( checkboxLabel )
332331 }
@@ -346,7 +345,7 @@ const chatgpt = {
346345 closeSVG . append ( closeSVGpath ) ; closeBtn . append ( closeSVG )
347346
348347 // Assemble/append div
349- modal . append ( closeBtn , modalTitle , modalMessage , checkboxDiv , modalButtons )
348+ modal . append ( closeBtn , modalTitle , modalMsg , checkboxDiv , modalBtns )
350349 modal . style . width = `${ width || 458 } px`
351350 modalContainer . append ( modal ) ; document . body . append ( modalContainer )
352351
@@ -453,7 +452,6 @@ const chatgpt = {
453452 } ,
454453
455454 toggle : {
456-
457455 beacons ( ) {
458456 if ( ! chatgpt . _validateEnv ( { allowed : 'frontend' } ) ) return
459457 if ( chatgpt . autoRefresh . beaconID ) {
@@ -684,7 +682,7 @@ const chatgpt = {
684682 // Init args
685683 chatToGet = ! chatToGet ? 'active' // default to 'active' if unpassed
686684 : Number . isInteger ( chatToGet ) || / ^ \d + $ / . test ( chatToGet ) ? // else if string/int num passed
687- parseInt ( chatToGet , 10 ) // parse as integer
685+ parseInt ( chatToGet , 10 ) // parse as integer
688686 : chatToGet // else preserve non-num string as 'active', 'latest' or title/id of chat to get
689687 format = format . toLowerCase ( ) || 'html' // default to 'html' if unpassed
690688
@@ -951,29 +949,28 @@ const chatgpt = {
951949 xhr . setRequestHeader ( 'Content-Type' , 'application/json' )
952950 xhr . setRequestHeader ( 'Authorization' , 'Bearer ' + token )
953951 xhr . onload = ( ) => {
954- if ( xhr . status != 200 )
955- return reject ( 'Request failed. Cannot retrieve chat messages.' )
952+ if ( xhr . status != 200 ) return reject ( 'Request failed. Cannot retrieve chat messages.' )
956953
957954 // Init const's
958955 const data = JSON . parse ( xhr . responseText ) . mapping , // get chat messages
959- userMessages = [ ] , chatGPTMessages = [ ] , msgsToReturn = [ ]
956+ userMsgs = [ ] , chatGPTMessages = [ ] , msgsToReturn = [ ]
960957
961- // Fill [userMessages ]
958+ // Fill [userMsgs ]
962959 for ( const key in data )
963960 if ( data [ key ] ?. message ?. author ?. role == 'user' )
964- userMessages . push ( { id : data [ key ] . id , msg : data [ key ] . message } )
965- userMessages . sort ( ( a , b ) => a . msg . create_time - b . msg . create_time ) // sort in chronological order
961+ userMsgs . push ( { id : data [ key ] . id , msg : data [ key ] . message } )
962+ userMsgs . sort ( ( a , b ) => a . msg . create_time - b . msg . create_time ) // sort in chronological order
966963
967- if ( parseInt ( msgToGet , 10 ) + 1 > userMessages . length ) // reject if index out of bounds
964+ if ( parseInt ( msgToGet , 10 ) + 1 > userMsgs . length ) // reject if index out of bounds
968965 return reject ( `Message/response with index ${ msgToGet + 1 } `
969- + ` is out of bounds. Only ${ userMessages . length } messages/responses exist!` )
966+ + ` is out of bounds. Only ${ userMsgs . length } messages/responses exist!` )
970967
971968 // Fill [chatGPTMessages]
972- for ( const userMessage of userMessages ) {
969+ for ( const userMsg of userMsgs ) {
973970 let sub = [ ]
974971 for ( const key in data )
975972 if ( data [ key ] ?. message ?. author ?. role == 'assistant'
976- && isUserMsgAncestor ( key , userMessage . id )
973+ && isUserMsgAncestor ( key , userMsg . id )
977974 ) sub . push ( data [ key ] . message )
978975 sub . sort ( ( a , b ) => a . create_time - b . create_time ) // sort in chronological order
979976 sub = sub . map ( x => { // pull out msgs after sorting
@@ -983,22 +980,22 @@ const chatgpt = {
983980 default : return
984981 }
985982 } )
986- sub = sub . length == 1 ? sub [ 0 ] : sub // convert not regenerated responses to strings
983+ sub = sub . length === 1 ? sub [ 0 ] : sub // convert not regenerated responses to strings
987984 chatGPTMessages . push ( sub ) // array of arrays (length > 1 = regenerated responses)
988985 }
989986
990987 if ( sender == 'user' ) // Fill [msgsToReturn] with user messages
991- for ( const userMessage in userMessages )
992- msgsToReturn . push ( userMessages [ userMessage ] . msg . content . parts [ 0 ] )
988+ for ( const userMsg in userMsgs )
989+ msgsToReturn . push ( userMsgs [ userMsg ] . msg . content . parts [ 0 ] )
993990 else if ( sender == 'chatgpt' ) // Fill [msgsToReturn] with ChatGPT responses
994991 for ( const chatGPTMessage of chatGPTMessages )
995992 msgsToReturn . push ( msgToGet == 'latest' ? chatGPTMessages [ chatGPTMessages . length - 1 ]
996993 : chatGPTMessage )
997994 else { // Fill [msgsToReturn] with objects of user messages and chatgpt response(s)
998995 let i = 0
999- for ( const message in userMessages ) {
996+ for ( const message in userMsgs ) {
1000997 msgsToReturn . push ( {
1001- user : userMessages [ message ] . msg . content . parts [ 0 ] ,
998+ user : userMsgs [ message ] . msg . content . parts [ 0 ] ,
1002999 chatgpt : msgToGet == 'latest' ? chatGPTMessages [ i ] [ chatGPTMessages [ i ] . length - 1 ] : chatGPTMessages [ i ]
10031000 } )
10041001 i ++
0 commit comments