@kudoai/chatgpt.js 3.8.3 → 3.8.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE.md CHANGED
@@ -26,7 +26,7 @@
26
26
 
27
27
  # MIT License
28
28
 
29
- **Copyright © 2023–2025 [KudoAI](https://github.com/KudoAI) & [contributors](.#-contributors).**
29
+ **Copyright © 2023–2025 [KudoAI](https://github.com/KudoAI) & [contributors](.#-contributors)**
30
30
 
31
31
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
32
32
 
package/README.md CHANGED
@@ -51,16 +51,14 @@
51
51
  <img src="https://img.shields.io/badge/License-MIT-fc4f2d.svg?logo=internetarchive&logoColor=white&labelColor=464646&style=for-the-badge"></a>
52
52
  <a href="https://www.npmjs.com/package/@kudoai/chatgpt.js/v/latest" target="_blank" rel="noopener">
53
53
  <img src="https://img.shields.io/npm/v/%40kudoai%2Fchatgpt.js?logo=npm&logoColor=white&labelColor=464646&color=blue&style=for-the-badge&label=Latest+Release"></a>
54
- <a href="https://github.com/KudoAI/chatgpt.js/tree/v3.8.3/dist/chatgpt.min.js" target="_blank" rel="noopener">
55
- <img src="https://img.shields.io/github/size/KudoAI/chatgpt.js/dist/chatgpt.min.js?branch=v3.8.3&label=Minified%20Size&logo=databricks&logoColor=white&labelColor=464646&color=ff69b4&style=for-the-badge"></a>
54
+ <a href="https://github.com/KudoAI/chatgpt.js/tree/v3.8.5/dist/chatgpt.min.js" target="_blank" rel="noopener">
55
+ <img src="https://img.shields.io/github/size/KudoAI/chatgpt.js/dist/chatgpt.min.js?branch=v3.8.5&label=Minified%20Size&logo=databricks&logoColor=white&labelColor=464646&color=ff69b4&style=for-the-badge"></a>
56
56
  <a href="https://www.codefactor.io/repository/github/kudoai/chatgpt.js" target="_blank" rel="noopener">
57
57
  <img src="https://img.shields.io/codefactor/grade/github/kudoai/chatgpt.js?label=Code+Quality&logo=codefactor&logoColor=white&labelColor=464646&color=1acc6c&style=for-the-badge"></a>
58
58
  <a href="https://sonarcloud.io/component_measures?metric=new_vulnerabilities&id=kudoai_chatgpt.js" target="_blank" rel="noopener">
59
59
  <img src="https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fsonarcloud.io%2Fapi%2Fmeasures%2Fcomponent%3Fcomponent%3Dkudoai_chatgpt.js%26metricKeys%3Dvulnerabilities&query=%24.component.measures.0.value&style=for-the-badge&logo=sonarcloud&logoColor=white&labelColor=464646&label=Vulnerabilities&color=gold"></a>
60
60
  <a href="https://github.com/sindresorhus/awesome-chatgpt#javascript" target="_blank" rel="noopener">
61
61
  <img src="https://img.shields.io/badge/Mentioned_in-Awesome-cca8c4?logo=awesomelists&logoColor=white&labelColor=464646&style=for-the-badge"></a>
62
- <a href="https://opentools.ai/tools/chatgptjs">
63
- <img alt="[Voted Top Tool on OpenTools.ai]" src="https://img.shields.io/badge/Voted_Top_Tool-OpenTools.ai-f43f5e?logo=data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIzNTAiIGhlaWdodD0iMzUwIiBzdHlsZT0ic2hhcGUtcmVuZGVyaW5nOmdlb21ldHJpY1ByZWNpc2lvbjt0ZXh0LXJlbmRlcmluZzpnZW9tZXRyaWNQcmVjaXNpb247aW1hZ2UtcmVuZGVyaW5nOm9wdGltaXplUXVhbGl0eTtmaWxsLXJ1bGU6ZXZlbm9kZDtjbGlwLXJ1bGU6ZXZlbm9kZCI+PHBhdGggZmlsbD0iI2ZlZmZmZSIgZD0iTTM2LjUgMzAuNWM5My44MzItMSAxODcuODMyLTEuMzMzIDI4Mi0xIC4xNjcgOTQuMDAxIDAgMTg4LjAwMS0uNSAyODJsLTc4LTc4Yy0uNS00MS42NjUtLjY2Ny04My4zMzItLjUtMTI1LTQxLjY2OC4xNjctODMuMzM1IDAtMTI1LS41YTg1MzcuOTUgODUzNy45NSAwIDAgMC03OC03Ny41WiIgc3R5bGU9Im9wYWNpdHk6Ljk4NCIvPjxwYXRoIGZpbGw9IiNmZWZmZmUiIGQ9Ik0yOS41IDM1LjVhMjkyNC4wMjQgMjkyNC4wMjQgMCAwIDEgNzguNSA3OWMuNSA0MS42NjUuNjY3IDgzLjMzMi41IDEyNSA0Mi4wMDEtLjE2NyA4NC4wMDEgMCAxMjYgLjVhODQzMy4xNiA4NDMzLjE2IDAgMCAxIDc3IDc3LjVjLTkzLjk5OCAxLTE4Ny45OTggMS4zMzMtMjgyIDF2LTI4M1oiIHN0eWxlPSJvcGFjaXR5Oi45ODEiLz48L3N2Zz4=&logoColor=white&labelColor=464646&style=for-the-badge"></a>
64
62
  <a href="https://www.producthunt.com/posts/chatgpt-js" target="_blank" rel="noopener">
65
63
  <img src="https://img.shields.io/badge/Featured_on-Product_Hunt-ff6154?logo=producthunt&logoColor=white&labelColor=464646&style=for-the-badge"></a>
66
64
  <a href="https://trendshift.io/repositories/2896" target="_blank" rel="noopener">
@@ -120,7 +118,7 @@
120
118
 
121
119
  ```js
122
120
  (async () => {
123
- await import('https://cdn.jsdelivr.net/npm/@kudoai/chatgpt.js@3.8.3/dist/chatgpt.min.js');
121
+ await import('https://cdn.jsdelivr.net/npm/@kudoai/chatgpt.js@3.8.5/dist/chatgpt.min.js');
124
122
  // Your code here...
125
123
  })();
126
124
  ```
@@ -129,7 +127,7 @@
129
127
 
130
128
  ```js
131
129
  var xhr = new XMLHttpRequest();
132
- xhr.open('GET', 'https://cdn.jsdelivr.net/npm/@kudoai/chatgpt.js@3.8.3/dist/chatgpt.min.js');
130
+ xhr.open('GET', 'https://cdn.jsdelivr.net/npm/@kudoai/chatgpt.js@3.8.5/dist/chatgpt.min.js');
133
131
  xhr.onload = function () {
134
132
  if (xhr.status === 200) {
135
133
  var chatgptJS = document.createElement('script');
@@ -152,7 +150,7 @@ function yourCode() {
152
150
 
153
151
  ```js
154
152
  ...
155
- // @require https://cdn.jsdelivr.net/npm/@kudoai/chatgpt.js@3.8.3/dist/chatgpt.min.js
153
+ // @require https://cdn.jsdelivr.net/npm/@kudoai/chatgpt.js@3.8.5/dist/chatgpt.min.js
156
154
  // ==/UserScript==
157
155
 
158
156
  // Your code here...
@@ -222,7 +220,7 @@ chatgpt.get('reply', 'last');
222
220
 
223
221
  Each call equally fetches the last response. If you think it works, it probably will... so just type it!
224
222
 
225
- If it didn't, check out the extended [userguide](https://github.com/KudoAI/chatgpt.js/blob/v3.8.3/docs/USERGUIDE.md), or simply submit an [issue](https://github.com/KudoAI/chatgpt.js/issues) or [PR](https://github.com/KudoAI/chatgpt.js/pulls) and it will be integrated, ezpz!
223
+ If it didn't, check out the extended [userguide](https://github.com/KudoAI/chatgpt.js/blob/v3.8.5/docs/USERGUIDE.md), or simply submit an [issue](https://github.com/KudoAI/chatgpt.js/issues) or [PR](https://github.com/KudoAI/chatgpt.js/pulls) and it will be integrated, ezpz!
226
224
 
227
225
  <img height=8px width="100%" src="https://assets.chatgptjs.org/images/separators/gradient-aqua.png?v=e638eac">
228
226
 
@@ -416,7 +414,11 @@ This library exists thanks to code, translations, issues & ideas from the follow
416
414
  <a href="https://github.com/ericdachen" target="_blank" rel="noopener">
417
415
  <img title="@ericdachen" src="https://images.weserv.nl/?url=https://avatars.githubusercontent.com/u/54382303?first-contrib=2025.3.20-implement-warp-to-golden-sponsors&h=47&w=47&mask=circle&maxage=7d"></a>
418
416
  <a href="https://github.com/m-k8s" target="_blank" rel="noopener">
419
- <img title="@m-k8s" src="https://images.weserv.nl/?url=https://avatars.githubusercontent.com/u/42094254?first-contrib=2025.7.26-fixed-hand,ling-of-intermediate-msgs-by-getchatdata&h=47&w=47&mask=circle&maxage=7d"></a>
417
+ <img title="@m-k8s" src="https://images.weserv.nl/?url=https://avatars.githubusercontent.com/u/42094254?first-contrib=2025.7.26-fixed-handling-of-intermediate-msgs-by-getchatdata&h=47&w=47&mask=circle&maxage=7d"></a>
418
+ <a href="https://github.com/ahnupeng" target="_blank" rel="noopener">
419
+ <img title="@ahnupeng" src="https://images.weserv.nl/?url=https://avatars.githubusercontent.com/u/5319112?first-contrib=2025.9.4-suggested-allow-edit-slider-vals&h=47&w=47&mask=circle&maxage=7d"></a>
420
+ <a href="https://github.com/geghamyan" target="_blank" rel="noopener">
421
+ <img title="@geghamyan" src="https://images.weserv.nl/?url=https://avatars.githubusercontent.com/u/12634915?first-contrib=2026.1.2-fixed-console-err-bug&h=47&w=47&mask=circle&maxage=7d"></a>
420
422
  <a href="https://github.com/dependabot" target="_blank" rel="noopener">
421
423
  <img title="Dependabot" src="https://images.weserv.nl/?url=https://avatars.githubusercontent.com/in/29110&h=47&w=47&mask=circle&maxage=7d"></a>
422
424
  <a href="https://chatgpt.com" target="_blank" rel="noopener">
@@ -480,7 +482,7 @@ This library exists thanks to code, translations, issues & ideas from the follow
480
482
  <div align="center">
481
483
 
482
484
  **[Releases](https://github.com/KudoAI/chatgpt.js/releases)** /
483
- [Userguide](https://github.com/KudoAI/chatgpt.js/blob/v3.8.3/docs/USERGUIDE.md) /
485
+ [Userguide](https://github.com/KudoAI/chatgpt.js/blob/v3.8.5/docs/USERGUIDE.md) /
484
486
  [Discuss](https://github.com/KudoAI/chatgpt.js/discussions) /
485
487
  [Back to top ↑](#top)
486
488
 
package/chatgpt.js CHANGED
@@ -38,7 +38,7 @@ const chatgpt = {
38
38
  reason: 'button[data-testid=composer-button-reason]',
39
39
  send: 'button[data-testid=send-button]',
40
40
  sidebar: 'div[style*=-sidebar-width] button[data-testid=close-sidebar-button], div[style*=-sidebar-rail-width] button[aria-controls=stage-slideover-sidebar]',
41
- stop: 'button[data-testid=stop-button]',
41
+ stop: 'div:has(> svg > path[d^="M10 2.08496C14.3713"])',
42
42
  upload: 'button:has(> svg > path[d^="M12 3C12.5523"])',
43
43
  voice: 'button[data-testid*=composer-speech-button]'
44
44
  },
@@ -127,13 +127,14 @@ const chatgpt = {
127
127
 
128
128
  drag: {
129
129
  mousedown(event) { // find modal, update styles, attach listeners, init XY offsets
130
- if (event.button != 0) return // prevent non-left-click drag
131
- if (!/auto|default/.test(getComputedStyle(event.target).cursor))
132
- return // prevent drag on interactive elems
130
+ if ( // prevent drag when...
131
+ event.button != 0 // non-left-click
132
+ || !/auto|default/.test(getComputedStyle(event.target).cursor) // cursor changed
133
+ ) return
133
134
  chatgpt.draggingModal = event.currentTarget
134
135
  event.preventDefault() // prevent sub-elems like icons being draggable
135
136
  Object.assign(chatgpt.draggingModal.style, {
136
- transition: '0.1s', willChange: 'transform', transform: 'scale(1.05)' })
137
+ transition: 'transform 0.1s ease', transform: 'scale(1.05)' })
137
138
  document.body.style.cursor = 'grabbing' // update cursor
138
139
  ;[...chatgpt.draggingModal.children] // prevent hover FX if drag lags behind cursor
139
140
  .forEach(child => child.style.pointerEvents = 'none')
@@ -153,7 +154,7 @@ const chatgpt = {
153
154
 
154
155
  mouseup() { // restore styles/pointer events, remove listeners, reset chatgpt.draggingModal
155
156
  Object.assign(chatgpt.draggingModal.style, { // restore styles
156
- cursor: 'inherit', transition: 'inherit', willChange: 'auto', transform: 'scale(1)' })
157
+ cursor: 'inherit', transition: 'inherit', transform: 'scale(1)' })
157
158
  document.body.style.cursor = '' // restore cursor
158
159
  ;[...chatgpt.draggingModal.children] // restore pointer events
159
160
  .forEach(child => child.style.pointerEvents = '')
@@ -370,7 +371,7 @@ const chatgpt = {
370
371
  document.removeEventListener('keydown', handlers.dismiss.key) // prevent memory leaks
371
372
 
372
373
  // Check for pending alerts in queue
373
- if (alertQueue.length > 0) {
374
+ if (alertQueue.length) {
374
375
  const nextAlert = document.getElementById(alertQueue[0])
375
376
  setTimeout(() => {
376
377
  nextAlert.style.display = ''
@@ -408,7 +409,7 @@ const chatgpt = {
408
409
  }
409
410
  scheduleRefreshes(interval)
410
411
  }, (interval + randomDelay) * 1000)
411
- };
412
+ }
412
413
  scheduleRefreshes( interval ? parseInt(interval, 10) : 30 )
413
414
  console.log(`↻ ChatGPT >> [${chatgpt.autoRefresh.nowTimeStamp()}] Auto refresh activated`)
414
415
 
@@ -431,7 +432,7 @@ const chatgpt = {
431
432
  const now = new Date()
432
433
  const hours = now.getHours() % 12 || 12 // convert to 12h format
433
434
  let minutes = now.getMinutes(), seconds = now.getSeconds()
434
- if (minutes < 10) minutes = '0' + minutes; if (seconds < 10) seconds = '0' + seconds
435
+ if (minutes < 10) minutes = '0' + minutes ; if (seconds < 10) seconds = '0' + seconds
435
436
  const meridiem = now.getHours() < 12 ? 'AM' : 'PM'
436
437
  return `${hours}:${minutes}:${seconds} ${meridiem}`
437
438
  },
@@ -573,7 +574,7 @@ const chatgpt = {
573
574
 
574
575
  async refactor(code, objective) {
575
576
  if (!code) return console.error('Code (1st) argument not supplied. Pass some code!')
576
- for (let i = 0; i < arguments.length; i++) if (typeof arguments[i] != 'string')
577
+ for (let i = 0 ; i < arguments.length ; i++) if (typeof arguments[i] != 'string')
577
578
  return console.error(`Argument ${ i + 1 } must be a string.`)
578
579
  chatgpt.send(`Refactor the following code for ${ objective || 'brevity' }:\n\n${code}`)
579
580
  console.info('Refactoring code...')
@@ -602,7 +603,7 @@ const chatgpt = {
602
603
  async write(prompt, outputLang) {
603
604
  if (!prompt) return console.error('Prompt (1st) argument not supplied. Pass a prompt!')
604
605
  if (!outputLang) return console.error('outputLang (2nd) argument not supplied. Pass a language!')
605
- for (let i = 0; i < arguments.length; i++) if (typeof arguments[i] != 'string')
606
+ for (let i = 0 ; i < arguments.length ; i++) if (typeof arguments[i] != 'string')
606
607
  return console.error(`Argument ${ i + 1 } must be a string.`)
607
608
  chatgpt.send(`${prompt}\n\nWrite this as code in ${outputLang}`)
608
609
  console.info('Writing code...')
@@ -656,7 +657,7 @@ const chatgpt = {
656
657
  if (!chatDivs.length) return console.error('Chat is empty!')
657
658
  const msgs = [] ; let isUserMsg = true
658
659
  chatDivs.forEach(div => {
659
- const sender = isUserMsg ? 'USER' : 'CHATGPT'; isUserMsg = !isUserMsg
660
+ const sender = isUserMsg ? 'USER' : 'CHATGPT' ; isUserMsg = !isUserMsg
660
661
  const msg = [...div.childNodes].map(node => node.innerText)
661
662
  .join('\n\n') // insert double line breaks between paragraphs
662
663
  .replace('Copy code', '')
@@ -685,7 +686,7 @@ const chatgpt = {
685
686
  cssLinks.forEach(link => {
686
687
  const href = link.getAttribute('href')
687
688
  if (href?.startsWith('/')) link.setAttribute('href', 'https://chat.openai.com' + href)
688
- });
689
+ })
689
690
 
690
691
  // Serialize updated HTML to string
691
692
  transcript = new XMLSerializer().serializeToString(parsedHtml)
@@ -710,7 +711,7 @@ const chatgpt = {
710
711
 
711
712
  if (format == 'md') { // remove extraneous HTML + fix file extension
712
713
  const mdMatch = /<.*<h1(.|\n)*?href=".*?continue[^"]*".*?\/a>.*?<[^/]/.exec(transcript)[1]
713
- transcript = mdMatch || transcript; filename = filename.replace('.html', '.md')
714
+ transcript = mdMatch || transcript ; filename = filename.replace('.html', '.md')
714
715
  }
715
716
  const blob = new Blob([transcript],
716
717
  { type: 'text/' + ( format == 'html' ? 'html' : format == 'md' ? 'markdown' : 'plain' )})
@@ -768,7 +769,7 @@ const chatgpt = {
768
769
  }}
769
770
  if (!targetNames.includes(targetName.toLowerCase()))
770
771
  throw new Error(`Invalid targetName: ${targetName}. `
771
- + (targetNames.length > 0 ? 'Valid values are: ' + JSON.stringify(targetNames)
772
+ + (targetNames.length ? 'Valid values are: ' + JSON.stringify(targetNames)
772
773
  : 'targetType ' + targetType.toLowerCase() + ' does not require additional options.'))
773
774
 
774
775
  // Call target function using pre-validated name components
@@ -926,7 +927,7 @@ const chatgpt = {
926
927
 
927
928
  // Fill [userMessages]
928
929
  for (const key in data)
929
- if (data[key].message != null && data[key].message.author.role == 'user')
930
+ if (data[key]?.message?.author?.role == 'user')
930
931
  userMessages.push({ id: data[key].id, msg: data[key].message })
931
932
  userMessages.sort((a, b) => a.msg.create_time - b.msg.create_time) // sort in chronological order
932
933
 
@@ -937,12 +938,10 @@ const chatgpt = {
937
938
  // Fill [chatGPTMessages]
938
939
  for (const userMessage of userMessages) {
939
940
  let sub = []
940
- for (const key in data) {
941
- if (data[key].message != null && data[key].message.author.role == 'assistant'
942
- && isUserMsgAncestor(key, userMessage.id)) {
943
- sub.push(data[key].message)
944
- }
945
- }
941
+ for (const key in data)
942
+ if (data[key]?.message?.author?.role == 'assistant'
943
+ && isUserMsgAncestor(key, userMessage.id)
944
+ ) sub.push(data[key].message)
946
945
  sub.sort((a, b) => a.create_time - b.create_time) // sort in chronological order
947
946
  sub = sub.map(x => { // pull out msgs after sorting
948
947
  switch(x.content.content_type) {
@@ -960,7 +959,8 @@ const chatgpt = {
960
959
  msgsToReturn.push(userMessages[userMessage].msg.content.parts[0])
961
960
  else if (sender == 'chatgpt') // Fill [msgsToReturn] with ChatGPT responses
962
961
  for (const chatGPTMessage of chatGPTMessages)
963
- msgsToReturn.push(msgToGet == 'latest' ? chatGPTMessages[chatGPTMessages.length - 1] : chatGPTMessage );
962
+ msgsToReturn.push(msgToGet == 'latest' ? chatGPTMessages[chatGPTMessages.length - 1]
963
+ : chatGPTMessage )
964
964
  else { // Fill [msgsToReturn] with objects of user messages and chatgpt response(s)
965
965
  let i = 0
966
966
  for (const message in userMessages) {
@@ -1076,9 +1076,9 @@ const chatgpt = {
1076
1076
  else if (target == 'chatgpt') instructionsData.about_model_message += instruction
1077
1077
 
1078
1078
  await this.sendRequest('POST', token, instructionsData)
1079
- return resolve();
1080
- });
1081
- });
1079
+ return resolve()
1080
+ })
1081
+ })
1082
1082
  },
1083
1083
 
1084
1084
  clear(target) {
@@ -1133,7 +1133,7 @@ const chatgpt = {
1133
1133
  xhr.onload = () => {
1134
1134
  const responseData = JSON.parse(xhr.responseText)
1135
1135
  if (xhr.status == 422)
1136
- return reject('🤖 chatgpt.js >> Character limit exceeded. Custom instructions can have a maximum length of 1500 characters.');
1136
+ return reject('🤖 chatgpt.js >> Character limit exceeded. Custom instructions can have a maximum length of 1500 characters.')
1137
1137
  else if (xhr.status == 403 && responseData.detail.reason == 'content_policy')
1138
1138
  return reject('🤖 chatgpt.js >> ' + responseData.detail.description)
1139
1139
  else if (xhr.status != 200)
@@ -1258,7 +1258,7 @@ const chatgpt = {
1258
1258
  if (!attrs.items.every(el => typeof el == 'object')) // the entries of the array are not objects
1259
1259
  return console.error('\'items\' must be an array of objects!')
1260
1260
 
1261
- newElem.style = 'background-color: #000; width: 100%; border: none;'
1261
+ newElem.style = 'background-color: #000 ; width: 100% ; border: none'
1262
1262
 
1263
1263
  attrs.items.forEach(item => {
1264
1264
  const optionElement = document.createElement('option')
@@ -1301,7 +1301,7 @@ const chatgpt = {
1301
1301
  }
1302
1302
  },
1303
1303
 
1304
- minify() { chatgpt.code.minify(); },
1304
+ minify() { chatgpt.code.minify() },
1305
1305
 
1306
1306
  notify(...args) {
1307
1307
  const scheme = chatgpt.isDarkMode() ? 'dark' : 'light'
@@ -1309,7 +1309,7 @@ const chatgpt = {
1309
1309
  if (typeof args[0] == 'object' && !Array.isArray(args[0]))
1310
1310
  ({ msg, position, notifDuration, shadow, toast } = args[0])
1311
1311
  else [msg, position, notifDuration, shadow] = args
1312
- notifDuration = notifDuration ? +notifDuration : 1.75; // sec duration to maintain notification visibility
1312
+ notifDuration = notifDuration ? +notifDuration : 1.75 // sec duration to maintain notification visibility
1313
1313
  const fadeDuration = 0.35, // sec duration of fade-out
1314
1314
  vpYoffset = 23, vpXoffset = 27 // px offset from viewport border
1315
1315
 
@@ -1322,7 +1322,7 @@ const chatgpt = {
1322
1322
 
1323
1323
  // Create/append close button
1324
1324
  const closeBtn = document.createElement('div')
1325
- closeBtn.title = 'Dismiss'; closeBtn.classList.add('notif-close-btn', 'no-mobile-tap-outline')
1325
+ closeBtn.title = 'Dismiss' ; closeBtn.classList.add('notif-close-btn', 'no-mobile-tap-outline')
1326
1326
  const closeSVG = document.createElementNS('http://www.w3.org/2000/svg', 'svg')
1327
1327
  closeSVG.setAttribute('height', '8px')
1328
1328
  closeSVG.setAttribute('viewBox', '0 0 14 14')
@@ -1332,7 +1332,7 @@ const chatgpt = {
1332
1332
  closeSVGpath.setAttribute('fill-rule', 'evenodd')
1333
1333
  closeSVGpath.setAttribute('clip-rule', 'evenodd')
1334
1334
  closeSVGpath.setAttribute('fill', 'white')
1335
- closeSVGpath.setAttribute('d', 'M13.7071 1.70711C14.0976 1.31658 14.0976 0.683417 13.7071 0.292893C13.3166 -0.0976312 12.6834 -0.0976312 12.2929 0.292893L7 5.58579L1.70711 0.292893C1.31658 -0.0976312 0.683417 -0.0976312 0.292893 0.292893C-0.0976312 0.683417 -0.0976312 1.31658 0.292893 1.70711L5.58579 7L0.292893 12.2929C-0.0976312 12.6834 -0.0976312 13.3166 0.292893 13.7071C0.683417 14.0976 1.31658 14.0976 1.70711 13.7071L7 8.41421L12.2929 13.7071C12.6834 14.0976 13.3166 14.0976 13.7071 13.7071C14.0976 13.3166 14.0976 12.6834 13.7071 12.2929L8.41421 7L13.7071 1.70711Z');
1335
+ closeSVGpath.setAttribute('d', 'M13.7071 1.70711C14.0976 1.31658 14.0976 0.683417 13.7071 0.292893C13.3166 -0.0976312 12.6834 -0.0976312 12.2929 0.292893L7 5.58579L1.70711 0.292893C1.31658 -0.0976312 0.683417 -0.0976312 0.292893 0.292893C-0.0976312 0.683417 -0.0976312 1.31658 0.292893 1.70711L5.58579 7L0.292893 12.2929C-0.0976312 12.6834 -0.0976312 13.3166 0.292893 13.7071C0.683417 14.0976 1.31658 14.0976 1.70711 13.7071L7 8.41421L12.2929 13.7071C12.6834 14.0976 13.3166 14.0976 13.7071 13.7071C14.0976 13.3166 14.0976 12.6834 13.7071 12.2929L8.41421 7L13.7071 1.70711Z')
1336
1336
  closeSVG.append(closeSVGpath) ; closeBtn.append(closeSVG) ; notificationDiv.append(closeBtn)
1337
1337
 
1338
1338
  // Determine div position/quadrant
@@ -1419,7 +1419,7 @@ const chatgpt = {
1419
1419
 
1420
1420
  // Add notification dismissal to timeout schedule + button clicks
1421
1421
  const dismissNotif = () => {
1422
- notificationDiv.style.animation = `notif-zoom-fade-out ${fadeDuration}s ease-out`;
1422
+ notificationDiv.style.animation = `notif-zoom-fade-out ${fadeDuration}s ease-out`
1423
1423
  clearTimeout(dismissFuncTID)
1424
1424
  }
1425
1425
  const dismissFuncTID = setTimeout(dismissNotif, hideDelay * 1000) // maintain visibility for `hideDelay` secs, then dismiss
@@ -1471,7 +1471,7 @@ const chatgpt = {
1471
1471
 
1472
1472
  // Print methods
1473
1473
  const isDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches,
1474
- baseFontStyles = 'font-family: monospace ; font-size: larger ; '
1474
+ baseFontStyles = 'font-family: monospace ; font-size: larger ;'
1475
1475
  console.log('\n%c🤖 chatgpt.js methods\n', 'font-family: sans-serif ; font-size: xxx-large ; font-weight: bold')
1476
1476
  for (const functionName of functionNames) {
1477
1477
  const isChatGptObjParent = /chatgpt|other/.test(functionName[0]),
@@ -1534,7 +1534,7 @@ const chatgpt = {
1534
1534
  elems = [...text.matchAll(reTags)]
1535
1535
 
1536
1536
  // Process 1st element to render
1537
- if (elems.length > 0) {
1537
+ if (elems.length) {
1538
1538
  const elem = elems[0],
1539
1539
  [tagContent, tagName, tagAttrs, tagText] = elem.slice(0, 4),
1540
1540
  tagNode = document.createElement(tagName) ; tagNode.textContent = tagText
@@ -1584,7 +1584,7 @@ const chatgpt = {
1584
1584
  // chatToGet = index|title|id of chat to get (defaults to latest if '' or unpassed)
1585
1585
  // responseToGet = index of response to get (defaults to latest if '' or unpassed)
1586
1586
 
1587
- chatToGet = chatToGet || 'latest'; responseToGet = responseToGet || 'latest'
1587
+ chatToGet = chatToGet || 'latest' ; responseToGet = responseToGet || 'latest'
1588
1588
  return chatgpt.getChatData(chatToGet, 'msg', 'chatgpt', responseToGet)
1589
1589
  },
1590
1590
 
@@ -1637,7 +1637,7 @@ const chatgpt = {
1637
1637
  return console.error(`Argument ${ i + 1 } must be a string!`)
1638
1638
  const textArea = chatgpt.getChatBox()
1639
1639
  if (!textArea) return console.error('Chatbar element not found!')
1640
- const msgP = document.createElement('p'); msgP.textContent = msg
1640
+ const msgP = document.createElement('p') ; msgP.textContent = msg
1641
1641
  textArea.querySelector('p').replaceWith(msgP)
1642
1642
  textArea.dispatchEvent(new Event('input', { bubbles: true })) // enable send button
1643
1643
  setTimeout(function delaySend() {
@@ -1687,7 +1687,7 @@ const chatgpt = {
1687
1687
  },
1688
1688
 
1689
1689
  async sentiment(text, entity) {
1690
- for (let i = 0; i < arguments.length; i++) if (typeof arguments[i] != 'string')
1690
+ for (let i = 0 ; i < arguments.length ; i++) if (typeof arguments[i] != 'string')
1691
1691
  return console.error(`Argument ${ i + 1 } must be a string.`)
1692
1692
  chatgpt.send('What is the sentiment of the following text'
1693
1693
  + ( entity ? ` towards the entity ${entity},` : '')
@@ -1882,7 +1882,7 @@ const chatgpt = {
1882
1882
  return newElem.id // Return the element id
1883
1883
  },
1884
1884
 
1885
- exists() { return !!chatgpt.getNewChatLink(); },
1885
+ exists() { return !!chatgpt.getNewChatLink() },
1886
1886
  hide() { this.isOn() ? this.toggle() : console.info('Sidebar already hidden!') },
1887
1887
  show() { this.isOff() ? this.toggle() : console.info('Sidebar already shown!') },
1888
1888
  isOff() { return !this.isOn() },
@@ -1916,12 +1916,12 @@ const chatgpt = {
1916
1916
  },
1917
1917
 
1918
1918
  startNewChat() { try { chatgpt.getNewChatBtn().click() } catch (err) { console.error(err.message) }},
1919
- stop() { chatgpt.response.stopGenerating(); },
1919
+ stop() { chatgpt.response.stopGenerating() },
1920
1920
 
1921
1921
  async suggest(ideaType, details) {
1922
1922
  if (!ideaType) return console.error('ideaType (1st argument) not supplied'
1923
1923
  + `(e.g. 'gifts', 'names', 'recipes', etc.)`)
1924
- for (let i = 0; i < arguments.length; i++) if (typeof arguments[i] != 'string')
1924
+ for (let i = 0 ; i < arguments.length ; i++) if (typeof arguments[i] != 'string')
1925
1925
  return console.error(`Argument ${ i + 1 } must be a string.`)
1926
1926
  chatgpt.send('Suggest some names. ' + ( details || '' ))
1927
1927
  console.info(`Creating ${ideaType}...`)
@@ -1965,7 +1965,7 @@ const chatgpt = {
1965
1965
  return chatgpt.getChatData('active', 'msg', 'chatgpt', 'latest')
1966
1966
  },
1967
1967
 
1968
- toggleScheme() { chatgpt.settings.scheme.toggle(); },
1968
+ toggleScheme() { chatgpt.settings.scheme.toggle() },
1969
1969
 
1970
1970
  async translate(text, outputLang) {
1971
1971
  if (!text) return console.error('Text (1st) argument not supplied. Pass some text!')
@@ -1990,7 +1990,7 @@ const chatgpt = {
1990
1990
  const r = ( // generate random nibble
1991
1991
  ( d + (window.crypto.getRandomValues(new Uint32Array(1))[0] / (Math.pow(2, 32) - 1))*16)%16 | 0 )
1992
1992
  d = Math.floor(d/16) // correspond each UUID digit to unique 4-bit chunks of timestamp
1993
- return ( c == 'x' ? r : (r&0x3|0x8) ).toString(16); // generate random hexadecimal digit
1993
+ return ( c == 'x' ? r : (r&0x3|0x8) ).toString(16) // generate random hexadecimal digit
1994
1994
  })
1995
1995
  return uuid
1996
1996
  }
@@ -2091,8 +2091,8 @@ const cjsFuncSynonyms = [
2091
2091
  ['temp', 'temporary'],
2092
2092
  ['typing', 'generating'],
2093
2093
  ['unminify', 'beautify', 'prettify', 'prettyPrint']
2094
- ];
2095
- (function createCJSaliasFuncs(obj = chatgpt) {
2094
+ ]
2095
+ ;(function createCJSaliasFuncs(obj = chatgpt) {
2096
2096
  for (const prop in obj) {
2097
2097
  if (!Object.prototype.hasOwnProperty.call(obj, prop)) continue // skip inherited props
2098
2098
  if (typeof obj[prop] == 'object') createCJSaliasFuncs(obj[prop]) // recurse thru objs to find deeper functions
@@ -2133,11 +2133,13 @@ function toCamelCase(words) {
2133
2133
  // Prefix console logs w/ '🤖 chatgpt.js >> '
2134
2134
  const consolePrefix = '🤖 chatgpt.js >> ', ogError = console.error, ogInfo = console.info
2135
2135
  console.error = (...args) => {
2136
- if (!args[0].startsWith(consolePrefix)) ogError(consolePrefix + args[0], ...args.slice(1))
2137
- else ogError(...args)
2136
+ if (typeof args[0] == 'string') {
2137
+ if (!args[0].startsWith(consolePrefix)) ogError(consolePrefix + args[0], ...args.slice(1))
2138
+ else ogError(...args)
2139
+ } else ogError(consolePrefix, ...args)
2138
2140
  }
2139
2141
  console.info = (msg) => {
2140
- if (!msg.startsWith(consolePrefix)) ogInfo(consolePrefix + msg);
2142
+ if (!msg.startsWith(consolePrefix)) ogInfo(consolePrefix + msg)
2141
2143
  else ogInfo(msg)
2142
2144
  }
2143
2145