@kudoai/chatgpt.js 3.8.4 → 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/README.md +9 -9
- package/chatgpt.js +43 -42
- package/dist/chatgpt.min.js +7 -7
- package/docs/README.md +9 -9
- package/docs/USERGUIDE.md +3 -3
- package/package.json +11 -10
- package/starters/chrome/extension/components/modals.js +2 -2
- package/starters/chrome/extension/content.js +1 -1
- package/starters/chrome/extension/lib/chatgpt.js +43 -42
- package/starters/chrome/extension/manifest.json +1 -1
- package/starters/chrome/extension/popup/style.css +1 -2
- package/starters/greasemonkey/chatgpt.js-greasemonkey-starter.user.js +3 -2
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.
|
|
55
|
-
<img src="https://img.shields.io/github/size/KudoAI/chatgpt.js/dist/chatgpt.min.js?branch=v3.8.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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
|
|
|
@@ -419,6 +417,8 @@ This library exists thanks to code, translations, issues & ideas from the follow
|
|
|
419
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>
|
|
420
418
|
<a href="https://github.com/ahnupeng" target="_blank" rel="noopener">
|
|
421
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>
|
|
422
422
|
<a href="https://github.com/dependabot" target="_blank" rel="noopener">
|
|
423
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>
|
|
424
424
|
<a href="https://chatgpt.com" target="_blank" rel="noopener">
|
|
@@ -482,7 +482,7 @@ This library exists thanks to code, translations, issues & ideas from the follow
|
|
|
482
482
|
<div align="center">
|
|
483
483
|
|
|
484
484
|
**[Releases](https://github.com/KudoAI/chatgpt.js/releases)** /
|
|
485
|
-
[Userguide](https://github.com/KudoAI/chatgpt.js/blob/v3.8.
|
|
485
|
+
[Userguide](https://github.com/KudoAI/chatgpt.js/blob/v3.8.5/docs/USERGUIDE.md) /
|
|
486
486
|
[Discuss](https://github.com/KudoAI/chatgpt.js/discussions) /
|
|
487
487
|
[Back to top ↑](#top)
|
|
488
488
|
|
package/chatgpt.js
CHANGED
|
@@ -371,7 +371,7 @@ const chatgpt = {
|
|
|
371
371
|
document.removeEventListener('keydown', handlers.dismiss.key) // prevent memory leaks
|
|
372
372
|
|
|
373
373
|
// Check for pending alerts in queue
|
|
374
|
-
if (alertQueue.length
|
|
374
|
+
if (alertQueue.length) {
|
|
375
375
|
const nextAlert = document.getElementById(alertQueue[0])
|
|
376
376
|
setTimeout(() => {
|
|
377
377
|
nextAlert.style.display = ''
|
|
@@ -409,7 +409,7 @@ const chatgpt = {
|
|
|
409
409
|
}
|
|
410
410
|
scheduleRefreshes(interval)
|
|
411
411
|
}, (interval + randomDelay) * 1000)
|
|
412
|
-
}
|
|
412
|
+
}
|
|
413
413
|
scheduleRefreshes( interval ? parseInt(interval, 10) : 30 )
|
|
414
414
|
console.log(`↻ ChatGPT >> [${chatgpt.autoRefresh.nowTimeStamp()}] Auto refresh activated`)
|
|
415
415
|
|
|
@@ -432,7 +432,7 @@ const chatgpt = {
|
|
|
432
432
|
const now = new Date()
|
|
433
433
|
const hours = now.getHours() % 12 || 12 // convert to 12h format
|
|
434
434
|
let minutes = now.getMinutes(), seconds = now.getSeconds()
|
|
435
|
-
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
|
|
436
436
|
const meridiem = now.getHours() < 12 ? 'AM' : 'PM'
|
|
437
437
|
return `${hours}:${minutes}:${seconds} ${meridiem}`
|
|
438
438
|
},
|
|
@@ -574,7 +574,7 @@ const chatgpt = {
|
|
|
574
574
|
|
|
575
575
|
async refactor(code, objective) {
|
|
576
576
|
if (!code) return console.error('Code (1st) argument not supplied. Pass some code!')
|
|
577
|
-
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')
|
|
578
578
|
return console.error(`Argument ${ i + 1 } must be a string.`)
|
|
579
579
|
chatgpt.send(`Refactor the following code for ${ objective || 'brevity' }:\n\n${code}`)
|
|
580
580
|
console.info('Refactoring code...')
|
|
@@ -603,7 +603,7 @@ const chatgpt = {
|
|
|
603
603
|
async write(prompt, outputLang) {
|
|
604
604
|
if (!prompt) return console.error('Prompt (1st) argument not supplied. Pass a prompt!')
|
|
605
605
|
if (!outputLang) return console.error('outputLang (2nd) argument not supplied. Pass a language!')
|
|
606
|
-
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')
|
|
607
607
|
return console.error(`Argument ${ i + 1 } must be a string.`)
|
|
608
608
|
chatgpt.send(`${prompt}\n\nWrite this as code in ${outputLang}`)
|
|
609
609
|
console.info('Writing code...')
|
|
@@ -657,7 +657,7 @@ const chatgpt = {
|
|
|
657
657
|
if (!chatDivs.length) return console.error('Chat is empty!')
|
|
658
658
|
const msgs = [] ; let isUserMsg = true
|
|
659
659
|
chatDivs.forEach(div => {
|
|
660
|
-
const sender = isUserMsg ? 'USER' : 'CHATGPT'; isUserMsg = !isUserMsg
|
|
660
|
+
const sender = isUserMsg ? 'USER' : 'CHATGPT' ; isUserMsg = !isUserMsg
|
|
661
661
|
const msg = [...div.childNodes].map(node => node.innerText)
|
|
662
662
|
.join('\n\n') // insert double line breaks between paragraphs
|
|
663
663
|
.replace('Copy code', '')
|
|
@@ -686,7 +686,7 @@ const chatgpt = {
|
|
|
686
686
|
cssLinks.forEach(link => {
|
|
687
687
|
const href = link.getAttribute('href')
|
|
688
688
|
if (href?.startsWith('/')) link.setAttribute('href', 'https://chat.openai.com' + href)
|
|
689
|
-
})
|
|
689
|
+
})
|
|
690
690
|
|
|
691
691
|
// Serialize updated HTML to string
|
|
692
692
|
transcript = new XMLSerializer().serializeToString(parsedHtml)
|
|
@@ -711,7 +711,7 @@ const chatgpt = {
|
|
|
711
711
|
|
|
712
712
|
if (format == 'md') { // remove extraneous HTML + fix file extension
|
|
713
713
|
const mdMatch = /<.*<h1(.|\n)*?href=".*?continue[^"]*".*?\/a>.*?<[^/]/.exec(transcript)[1]
|
|
714
|
-
transcript = mdMatch || transcript; filename = filename.replace('.html', '.md')
|
|
714
|
+
transcript = mdMatch || transcript ; filename = filename.replace('.html', '.md')
|
|
715
715
|
}
|
|
716
716
|
const blob = new Blob([transcript],
|
|
717
717
|
{ type: 'text/' + ( format == 'html' ? 'html' : format == 'md' ? 'markdown' : 'plain' )})
|
|
@@ -769,7 +769,7 @@ const chatgpt = {
|
|
|
769
769
|
}}
|
|
770
770
|
if (!targetNames.includes(targetName.toLowerCase()))
|
|
771
771
|
throw new Error(`Invalid targetName: ${targetName}. `
|
|
772
|
-
+ (targetNames.length
|
|
772
|
+
+ (targetNames.length ? 'Valid values are: ' + JSON.stringify(targetNames)
|
|
773
773
|
: 'targetType ' + targetType.toLowerCase() + ' does not require additional options.'))
|
|
774
774
|
|
|
775
775
|
// Call target function using pre-validated name components
|
|
@@ -927,7 +927,7 @@ const chatgpt = {
|
|
|
927
927
|
|
|
928
928
|
// Fill [userMessages]
|
|
929
929
|
for (const key in data)
|
|
930
|
-
if (data[key]
|
|
930
|
+
if (data[key]?.message?.author?.role == 'user')
|
|
931
931
|
userMessages.push({ id: data[key].id, msg: data[key].message })
|
|
932
932
|
userMessages.sort((a, b) => a.msg.create_time - b.msg.create_time) // sort in chronological order
|
|
933
933
|
|
|
@@ -938,12 +938,10 @@ const chatgpt = {
|
|
|
938
938
|
// Fill [chatGPTMessages]
|
|
939
939
|
for (const userMessage of userMessages) {
|
|
940
940
|
let sub = []
|
|
941
|
-
for (const key in data)
|
|
942
|
-
if (data[key]
|
|
943
|
-
&& isUserMsgAncestor(key, userMessage.id)
|
|
944
|
-
|
|
945
|
-
}
|
|
946
|
-
}
|
|
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)
|
|
947
945
|
sub.sort((a, b) => a.create_time - b.create_time) // sort in chronological order
|
|
948
946
|
sub = sub.map(x => { // pull out msgs after sorting
|
|
949
947
|
switch(x.content.content_type) {
|
|
@@ -961,7 +959,8 @@ const chatgpt = {
|
|
|
961
959
|
msgsToReturn.push(userMessages[userMessage].msg.content.parts[0])
|
|
962
960
|
else if (sender == 'chatgpt') // Fill [msgsToReturn] with ChatGPT responses
|
|
963
961
|
for (const chatGPTMessage of chatGPTMessages)
|
|
964
|
-
msgsToReturn.push(msgToGet == 'latest' ? chatGPTMessages[chatGPTMessages.length - 1]
|
|
962
|
+
msgsToReturn.push(msgToGet == 'latest' ? chatGPTMessages[chatGPTMessages.length - 1]
|
|
963
|
+
: chatGPTMessage )
|
|
965
964
|
else { // Fill [msgsToReturn] with objects of user messages and chatgpt response(s)
|
|
966
965
|
let i = 0
|
|
967
966
|
for (const message in userMessages) {
|
|
@@ -1077,9 +1076,9 @@ const chatgpt = {
|
|
|
1077
1076
|
else if (target == 'chatgpt') instructionsData.about_model_message += instruction
|
|
1078
1077
|
|
|
1079
1078
|
await this.sendRequest('POST', token, instructionsData)
|
|
1080
|
-
return resolve()
|
|
1081
|
-
})
|
|
1082
|
-
})
|
|
1079
|
+
return resolve()
|
|
1080
|
+
})
|
|
1081
|
+
})
|
|
1083
1082
|
},
|
|
1084
1083
|
|
|
1085
1084
|
clear(target) {
|
|
@@ -1134,7 +1133,7 @@ const chatgpt = {
|
|
|
1134
1133
|
xhr.onload = () => {
|
|
1135
1134
|
const responseData = JSON.parse(xhr.responseText)
|
|
1136
1135
|
if (xhr.status == 422)
|
|
1137
|
-
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.')
|
|
1138
1137
|
else if (xhr.status == 403 && responseData.detail.reason == 'content_policy')
|
|
1139
1138
|
return reject('🤖 chatgpt.js >> ' + responseData.detail.description)
|
|
1140
1139
|
else if (xhr.status != 200)
|
|
@@ -1259,7 +1258,7 @@ const chatgpt = {
|
|
|
1259
1258
|
if (!attrs.items.every(el => typeof el == 'object')) // the entries of the array are not objects
|
|
1260
1259
|
return console.error('\'items\' must be an array of objects!')
|
|
1261
1260
|
|
|
1262
|
-
newElem.style = 'background-color: #000; width: 100
|
|
1261
|
+
newElem.style = 'background-color: #000 ; width: 100% ; border: none'
|
|
1263
1262
|
|
|
1264
1263
|
attrs.items.forEach(item => {
|
|
1265
1264
|
const optionElement = document.createElement('option')
|
|
@@ -1302,7 +1301,7 @@ const chatgpt = {
|
|
|
1302
1301
|
}
|
|
1303
1302
|
},
|
|
1304
1303
|
|
|
1305
|
-
minify() { chatgpt.code.minify()
|
|
1304
|
+
minify() { chatgpt.code.minify() },
|
|
1306
1305
|
|
|
1307
1306
|
notify(...args) {
|
|
1308
1307
|
const scheme = chatgpt.isDarkMode() ? 'dark' : 'light'
|
|
@@ -1310,7 +1309,7 @@ const chatgpt = {
|
|
|
1310
1309
|
if (typeof args[0] == 'object' && !Array.isArray(args[0]))
|
|
1311
1310
|
({ msg, position, notifDuration, shadow, toast } = args[0])
|
|
1312
1311
|
else [msg, position, notifDuration, shadow] = args
|
|
1313
|
-
notifDuration = notifDuration ? +notifDuration : 1.75
|
|
1312
|
+
notifDuration = notifDuration ? +notifDuration : 1.75 // sec duration to maintain notification visibility
|
|
1314
1313
|
const fadeDuration = 0.35, // sec duration of fade-out
|
|
1315
1314
|
vpYoffset = 23, vpXoffset = 27 // px offset from viewport border
|
|
1316
1315
|
|
|
@@ -1323,7 +1322,7 @@ const chatgpt = {
|
|
|
1323
1322
|
|
|
1324
1323
|
// Create/append close button
|
|
1325
1324
|
const closeBtn = document.createElement('div')
|
|
1326
|
-
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')
|
|
1327
1326
|
const closeSVG = document.createElementNS('http://www.w3.org/2000/svg', 'svg')
|
|
1328
1327
|
closeSVG.setAttribute('height', '8px')
|
|
1329
1328
|
closeSVG.setAttribute('viewBox', '0 0 14 14')
|
|
@@ -1333,7 +1332,7 @@ const chatgpt = {
|
|
|
1333
1332
|
closeSVGpath.setAttribute('fill-rule', 'evenodd')
|
|
1334
1333
|
closeSVGpath.setAttribute('clip-rule', 'evenodd')
|
|
1335
1334
|
closeSVGpath.setAttribute('fill', 'white')
|
|
1336
|
-
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')
|
|
1337
1336
|
closeSVG.append(closeSVGpath) ; closeBtn.append(closeSVG) ; notificationDiv.append(closeBtn)
|
|
1338
1337
|
|
|
1339
1338
|
// Determine div position/quadrant
|
|
@@ -1420,7 +1419,7 @@ const chatgpt = {
|
|
|
1420
1419
|
|
|
1421
1420
|
// Add notification dismissal to timeout schedule + button clicks
|
|
1422
1421
|
const dismissNotif = () => {
|
|
1423
|
-
notificationDiv.style.animation = `notif-zoom-fade-out ${fadeDuration}s ease-out
|
|
1422
|
+
notificationDiv.style.animation = `notif-zoom-fade-out ${fadeDuration}s ease-out`
|
|
1424
1423
|
clearTimeout(dismissFuncTID)
|
|
1425
1424
|
}
|
|
1426
1425
|
const dismissFuncTID = setTimeout(dismissNotif, hideDelay * 1000) // maintain visibility for `hideDelay` secs, then dismiss
|
|
@@ -1472,7 +1471,7 @@ const chatgpt = {
|
|
|
1472
1471
|
|
|
1473
1472
|
// Print methods
|
|
1474
1473
|
const isDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches,
|
|
1475
|
-
baseFontStyles = 'font-family: monospace ; font-size: larger ;
|
|
1474
|
+
baseFontStyles = 'font-family: monospace ; font-size: larger ;'
|
|
1476
1475
|
console.log('\n%c🤖 chatgpt.js methods\n', 'font-family: sans-serif ; font-size: xxx-large ; font-weight: bold')
|
|
1477
1476
|
for (const functionName of functionNames) {
|
|
1478
1477
|
const isChatGptObjParent = /chatgpt|other/.test(functionName[0]),
|
|
@@ -1535,7 +1534,7 @@ const chatgpt = {
|
|
|
1535
1534
|
elems = [...text.matchAll(reTags)]
|
|
1536
1535
|
|
|
1537
1536
|
// Process 1st element to render
|
|
1538
|
-
if (elems.length
|
|
1537
|
+
if (elems.length) {
|
|
1539
1538
|
const elem = elems[0],
|
|
1540
1539
|
[tagContent, tagName, tagAttrs, tagText] = elem.slice(0, 4),
|
|
1541
1540
|
tagNode = document.createElement(tagName) ; tagNode.textContent = tagText
|
|
@@ -1585,7 +1584,7 @@ const chatgpt = {
|
|
|
1585
1584
|
// chatToGet = index|title|id of chat to get (defaults to latest if '' or unpassed)
|
|
1586
1585
|
// responseToGet = index of response to get (defaults to latest if '' or unpassed)
|
|
1587
1586
|
|
|
1588
|
-
chatToGet = chatToGet || 'latest'; responseToGet = responseToGet || 'latest'
|
|
1587
|
+
chatToGet = chatToGet || 'latest' ; responseToGet = responseToGet || 'latest'
|
|
1589
1588
|
return chatgpt.getChatData(chatToGet, 'msg', 'chatgpt', responseToGet)
|
|
1590
1589
|
},
|
|
1591
1590
|
|
|
@@ -1638,7 +1637,7 @@ const chatgpt = {
|
|
|
1638
1637
|
return console.error(`Argument ${ i + 1 } must be a string!`)
|
|
1639
1638
|
const textArea = chatgpt.getChatBox()
|
|
1640
1639
|
if (!textArea) return console.error('Chatbar element not found!')
|
|
1641
|
-
const msgP = document.createElement('p'); msgP.textContent = msg
|
|
1640
|
+
const msgP = document.createElement('p') ; msgP.textContent = msg
|
|
1642
1641
|
textArea.querySelector('p').replaceWith(msgP)
|
|
1643
1642
|
textArea.dispatchEvent(new Event('input', { bubbles: true })) // enable send button
|
|
1644
1643
|
setTimeout(function delaySend() {
|
|
@@ -1688,7 +1687,7 @@ const chatgpt = {
|
|
|
1688
1687
|
},
|
|
1689
1688
|
|
|
1690
1689
|
async sentiment(text, entity) {
|
|
1691
|
-
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')
|
|
1692
1691
|
return console.error(`Argument ${ i + 1 } must be a string.`)
|
|
1693
1692
|
chatgpt.send('What is the sentiment of the following text'
|
|
1694
1693
|
+ ( entity ? ` towards the entity ${entity},` : '')
|
|
@@ -1883,7 +1882,7 @@ const chatgpt = {
|
|
|
1883
1882
|
return newElem.id // Return the element id
|
|
1884
1883
|
},
|
|
1885
1884
|
|
|
1886
|
-
exists() { return !!chatgpt.getNewChatLink()
|
|
1885
|
+
exists() { return !!chatgpt.getNewChatLink() },
|
|
1887
1886
|
hide() { this.isOn() ? this.toggle() : console.info('Sidebar already hidden!') },
|
|
1888
1887
|
show() { this.isOff() ? this.toggle() : console.info('Sidebar already shown!') },
|
|
1889
1888
|
isOff() { return !this.isOn() },
|
|
@@ -1917,12 +1916,12 @@ const chatgpt = {
|
|
|
1917
1916
|
},
|
|
1918
1917
|
|
|
1919
1918
|
startNewChat() { try { chatgpt.getNewChatBtn().click() } catch (err) { console.error(err.message) }},
|
|
1920
|
-
stop() { chatgpt.response.stopGenerating()
|
|
1919
|
+
stop() { chatgpt.response.stopGenerating() },
|
|
1921
1920
|
|
|
1922
1921
|
async suggest(ideaType, details) {
|
|
1923
1922
|
if (!ideaType) return console.error('ideaType (1st argument) not supplied'
|
|
1924
1923
|
+ `(e.g. 'gifts', 'names', 'recipes', etc.)`)
|
|
1925
|
-
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')
|
|
1926
1925
|
return console.error(`Argument ${ i + 1 } must be a string.`)
|
|
1927
1926
|
chatgpt.send('Suggest some names. ' + ( details || '' ))
|
|
1928
1927
|
console.info(`Creating ${ideaType}...`)
|
|
@@ -1966,7 +1965,7 @@ const chatgpt = {
|
|
|
1966
1965
|
return chatgpt.getChatData('active', 'msg', 'chatgpt', 'latest')
|
|
1967
1966
|
},
|
|
1968
1967
|
|
|
1969
|
-
toggleScheme() { chatgpt.settings.scheme.toggle()
|
|
1968
|
+
toggleScheme() { chatgpt.settings.scheme.toggle() },
|
|
1970
1969
|
|
|
1971
1970
|
async translate(text, outputLang) {
|
|
1972
1971
|
if (!text) return console.error('Text (1st) argument not supplied. Pass some text!')
|
|
@@ -1991,7 +1990,7 @@ const chatgpt = {
|
|
|
1991
1990
|
const r = ( // generate random nibble
|
|
1992
1991
|
( d + (window.crypto.getRandomValues(new Uint32Array(1))[0] / (Math.pow(2, 32) - 1))*16)%16 | 0 )
|
|
1993
1992
|
d = Math.floor(d/16) // correspond each UUID digit to unique 4-bit chunks of timestamp
|
|
1994
|
-
return ( c == 'x' ? r : (r&0x3|0x8) ).toString(16)
|
|
1993
|
+
return ( c == 'x' ? r : (r&0x3|0x8) ).toString(16) // generate random hexadecimal digit
|
|
1995
1994
|
})
|
|
1996
1995
|
return uuid
|
|
1997
1996
|
}
|
|
@@ -2092,8 +2091,8 @@ const cjsFuncSynonyms = [
|
|
|
2092
2091
|
['temp', 'temporary'],
|
|
2093
2092
|
['typing', 'generating'],
|
|
2094
2093
|
['unminify', 'beautify', 'prettify', 'prettyPrint']
|
|
2095
|
-
]
|
|
2096
|
-
(function createCJSaliasFuncs(obj = chatgpt) {
|
|
2094
|
+
]
|
|
2095
|
+
;(function createCJSaliasFuncs(obj = chatgpt) {
|
|
2097
2096
|
for (const prop in obj) {
|
|
2098
2097
|
if (!Object.prototype.hasOwnProperty.call(obj, prop)) continue // skip inherited props
|
|
2099
2098
|
if (typeof obj[prop] == 'object') createCJSaliasFuncs(obj[prop]) // recurse thru objs to find deeper functions
|
|
@@ -2134,11 +2133,13 @@ function toCamelCase(words) {
|
|
|
2134
2133
|
// Prefix console logs w/ '🤖 chatgpt.js >> '
|
|
2135
2134
|
const consolePrefix = '🤖 chatgpt.js >> ', ogError = console.error, ogInfo = console.info
|
|
2136
2135
|
console.error = (...args) => {
|
|
2137
|
-
if (
|
|
2138
|
-
|
|
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)
|
|
2139
2140
|
}
|
|
2140
2141
|
console.info = (msg) => {
|
|
2141
|
-
if (!msg.startsWith(consolePrefix)) ogInfo(consolePrefix + msg)
|
|
2142
|
+
if (!msg.startsWith(consolePrefix)) ogInfo(consolePrefix + msg)
|
|
2142
2143
|
else ogInfo(msg)
|
|
2143
2144
|
}
|
|
2144
2145
|
|