@kudoai/chatgpt.js 3.6.0 → 3.6.2

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/README.md CHANGED
@@ -49,8 +49,8 @@
49
49
  <img src="https://img.shields.io/github/stars/KudoAI/chatgpt.js?label=Stars&color=af68ff&logo=github&logoColor=white&labelColor=464646&style=for-the-badge"></a>
50
50
  <a href="https://github.com/KudoAI/chatgpt.js/blob/main/LICENSE.md">
51
51
  <img src="https://img.shields.io/badge/License-MIT-green.svg?logo=internetarchive&logoColor=white&labelColor=464646&style=for-the-badge"></a>
52
- <a href="https://github.com/KudoAI/chatgpt.js/tree/v3.6.0/dist/chatgpt.min.js">
53
- <img src="https://img.shields.io/github/size/KudoAI/chatgpt.js/dist/chatgpt.min.js?branch=v3.6.0&label=Minified%20Size&logo=databricks&logoColor=white&labelColor=464646&color=ff69b4&style=for-the-badge"></a>
52
+ <a href="https://github.com/KudoAI/chatgpt.js/tree/v3.6.2/dist/chatgpt.min.js">
53
+ <img src="https://img.shields.io/github/size/KudoAI/chatgpt.js/dist/chatgpt.min.js?branch=v3.6.2&label=Minified%20Size&logo=databricks&logoColor=white&labelColor=464646&color=ff69b4&style=for-the-badge"></a>
54
54
  <a href="https://www.codefactor.io/repository/github/kudoai/chatgpt.js">
55
55
  <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>
56
56
  <a href="https://sonarcloud.io/component_measures?metric=new_vulnerabilities&id=kudoai_chatgpt.js">
@@ -94,7 +94,7 @@
94
94
 
95
95
  ```js
96
96
  (async () => {
97
- await import('https://cdn.jsdelivr.net/npm/@kudoai/chatgpt.js@3.6.0/dist/chatgpt.min.js');
97
+ await import('https://cdn.jsdelivr.net/npm/@kudoai/chatgpt.js@3.6.2/dist/chatgpt.min.js');
98
98
  // Your code here...
99
99
  })();
100
100
  ```
@@ -103,7 +103,7 @@
103
103
 
104
104
  ```js
105
105
  var xhr = new XMLHttpRequest();
106
- xhr.open('GET', 'https://cdn.jsdelivr.net/npm/@kudoai/chatgpt.js@3.6.0/dist/chatgpt.min.js');
106
+ xhr.open('GET', 'https://cdn.jsdelivr.net/npm/@kudoai/chatgpt.js@3.6.2/dist/chatgpt.min.js');
107
107
  xhr.onload = function () {
108
108
  if (xhr.status === 200) {
109
109
  var chatgptJS = document.createElement('script');
@@ -126,7 +126,7 @@ function yourCode() {
126
126
 
127
127
  ```js
128
128
  ...
129
- // @require https://cdn.jsdelivr.net/npm/@kudoai/chatgpt.js@3.6.0/dist/chatgpt.min.js
129
+ // @require https://cdn.jsdelivr.net/npm/@kudoai/chatgpt.js@3.6.2/dist/chatgpt.min.js
130
130
  // ==/UserScript==
131
131
 
132
132
  // Your code here...
@@ -196,7 +196,7 @@ chatgpt.get('reply', 'last');
196
196
 
197
197
  Each call equally fetches the last response. If you think it works, it probably will... so just type it!
198
198
 
199
- If it didn't, check out the extended [userguide](https://github.com/KudoAI/chatgpt.js/blob/v3.6.0/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!
199
+ If it didn't, check out the extended [userguide](https://github.com/KudoAI/chatgpt.js/blob/v3.6.2/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!
200
200
 
201
201
  <img height=8px width="100%" src="https://assets.chatgptjs.org/images/separators/gradient-aqua.png?v=e638eac">
202
202
 
@@ -411,19 +411,12 @@ This library exists thanks to code, translations, issues & ideas from the follow
411
411
 
412
412
  **chatgpt.js** is funded in part by:
413
413
 
414
- <a href="https://microsoft.com">
414
+ <a href="https://microsoft.com?utm_source=github&utm_medium=readme&utm_content=partner-logo&utm_campaign=chatgpt.js">
415
415
  <picture>
416
416
  <source type="image/png" media="(prefers-color-scheme: dark)" srcset="https://assets.chatgptjs.org/images/logos/partners/microsoft/white.png?v=e638eac">
417
417
  <img width=255 src="https://assets.chatgptjs.org/images/logos/partners/microsoft/black.png?v=e638eac">
418
418
  </picture>
419
419
  </a>
420
- &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
421
- <a href="https://burncloud.com/?utm_source=github&utm_medium=readme&utm_content=partner-logo&utm_campaign=chatgpt.js">
422
- <picture>
423
- <source type="image/png" media="(prefers-color-scheme: dark)" srcset="https://assets.chatgptjs.org/images/logos/partners/burncloud/with-description/white.png?v=610795b">
424
- <img width=285 src="https://assets.chatgptjs.org/images/logos/partners/burncloud/with-description/black.png?v=610795b">
425
- </picture>
426
- </a>
427
420
 
428
421
  </div>
429
422
 
@@ -434,7 +427,7 @@ This library exists thanks to code, translations, issues & ideas from the follow
434
427
  <div align="center">
435
428
 
436
429
  **[Releases](https://github.com/KudoAI/chatgpt.js/releases)** /
437
- [Userguide](https://github.com/KudoAI/chatgpt.js/blob/v3.6.0/docs/USERGUIDE.md) /
430
+ [Userguide](https://github.com/KudoAI/chatgpt.js/blob/v3.6.2/docs/USERGUIDE.md) /
438
431
  [Discuss](https://github.com/KudoAI/chatgpt.js/discussions) /
439
432
  [Back to top ↑](#top)
440
433
 
package/chatgpt.js CHANGED
@@ -97,7 +97,8 @@ const chatgpt = {
97
97
  if (event.button != 0) return // prevent non-left-click drag
98
98
  if (getComputedStyle(event.target).cursor == 'pointer') return // prevent drag on interactive elems
99
99
  chatgpt.draggableElem = event.currentTarget
100
- chatgpt.draggableElem.style.cursor = 'grabbing'
100
+ Object.assign(chatgpt.draggableElem.style, {
101
+ cursor: 'grabbing', transition: '0.1s', willChange: 'transform', transform: 'scale(1.05)' })
101
102
  event.preventDefault(); // prevent sub-elems like icons being draggable
102
103
  ['mousemove', 'mouseup'].forEach(eventType =>
103
104
  document.addEventListener(eventType, handlers.drag[eventType]))
@@ -114,7 +115,8 @@ const chatgpt = {
114
115
  },
115
116
 
116
117
  mouseup() { // remove listeners, reset chatgpt.draggableElem
117
- chatgpt.draggableElem.style.cursor = 'inherit';
118
+ Object.assign(chatgpt.draggableElem.style, {
119
+ cursor: 'inherit', transition: 'inherit', willChange: 'auto', transform: 'scale(1)' });
118
120
  ['mousemove', 'mouseup'].forEach(eventType =>
119
121
  document.removeEventListener(eventType, handlers.drag[eventType]))
120
122
  chatgpt.draggableElem = null
@@ -165,19 +167,22 @@ const chatgpt = {
165
167
  + `background-color: ${ scheme == 'dark' ? 'black' : 'white' };`
166
168
  + 'transform: translateX(-3px) translateY(7px) ;' // offset to move-in from
167
169
  + 'max-width: 75vw ; word-wrap: break-word ; border-radius: 15px ;'
168
- + 'padding: 20px ; margin: 12px 23px ; box-shadow: 0 30px 60px rgba(0,0,0,0.12) ;'
170
+ + 'padding: 20px ; margin: 12px 23px ;'
171
+ + `--shadow: 0 30px 60px rgba(0,0,0,0.12) ; box-shadow: var(--shadow) ;
172
+ -webkit-box-shadow: var(--shadow) ; -moz-box-shadow: var(--shadow) ;`
169
173
  + 'user-select: none ; -webkit-user-select: none ; -moz-user-select: none ; -o-user-select: none ;'
170
174
  + '-ms-user-select: none ;'
171
175
  + 'transition: var(--transition) ;' // for fade-in + move-in
172
176
  + '-webkit-transition: var(--transition) ; -moz-transition: var(--transition) ;'
173
177
  + '-o-transition: var(--transition) ; -ms-transition: var(--transition) }'
174
- + '.chatgpt-modal h2 { margin-bottom: 9px }'
175
- + `.chatgpt-modal a { color: ${ scheme == 'dark' ? '#00cfff' : '#1e9ebb' }}`
176
- + '.chatgpt-modal a:hover { text-decoration: underline }'
177
- + '.chatgpt-modal.animated > div { z-index: 13456 ; opacity: 0.98 ; transform: translateX(0) translateY(0) }'
178
- + '@keyframes alert-zoom-fade-out {'
179
- + '0% { opacity: 1 } 50% { opacity: 0.25 ; transform: scale(1.05) }'
180
- + '100% { opacity: 0 ; transform: scale(1.35) }}'
178
+ + `.chatgpt-modal h2 { margin-bottom: 9px }
179
+ .chatgpt-modal a { color: ${ scheme == 'dark' ? '#00cfff' : '#1e9ebb' }}
180
+ .chatgpt-modal a:hover { text-decoration: underline }
181
+ .chatgpt-modal.animated > div {
182
+ z-index: 13456 ; opacity: 0.98 ; transform: translateX(0) translateY(0) }
183
+ @keyframes alert-zoom-fade-out {
184
+ 0% { opacity: 1 } 50% { opacity: 0.25 ; transform: scale(1.05) }
185
+ 100% { opacity: 0 ; transform: scale(1.35) }}`
181
186
 
182
187
  // Button styles
183
188
  + '.modal-buttons { display: flex ; justify-content: flex-end ; margin: 20px -5px -3px 0 ;'
@@ -190,9 +195,11 @@ const chatgpt = {
190
195
  + `border: 1px solid ${ scheme == 'dark' ? 'white' : 'black' } ;`
191
196
  + `background: ${ scheme == 'dark' ? 'white' : 'black' } ;`
192
197
  + `color: ${ scheme == 'dark' ? 'black' : 'white' }}`
193
- + '.chatgpt-modal button:hover { color: #3d5d71 ; border-color: #6d9cb9 ;'
194
- + 'background-color: ' + ( scheme == 'dark' ? '#00cfff' : '#9cdaff' ) + ';'
195
- + 'box-shadow: 2px 1px ' + ( scheme == 'dark' ? '54px #00cfff' : '30px #9cdaff' ) + '}'
198
+ + `.chatgpt-modal button:hover {
199
+ color: #3d5d71 ; border-color: #6d9cb9 ;
200
+ background-color: ${ scheme == 'dark' ? '#00cfff' : '#9cdaff' };
201
+ --shadow: 2px 1px ${ scheme == 'dark' ? '54px #00cfff' : '30px #9cdaff' };
202
+ box-shadow: var(--shadow) ; box-shadow: var(--shadow) ; box-shadow: var(--shadow) }`
196
203
  + '.modal-close-btn {'
197
204
  + 'cursor: pointer ; width: 29px ; height: 29px ; border-radius: 17px ;'
198
205
  + 'float: right ; position: relative ; right: -6px ; top: -5px }'
@@ -200,17 +207,18 @@ const chatgpt = {
200
207
  + `.modal-close-btn:hover { background-color: #f2f2f2${ scheme == 'dark' ? '00' : '' }}`
201
208
 
202
209
  // Checkbox styles
203
- + '.chatgpt-modal .checkbox-group { display: flex ; margin-top: -18px }'
204
- + '.chatgpt-modal .checkbox-group label {'
205
- + 'font-size: .7rem ; margin: -.04rem 0 0px .3rem ;'
206
- + `color: ${ scheme == 'dark' ? '#e1e1e1' : '#1e1e1e' }}`
207
- + '.chatgpt-modal input[type=checkbox] { transform: scale(0.7) ;'
208
- + `border: 1px solid ${ scheme == 'dark' ? 'white' : 'black' }}`
209
- + '.chatgpt-modal input[type=checkbox]:checked {'
210
- + `border: 1px solid ${ scheme == 'dark' ? 'white' : 'black' } ;`
211
- + 'background-color: black ; position: inherit }'
212
- + '.chatgpt-modal input[type=checkbox]:focus { outline: none ; box-shadow: none }'
213
- );
210
+ + `.chatgpt-modal .checkbox-group { margin-top: 15px }
211
+ .chatgpt-modal .checkbox-group label {
212
+ font-size: .7rem ; margin: -.04rem 0 0px .3rem
213
+ color: ${ scheme == 'dark' ? '#e1e1e1' : '#1e1e1e' }}
214
+ .chatgpt-modal input[type=checkbox] { transform: scale(0.7) ;
215
+ border: 1px solid ${ scheme == 'dark' ? 'white' : 'black' }}
216
+ .chatgpt-modal input[type=checkbox]:checked {
217
+ border: 1px solid ${ scheme == 'dark' ? 'white' : 'black' } ;
218
+ background-color: black ; position: inherit }
219
+ .chatgpt-modal input[type=checkbox]:focus {
220
+ outline: none ; box-shadow: none ; -webkit-box-shadow: none ; -moz-box-shadow: none }`
221
+ )
214
222
  }
215
223
 
216
224
  // Insert text into elements
@@ -277,7 +285,7 @@ const chatgpt = {
277
285
  closeSVG.append(closeSVGpath); closeBtn.append(closeSVG);
278
286
 
279
287
  // Assemble/append div
280
- const modalElems = [closeBtn, modalTitle, modalMessage, modalButtons, checkboxDiv];
288
+ const modalElems = [closeBtn, modalTitle, modalMessage, checkboxDiv, modalButtons ];
281
289
  modalElems.forEach((elem) => { modal.append(elem); });
282
290
  modal.style.width = `${ width || 458 }px`;
283
291
  modalContainer.append(modal); document.body.append(modalContainer);
@@ -942,7 +950,12 @@ const chatgpt = {
942
950
  getLastResponse() { return chatgpt.getChatData('active', 'msg', 'chatgpt', 'latest'); },
943
951
 
944
952
  getNewChatButton() {
945
- return document.querySelector('button[data-testid*=new-chat-button], button:has([d^="M15.6729"])'); },
953
+ return document.querySelector(
954
+ 'button[data-testid*=new-chat-button],' // sidebar button (when logged in)
955
+ + 'button:has([d^="M3.06957"]),' // Cycle Arrows icon (Temp chat mode)
956
+ + 'button:has([d^="M15.6729"])' // Pencil icon (recorded chat mode)
957
+ )
958
+ },
946
959
 
947
960
  getNewChatLink() { return document.querySelector('nav a[href="/"]'); },
948
961
  getRegenerateButton() { return document.querySelector('button:has([d^="M3.06957"])'); },
@@ -978,14 +991,14 @@ const chatgpt = {
978
991
 
979
992
  history: {
980
993
  async isLoaded(timeout = null) {
981
- const timeoutPromise = timeout ? new Promise(resolve => setTimeout(() => resolve(false), timeout)) : null;
994
+ const timeoutPromise = timeout ? new Promise(resolve => setTimeout(() => resolve(false), timeout)) : null
982
995
  const isLoadedPromise = new Promise(resolve => {
983
- if (document.querySelector('nav')) resolve(true);
996
+ if (document.querySelector('nav')) resolve(true)
984
997
  else new MutationObserver((_, obs) => {
985
- if (document.querySelector('nav')) { obs.disconnect(); resolve(true); }
986
- }).observe(document.body, { childList: true, subtree: true });
987
- });
988
- return await ( timeoutPromise ? Promise.race([isLoadedPromise, timeoutPromise]) : isLoadedPromise );
998
+ if (document.querySelector('nav')) { obs.disconnect() ; resolve(true) }
999
+ }).observe(document.documentElement, { childList: true, subtree: true })
1000
+ })
1001
+ return await ( timeoutPromise ? Promise.race([isLoadedPromise, timeoutPromise]) : isLoadedPromise )
989
1002
  }
990
1003
  },
991
1004
 
@@ -1146,14 +1159,14 @@ const chatgpt = {
1146
1159
  },
1147
1160
 
1148
1161
  async isLoaded(timeout = null) {
1149
- const timeoutPromise = timeout ? new Promise(resolve => setTimeout(() => resolve(false), timeout)) : null;
1162
+ const timeoutPromise = timeout ? new Promise(resolve => setTimeout(() => resolve(false), timeout)) : null
1150
1163
  const isLoadedPromise = new Promise(resolve => {
1151
- if (chatgpt.getNewChatBtn()) resolve(true);
1164
+ if (chatgpt.getNewChatBtn()) resolve(true)
1152
1165
  else new MutationObserver((_, obs) => {
1153
- if (chatgpt.getNewChatBtn()) { obs.disconnect(); resolve(true); }
1154
- }).observe(document.body, { childList: true, subtree: true });
1155
- });
1156
- return await ( timeoutPromise ? Promise.race([isLoadedPromise, timeoutPromise]) : isLoadedPromise );
1166
+ if (chatgpt.getNewChatBtn()) { obs.disconnect() ; resolve(true) }
1167
+ }).observe(document.documentElement, { childList: true, subtree: true })
1168
+ })
1169
+ return await ( timeoutPromise ? Promise.race([isLoadedPromise, timeoutPromise]) : isLoadedPromise )
1157
1170
  },
1158
1171
 
1159
1172
  isLightMode() { return document.documentElement.classList.toString().includes('light'); },
@@ -1309,13 +1322,18 @@ const chatgpt = {
1309
1322
  + 'font-family: -apple-system, system-ui, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC",'
1310
1323
  + '"Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", sans-serif ;'
1311
1324
  + '.no-mobile-tap-outline { outline: none ; -webkit-tap-highlight-color: transparent }'
1312
- + 'background-color: black ; padding: 10px 13px 10px 18px ; border-radius: 11px ; border: 1px solid #f5f5f7 ;' // bubble style
1325
+ + 'background-color: black ; padding: 10px 13px 10px 18px ;' // bubble style
1326
+ + 'border-radius: 11px ; border: 1px solid #f5f5f7 ;'
1313
1327
  + 'opacity: 0 ; position: fixed ; z-index: 9999 ; font-size: 1.8rem ; color: white ;' // visibility
1314
1328
  + 'user-select: none ; -webkit-user-select: none ; -moz-user-select: none ; -o-user-select: none ;'
1315
1329
  + '-ms-user-select: none ;'
1316
- + `transform: translateX(${ !notificationDiv.isRight ? '-' : '' }35px) ;` // init off-screen for transition fx
1317
- + ( shadow ? ( 'box-shadow: -8px 13px 25px 0 ' + ( /\b(?:shadow|on)\b/i.test(shadow) ? 'gray' : shadow )) : '' ) + '}'
1318
- + '.notif-close-btn { cursor: pointer ; float: right ; position: relative ; right: -4px ; margin-left: -3px ;'
1330
+ + `transform: translateX(${ // init off-screen for transition fx
1331
+ !notificationDiv.isRight ? '-' : '' }35px) ;`
1332
+ + ( shadow ? `--shadow: -8px 13px 25px 0 ${ /\b(?:shadow|on)\b/i.test(shadow) ? 'gray' : shadow };
1333
+ box-shadow: var(--shadow) ; -webkit-box-shadow: var(--shadow) ; -moz-box-shadow: var(--shadow)`
1334
+ : '' ) + '}'
1335
+ + `.notif-close-btn {
1336
+ cursor: pointer ; float: right ; position: relative ; right: -4px ; margin-left: -3px ;`
1319
1337
  + 'display: grid }' // top-align for non-OpenAI sites
1320
1338
  + '@keyframes notif-zoom-fade-out { 0% { opacity: 1 ; transform: scale(1) }' // transition out keyframes
1321
1339
  + '15% { opacity: 0.35 ; transform: rotateX(-27deg) scale(1.05) }'
@@ -1853,15 +1871,15 @@ const chatgpt = {
1853
1871
  },
1854
1872
 
1855
1873
  async isLoaded(timeout = 5000) {
1856
- await chatgpt.isLoaded();
1857
- const timeoutPromise = new Promise(resolve => setTimeout(() => { resolve(false); }, timeout));
1874
+ await chatgpt.isLoaded()
1875
+ const timeoutPromise = new Promise(resolve => setTimeout(() => resolve(false), timeout))
1858
1876
  const isLoadedPromise = new Promise(resolve => {
1859
- if (chatgpt.getNewChatLink()) resolve(true);
1877
+ if (chatgpt.getNewChatLink()) resolve(true)
1860
1878
  else new MutationObserver((_, obs) => {
1861
- if (chatgpt.getNewChatLink()) { obs.disconnect(); resolve(true); }
1862
- }).observe(document.body, { childList: true, subtree: true });
1863
- });
1864
- return await Promise.race([isLoadedPromise, timeoutPromise]);
1879
+ if (chatgpt.getNewChatLink()) { obs.disconnect() ; resolve(true) }
1880
+ }).observe(document.documentElement, { childList: true, subtree: true })
1881
+ })
1882
+ return await Promise.race([isLoadedPromise, timeoutPromise])
1865
1883
  }
1866
1884
  },
1867
1885
 
@@ -1879,7 +1897,7 @@ const chatgpt = {
1879
1897
  return chatgpt.getChatData('active', 'msg', 'chatgpt', 'latest');
1880
1898
  },
1881
1899
 
1882
- speak(msg, { voice = 2, pitch = 2, speed = 1.1, onend } = {} ) { // eslint-disable-line no-unused-vars
1900
+ speak(msg, { voice = 2, pitch = 2, speed = 1.1, onend } = {} ) {
1883
1901
  // Example call: chatgpt.speak(await chatgpt.getLastResponse(), { voice: 1, pitch: 2, speed: 3 })
1884
1902
  // - voice = index of voices available on user device
1885
1903
  // - pitch = float for pitch of speech from 0 to 2
@@ -1900,8 +1918,8 @@ const chatgpt = {
1900
1918
  }
1901
1919
 
1902
1920
  try { // to speak msg
1903
- const utterance = new SpeechSynthesisUtterance()
1904
- Object.assign(utterance, { text: msg, ...arguments[1], voice: speechSynthesis.getVoices()[voice] })
1921
+ const utterance = new SpeechSynthesisUtterance(), voices = speechSynthesis.getVoices()
1922
+ Object.assign(utterance, { text: msg, voice: voices[voice], pitch: pitch, speed: speed, onend: onend })
1905
1923
  speechSynthesis.speak(utterance)
1906
1924
  } catch (err) { console.error(err) }
1907
1925
  },