@kudoai/chatgpt.js 2.6.4 → 2.6.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.
Files changed (178) hide show
  1. package/README.md +341 -0
  2. package/chatgpt.js +6 -4
  3. package/dist/chatgpt.min.js +7 -0
  4. package/docs/README.md +341 -324
  5. package/docs/USERGUIDE.md +1812 -1814
  6. package/docs/de/README.md +341 -324
  7. package/docs/es/README.md +341 -324
  8. package/docs/fr/README.md +341 -324
  9. package/docs/hi/README.md +342 -325
  10. package/docs/it/README.md +341 -324
  11. package/docs/ja/README.md +341 -324
  12. package/docs/ko/README.md +346 -329
  13. package/docs/ne/README.md +342 -325
  14. package/docs/nl/README.md +341 -324
  15. package/docs/pt/README.md +341 -324
  16. package/docs/vi/README.md +341 -324
  17. package/docs/zh-cn/README.md +341 -324
  18. package/docs/zh-tw/README.md +340 -323
  19. package/package.json +50 -30
  20. package/starters/chrome/LICENSE.md +43 -0
  21. package/starters/chrome/docs/README.md +17 -1
  22. package/starters/chrome/docs/SECURITY.md +17 -0
  23. package/starters/chrome/docs/de/LICENSE.md +21 -3
  24. package/starters/chrome/docs/de/README.md +17 -1
  25. package/starters/chrome/docs/es/LICENSE.md +21 -3
  26. package/starters/chrome/docs/es/README.md +17 -1
  27. package/starters/chrome/docs/fr/LICENSE.md +21 -3
  28. package/starters/chrome/docs/fr/README.md +17 -1
  29. package/starters/chrome/docs/hi/LICENSE.md +21 -3
  30. package/starters/chrome/docs/hi/README.md +17 -2
  31. package/starters/chrome/docs/hi/SECURITY.md +17 -0
  32. package/starters/chrome/docs/it/LICENSE.md +21 -3
  33. package/starters/chrome/docs/it/README.md +17 -1
  34. package/starters/chrome/docs/ja/LICENSE.md +21 -3
  35. package/starters/chrome/docs/ja/README.md +17 -2
  36. package/starters/chrome/docs/ko/LICENSE.md +21 -3
  37. package/starters/chrome/docs/ko/README.md +17 -1
  38. package/starters/chrome/docs/nl/LICENSE.md +20 -3
  39. package/starters/chrome/docs/nl/README.md +17 -1
  40. package/starters/chrome/docs/pt/LICENSE.md +21 -3
  41. package/starters/chrome/docs/pt/README.md +17 -1
  42. package/starters/chrome/docs/vi/LICENSE.md +21 -3
  43. package/starters/chrome/docs/vi/README.md +17 -1
  44. package/starters/chrome/docs/zh-cn/LICENSE.md +21 -3
  45. package/starters/chrome/docs/zh-cn/README.md +17 -2
  46. package/starters/chrome/docs/zh-cn/SECURITY.md +17 -0
  47. package/starters/chrome/docs/zh-tw/LICENSE.md +21 -3
  48. package/starters/chrome/docs/zh-tw/README.md +17 -1
  49. package/starters/chrome/extension/content.js +1 -1
  50. package/starters/chrome/extension/lib/chatgpt.js +6 -4
  51. package/starters/chrome/extension/manifest.json +1 -1
  52. package/starters/greasemonkey/LICENSE.md +43 -0
  53. package/starters/greasemonkey/chatgpt.js-greasemonkey-starter.user.js +52 -52
  54. package/starters/greasemonkey/docs/SECURITY.md +17 -0
  55. package/starters/greasemonkey/docs/de/LICENSE.md +31 -0
  56. package/starters/greasemonkey/docs/es/LICENSE.md +31 -0
  57. package/starters/greasemonkey/docs/fr/LICENSE.md +31 -0
  58. package/starters/greasemonkey/docs/hi/LICENSE.md +31 -0
  59. package/starters/greasemonkey/docs/hi/SECURITY.md +17 -0
  60. package/starters/greasemonkey/docs/it/LICENSE.md +29 -0
  61. package/starters/greasemonkey/docs/ja/LICENSE.md +31 -0
  62. package/starters/greasemonkey/docs/ko/LICENSE.md +34 -0
  63. package/starters/greasemonkey/docs/nl/LICENSE.md +30 -0
  64. package/starters/greasemonkey/docs/pt/LICENSE.md +31 -0
  65. package/starters/greasemonkey/docs/vi/LICENSE.md +31 -0
  66. package/starters/greasemonkey/docs/zh-cn/LICENSE.md +31 -0
  67. package/starters/greasemonkey/docs/zh-cn/SECURITY.md +17 -0
  68. package/starters/greasemonkey/docs/zh-tw/LICENSE.md +31 -0
  69. package/dist/chatgpt-2.6.4.min.js +0 -1
  70. package/docs/.nojekyll +0 -0
  71. package/docs/CNAME +0 -1
  72. package/docs/_coverpage.md +0 -16
  73. package/docs/_utils/LICENSE.md +0 -21
  74. package/docs/_utils/minify.js +0 -50
  75. package/docs/assets/docsify/cursors/futuristic/pointer.cur +0 -0
  76. package/docs/assets/docsify/favicons/favicon16.png +0 -0
  77. package/docs/assets/docsify/favicons/favicon320.png +0 -0
  78. package/docs/assets/docsify/favicons/favicon48.png +0 -0
  79. package/docs/assets/docsify/favicons/favicon64.png +0 -0
  80. package/docs/assets/docsify/fonts/eurostile-extended-black/EurostileExtendedBlack.otf +0 -0
  81. package/docs/assets/docsify/fonts/eurostile-extended-black/EurostileExtendedBlack.ttf +0 -0
  82. package/docs/assets/docsify/fonts/eurostile-extended-black/EurostileExtendedBlack.woff +0 -0
  83. package/docs/assets/docsify/fonts/eurostile-extended-black/EurostileExtendedBlack.woff2 +0 -0
  84. package/docs/assets/docsify/fonts/ibm-plex-mono/OFL.txt +0 -93
  85. package/docs/assets/docsify/fonts/ibm-plex-mono/otf/IBMPlexMono-Bold.otf +0 -0
  86. package/docs/assets/docsify/fonts/ibm-plex-mono/otf/IBMPlexMono-BoldItalic.otf +0 -0
  87. package/docs/assets/docsify/fonts/ibm-plex-mono/otf/IBMPlexMono-ExtraLight.otf +0 -0
  88. package/docs/assets/docsify/fonts/ibm-plex-mono/otf/IBMPlexMono-ExtraLightItalic.otf +0 -0
  89. package/docs/assets/docsify/fonts/ibm-plex-mono/otf/IBMPlexMono-Italic.otf +0 -0
  90. package/docs/assets/docsify/fonts/ibm-plex-mono/otf/IBMPlexMono-Light.otf +0 -0
  91. package/docs/assets/docsify/fonts/ibm-plex-mono/otf/IBMPlexMono-LightItalic.otf +0 -0
  92. package/docs/assets/docsify/fonts/ibm-plex-mono/otf/IBMPlexMono-Medium.otf +0 -0
  93. package/docs/assets/docsify/fonts/ibm-plex-mono/otf/IBMPlexMono-MediumItalic.otf +0 -0
  94. package/docs/assets/docsify/fonts/ibm-plex-mono/otf/IBMPlexMono-Regular.otf +0 -0
  95. package/docs/assets/docsify/fonts/ibm-plex-mono/otf/IBMPlexMono-SemiBold.otf +0 -0
  96. package/docs/assets/docsify/fonts/ibm-plex-mono/otf/IBMPlexMono-SemiBoldItalic.otf +0 -0
  97. package/docs/assets/docsify/fonts/ibm-plex-mono/otf/IBMPlexMono-Thin.otf +0 -0
  98. package/docs/assets/docsify/fonts/ibm-plex-mono/otf/IBMPlexMono-ThinItalic.otf +0 -0
  99. package/docs/assets/docsify/fonts/ibm-plex-mono/ttf/IBMPlexMono-Bold.ttf +0 -0
  100. package/docs/assets/docsify/fonts/ibm-plex-mono/ttf/IBMPlexMono-BoldItalic.ttf +0 -0
  101. package/docs/assets/docsify/fonts/ibm-plex-mono/ttf/IBMPlexMono-ExtraLight.ttf +0 -0
  102. package/docs/assets/docsify/fonts/ibm-plex-mono/ttf/IBMPlexMono-ExtraLightItalic.ttf +0 -0
  103. package/docs/assets/docsify/fonts/ibm-plex-mono/ttf/IBMPlexMono-Italic.ttf +0 -0
  104. package/docs/assets/docsify/fonts/ibm-plex-mono/ttf/IBMPlexMono-Light.ttf +0 -0
  105. package/docs/assets/docsify/fonts/ibm-plex-mono/ttf/IBMPlexMono-LightItalic.ttf +0 -0
  106. package/docs/assets/docsify/fonts/ibm-plex-mono/ttf/IBMPlexMono-Medium.ttf +0 -0
  107. package/docs/assets/docsify/fonts/ibm-plex-mono/ttf/IBMPlexMono-MediumItalic.ttf +0 -0
  108. package/docs/assets/docsify/fonts/ibm-plex-mono/ttf/IBMPlexMono-Regular.ttf +0 -0
  109. package/docs/assets/docsify/fonts/ibm-plex-mono/ttf/IBMPlexMono-SemiBold.ttf +0 -0
  110. package/docs/assets/docsify/fonts/ibm-plex-mono/ttf/IBMPlexMono-SemiBoldItalic.ttf +0 -0
  111. package/docs/assets/docsify/fonts/ibm-plex-mono/ttf/IBMPlexMono-Thin.ttf +0 -0
  112. package/docs/assets/docsify/fonts/ibm-plex-mono/ttf/IBMPlexMono-ThinItalic.ttf +0 -0
  113. package/docs/assets/docsify/fonts/ibm-plex-mono/woff/IBMPlexMono-Bold.woff +0 -0
  114. package/docs/assets/docsify/fonts/ibm-plex-mono/woff/IBMPlexMono-BoldItalic.woff +0 -0
  115. package/docs/assets/docsify/fonts/ibm-plex-mono/woff/IBMPlexMono-ExtraLight.woff +0 -0
  116. package/docs/assets/docsify/fonts/ibm-plex-mono/woff/IBMPlexMono-ExtraLightItalic.woff +0 -0
  117. package/docs/assets/docsify/fonts/ibm-plex-mono/woff/IBMPlexMono-Italic.woff +0 -0
  118. package/docs/assets/docsify/fonts/ibm-plex-mono/woff/IBMPlexMono-Light.woff +0 -0
  119. package/docs/assets/docsify/fonts/ibm-plex-mono/woff/IBMPlexMono-LightItalic.woff +0 -0
  120. package/docs/assets/docsify/fonts/ibm-plex-mono/woff/IBMPlexMono-Medium.woff +0 -0
  121. package/docs/assets/docsify/fonts/ibm-plex-mono/woff/IBMPlexMono-MediumItalic.woff +0 -0
  122. package/docs/assets/docsify/fonts/ibm-plex-mono/woff/IBMPlexMono-Regular.woff +0 -0
  123. package/docs/assets/docsify/fonts/ibm-plex-mono/woff/IBMPlexMono-SemiBold.woff +0 -0
  124. package/docs/assets/docsify/fonts/ibm-plex-mono/woff/IBMPlexMono-SemiBoldItalic.woff +0 -0
  125. package/docs/assets/docsify/fonts/ibm-plex-mono/woff/IBMPlexMono-Thin.woff +0 -0
  126. package/docs/assets/docsify/fonts/ibm-plex-mono/woff/IBMPlexMono-ThinItalic.woff +0 -0
  127. package/docs/assets/docsify/fonts/ibm-plex-mono/woff2/IBMPlexMono-Bold.woff2 +0 -0
  128. package/docs/assets/docsify/fonts/ibm-plex-mono/woff2/IBMPlexMono-BoldItalic.woff2 +0 -0
  129. package/docs/assets/docsify/fonts/ibm-plex-mono/woff2/IBMPlexMono-ExtraLight.woff2 +0 -0
  130. package/docs/assets/docsify/fonts/ibm-plex-mono/woff2/IBMPlexMono-ExtraLightItalic.woff2 +0 -0
  131. package/docs/assets/docsify/fonts/ibm-plex-mono/woff2/IBMPlexMono-Italic.woff2 +0 -0
  132. package/docs/assets/docsify/fonts/ibm-plex-mono/woff2/IBMPlexMono-Light.woff2 +0 -0
  133. package/docs/assets/docsify/fonts/ibm-plex-mono/woff2/IBMPlexMono-LightItatlic.woff2 +0 -0
  134. package/docs/assets/docsify/fonts/ibm-plex-mono/woff2/IBMPlexMono-Medium.woff2 +0 -0
  135. package/docs/assets/docsify/fonts/ibm-plex-mono/woff2/IBMPlexMono-MediumItalic.woff2 +0 -0
  136. package/docs/assets/docsify/fonts/ibm-plex-mono/woff2/IBMPlexMono-Regular.woff2 +0 -0
  137. package/docs/assets/docsify/fonts/ibm-plex-mono/woff2/IBMPlexMono-SemiBold.woff2 +0 -0
  138. package/docs/assets/docsify/fonts/ibm-plex-mono/woff2/IBMPlexMono-SemiBoldItalic.woff2 +0 -0
  139. package/docs/assets/docsify/fonts/ibm-plex-mono/woff2/IBMPlexMono-Thin.woff2 +0 -0
  140. package/docs/assets/docsify/fonts/ibm-plex-mono/woff2/IBMPlexMono-ThinItalic.woff2 +0 -0
  141. package/docs/assets/docsify/fonts/major-mono-display/MajorMonoDisplay-Regular.otf +0 -0
  142. package/docs/assets/docsify/fonts/major-mono-display/MajorMonoDisplay-Regular.ttf +0 -0
  143. package/docs/assets/docsify/fonts/major-mono-display/MajorMonoDisplay-Regular.woff +0 -0
  144. package/docs/assets/docsify/fonts/major-mono-display/MajorMonoDisplay-Regular.woff2 +0 -0
  145. package/docs/assets/docsify/fonts/major-mono-display/OFL.txt +0 -93
  146. package/docs/assets/docsify/fonts/polysans-neutral/PolySansNeutral.eot +0 -0
  147. package/docs/assets/docsify/fonts/polysans-neutral/PolySansNeutral.ttf +0 -0
  148. package/docs/assets/docsify/fonts/polysans-neutral/PolySansNeutral.woff +0 -0
  149. package/docs/assets/docsify/fonts/polysans-neutral/PolySansNeutral.woff2 +0 -0
  150. package/docs/assets/docsify/html/footer.html +0 -23
  151. package/docs/assets/docsify/js/min/back-to-top-button.min.js +0 -1
  152. package/docs/assets/docsify/js/min/copy-code-button.min.js +0 -1
  153. package/docs/assets/docsify/js/min/onload-hacks.min.js +0 -3
  154. package/docs/assets/docsify/js/min/starry-background.min.js +0 -1
  155. package/docs/assets/docsify/js/src/back-to-top-button.js +0 -64
  156. package/docs/assets/docsify/js/src/copy-code-button.js +0 -91
  157. package/docs/assets/docsify/js/src/onload-hacks.js +0 -613
  158. package/docs/assets/docsify/js/src/starry-background.js +0 -111
  159. package/docs/assets/docsify/styles/css/style.min.css +0 -1
  160. package/docs/assets/docsify/styles/css/style.min.css.map +0 -1
  161. package/docs/assets/docsify/styles/scss/style.scss +0 -510
  162. package/docs/assets/separators/aqua.png +0 -0
  163. package/docs/de/_coverpage.md +0 -12
  164. package/docs/es/_coverpage.md +0 -12
  165. package/docs/fr/_coverpage.md +0 -12
  166. package/docs/hi/_coverpage.md +0 -12
  167. package/docs/index.html +0 -91
  168. package/docs/it/_coverpage.md +0 -12
  169. package/docs/ja/_coverpage.md +0 -12
  170. package/docs/ko/_coverpage.md +0 -12
  171. package/docs/ne/_coverpage.md +0 -12
  172. package/docs/nl/_coverpage.md +0 -12
  173. package/docs/pt/_coverpage.md +0 -12
  174. package/docs/vi/_coverpage.md +0 -12
  175. package/docs/zh-cn/_coverpage.md +0 -12
  176. package/docs/zh-tw/_coverpage.md +0 -12
  177. package/starters/chrome/LICENSE +0 -21
  178. package/starters/greasemonkey/LICENSE +0 -21
package/docs/USERGUIDE.md CHANGED
@@ -1,1814 +1,1812 @@
1
- <div align="center">
2
-
3
- <picture>
4
- <source type="image/png" media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/kudoai/chatgpt.js/main/media/images/logos/chatgpt.js/with-reflection/darkmode.png">
5
- <img width=700 src="https://raw.githubusercontent.com/kudoai/chatgpt.js/main/media/images/logos/chatgpt.js/with-reflection/lightmode.png">
6
- </picture>
7
-
8
- **chatgpt.js** is a powerful JavaScript library that allows for super easy interaction w/ the ChatGPT DOM.
9
-
10
- </div>
11
-
12
- ## Table of contents
13
-
14
- - [Importing the library](#importing-the-library)
15
- - [ES6](#es6)
16
- - [ES5](#es5)
17
- - [Greasemonkey](#greasemonkey)
18
- - [Chrome](#chrome)
19
- - [Library methods](#library-methods)
20
- - [General](#general)
21
- - [detectLanguage `async`](#detectlanguage-async)
22
- - [executeCode `async`](#executecode-async)
23
- - [generateRandomIP](#generaterandomip)
24
- - [get](#get)
25
- - [getUserLanguage](#getuserlanguage)
26
- - [isChromium](#ischromium)
27
- - [isFirefox](#isfirefox)
28
- - [isFullScreen](#isfullscreen)
29
- - [isLoaded `async`](#isloaded-async)
30
- - [isMobileDevice](#ismobiledevice)
31
- - [printAllFunctions](#printallfunctions)
32
- - [randomFloat](#randomfloat)
33
- - [renderHTML](#renderhtml)
34
- - [sentiment `async`](#sentiment-async)
35
- - [suggest `async`](#suggest-async)
36
- - [summarize `async`](#summarize-async)
37
- - [translate `async`](#translate-async)
38
- - [uuidv4](#uuidv4)
39
- - [Page theme](#page-theme)
40
- - [activateDarkMode](#activatedarkmode)
41
- - [activateLightMode](#activatelightmode)
42
- - [isDarkMode](#isdarkmode)
43
- - [isLightMode](#islightmode)
44
- - [toggleScheme](#togglescheme)
45
- - [In-site notifications](#in-site-notifications)
46
- - [alert](#alert)
47
- - [notify](#notify)
48
- - [User session](#user-session)
49
- - [getAccessToken `async`](#getaccesstoken-async)
50
- - [getAccountDetails `async`](#getaccountdetails-async)
51
- - [logout](#logout)
52
- - [Chats](#chats)
53
- - [askAndGetReply `async`](#askandgetreply-async)
54
- - [clearChats `async`](#clearchats-async)
55
- - [exportChat `async`](#exportchat-async)
56
- - [getChatData `async`](#getchatdata-async)
57
- - [getChatInput](#getchatinput)
58
- - [getLastPrompt `async`](#getlastprompt-async)
59
- - [getLastResponse `async`](#getlastresponse-async)
60
- - [getResponse](#getresponse)
61
- - [getResponseFromAPI `async`](#getresponsefromapi-async)
62
- - [getResponseFromDOM](#getresponsefromdom)
63
- - [isIdle `async`](#isidle-async)
64
- - [regenerate](#regenerate)
65
- - [resend `async`](#resend-async)
66
- - [scrollToBottom](#scrolltobottom)
67
- - [send](#send)
68
- - [sendInNewChat](#sendinnewchat)
69
- - [shareChat `async`](#sharechat-async)
70
- - [speak](#speak)
71
- - [startNewChat](#startnewchat)
72
- - [stop](#stop)
73
- - [DOM related](#dom-related)
74
- - [getChatBox](#getchatbox)
75
- - [getContinueGeneratingButton](#getcontinuegeneratingbutton)
76
- - [getNewChatLink](#getnewchatlink)
77
- - [getRegenerateButton](#getregeneratebutton)
78
- - [getSendButton](#getsendbutton)
79
- - [getStopGeneratingButton](#getstopgeneratingbutton)
80
- - [Library APIs](#library-apis)
81
- - [autoRefresh `api`](#autorefresh-api)
82
- - [activate](#activate)
83
- - [deactivate](#deactivate)
84
- - [nowTimeStamp](#nowtimestamp)
85
- - [browser `api`](#browser-api)
86
- - [isLightMode](#islightmode-1)
87
- - [isDarkMode](#isdarkmode-1)
88
- - [isChromium](#ischromium-1)
89
- - [isFirefox](#isfirefox-1)
90
- - [isFullScreen](#isfullscreen-1)
91
- - [isMobile](#ismobile)
92
- - [code `api`](#code-api)
93
- - [minify `async`](#minify-async)
94
- - [execute `async`](#execute-async)
95
- - [extract](#extract)
96
- - [obfuscate `async`](#obfuscate-async)
97
- - [refactor `async`](#refactor-async)
98
- - [review `async`](#review-async)
99
- - [unminify `async`](#unminify-async)
100
- - [write `async`](#write-async)
101
- - [history `api`](#history-api)
102
- - [isOn](#ison)
103
- - [isOff](#isoff)
104
- - [activate](#activate-1)
105
- - [deactivate](#deactivate-1)
106
- - [isLoaded](#isloaded-async-1)
107
- - [toggle](#toggle)
108
- - [instructions `api`](#instructions-api)
109
- - [add `async`](#add-async)
110
- - [clear `async`](#clear-async)
111
- - [turnOff `async`](#turnoff-async)
112
- - [turnOn `async`](#turnon-async)
113
- - [toggle `async`](#toggle-async)
114
- - [menu `api`](#menu-api)
115
- - [open](#open)
116
- - [close](#close)
117
- - [response `api`](#response-api)
118
- - [get](#get-1)
119
- - [getFromAPI `async`](#getfromapi-async)
120
- - [getFromDOM](#getfromdom)
121
- - [getLast `async`](#getlast-async)
122
- - [regenerate](#regenerate-1)
123
- - [stopGenerating](#stopgenerating)
124
- - [settings `api`](#settings-api)
125
- - [scheme `api subset`](#scheme-api-subset)
126
- - [isDark](#isdark)
127
- - [isLight](#islight)
128
- - [set](#set)
129
- - [toggle](#toggle-1)
130
- - [sidebar `api`](#sidebar-api)
131
- - [append](#append)
132
- - [isOn](#ison-1)
133
- - [isOff](#isoff-1)
134
- - [hide](#hide)
135
- - [show](#show)
136
- - [toggle](#toggle-2)
137
-
138
- # Importing the library
139
-
140
- ## ES6
141
-
142
- ```js
143
- (async () => {
144
- await import('https://code.chatgptjs.org/chatgpt-latest.min.js');
145
- // Your code here...
146
- })();
147
- ```
148
-
149
- ## ES5
150
-
151
- ```js
152
- var xhr = new XMLHttpRequest();
153
- xhr.open('GET', 'https://code.chatgptjs.org/chatgpt-latest.min.js');
154
- xhr.onload = function () {
155
- if (xhr.status === 200) {
156
- var chatgptJS = document.createElement('script');
157
- chatgptJS.textContent = xhr.responseText;
158
- document.head.append(chatgptJS);
159
- yourCode(); // runs your code
160
- }
161
- };
162
- xhr.send();
163
-
164
- function yourCode() {
165
- // Your code here...
166
- }
167
- ```
168
-
169
- ## Greasemonkey
170
-
171
- > **Note** _To use a starter template: [kudoai/chatgpt.js-greasemonkey-starter](https://github.com/kudoai/chatgpt.js-greasemonkey-starter)_
172
-
173
- Userscript repositories like Greasy Fork maintain a whitelist of pre-approved CDNs (such as commit-specific references from `cdn.jsdelivr.net`) so the import URL is substantially lengthier to preserve publishability to these sites:
174
-
175
- ```js
176
- ...
177
- // @require https://cdn.jsdelivr.net/gh/kudoai/chatgpt.js@fb4b04a5956a693726b80325b609cb98be3864d5/dist/chatgpt-2.6.4.min.js
178
- // ==/UserScript==
179
-
180
- // Your code here...
181
- ```
182
-
183
- If you don't plan on publishing to these repos, the simpler `https://code.chatgptjs.org/chatgpt-latest.min.js` can be used instead to import the latest minified release.
184
-
185
- ## Chrome
186
-
187
- > **Note** _To use a starter template: [kudoai/chatgpt.js-chrome-starter](https://github.com/kudoai/chatgpt.js-chrome-starter)_
188
-
189
- 1. Save https://raw.githubusercontent.com/kudoai/chatgpt.js/main/chatgpt.js to a subdirectory (`lib` in this example)
190
-
191
- 2. Add ES6 export statement to end of `lib/chatgpt.js`
192
- ```js
193
- ...
194
- export { chatgpt }
195
- ```
196
-
197
- 3. In project's (V3) `manifest.json`, add `lib/chatgpt.js` as a web accessible resource
198
- ```json
199
- "web_accessible_resources": [{
200
- "matches": ["<all_urls>"],
201
- "resources": ["lib/chatgpt.js"]
202
- }],
203
- ```
204
-
205
- 4. In scripts that need `chatgpt.js` (foreground/background alike), import it like so:
206
- ```js
207
- (async () => {
208
- const { chatgpt } = await import(chrome.runtime.getURL('lib/chatgpt.js'));
209
- // Your code here...
210
- })();
211
- ```
212
-
213
- # Library methods
214
-
215
- Unless noted otherwise, methods are **synchronous**: they wait for the operation to finish, instead of returning immediately. If you need to know the result of calling **asynchronous** methods, use the returned promise or pass a callback function into the method.
216
-
217
- ## General
218
-
219
- ### detectLanguage `async`
220
-
221
- Asks ChatGPT to detect the language of given text.
222
-
223
- **Parameters**:
224
-
225
- `text`: A string being the text to detect the language of.
226
-
227
- Example code:
228
-
229
- ```js
230
- (async () => {
231
- const language = await chatgpt.detectLanguage('我是一個大男孩');
232
- console.log(language);
233
- /* Logs:
234
- Chinese (Traditional) */
235
- })();
236
- ```
237
-
238
- ### executeCode `async`
239
-
240
- Asks ChatGPT to execute the given code.
241
-
242
- **Parameters**:
243
-
244
- `code`: A string being the code to execute.
245
-
246
- Example code:
247
-
248
- ```js
249
- (async () => {
250
- console.log(await chatgpt.executeCode('return 6 + 5')); // logs '11'
251
- })();
252
- ```
253
-
254
- ### generateRandomIP
255
-
256
- Returns a random IP address as a string.
257
-
258
- Example code:
259
-
260
- ```js
261
- const randomIP = chatgpt.generateRandomIP();
262
- console.log(randomIP); // Example output: '161.192.110.125'
263
- ```
264
-
265
- ### get
266
-
267
- Example code:
268
-
269
- ```js
270
- var response;
271
-
272
- response = chatgpt.get('reply', 'last');
273
- // Equivalent of
274
- response = chatgpt.getLastResponse();
275
- ```
276
-
277
- ### getUserLanguage
278
-
279
- Returns the user language as a string.
280
-
281
- Example code:
282
-
283
- ```js
284
- const userLanguage = chatgpt.getUserLanguage();
285
- console.log(userLanguage); // Example output: 'en-US'
286
- ```
287
-
288
- ### isChromium
289
-
290
- Returns a boolean value. `true` if the browser is Chromium and `false` otherwise.
291
-
292
- Example code:
293
-
294
- ```js
295
- if (chatgpt.isChromium()) {
296
- // Do something
297
- }
298
- ```
299
-
300
- ### isFirefox
301
-
302
- Returns a boolean value. `true` if the browser is Firefox and `false` otherwise.
303
-
304
- Example code:
305
-
306
- ```js
307
- if (chatgpt.isFirefox()) {
308
- // Do something
309
- }
310
- ```
311
-
312
- ### isFullScreen
313
-
314
- Returns a boolean value. `true` if the website is fullscreen and `false` otherwise.
315
-
316
- Example code:
317
-
318
- ```js
319
- if (chatgpt.isFullScreen()) {
320
- // Do something
321
- }
322
- ```
323
-
324
- ### isLoaded `async`
325
-
326
- Resolves a promise when ChatGPT has finished loading.
327
-
328
- Example code:
329
-
330
- ```js
331
- (async () => {
332
- await chatgpt.isLoaded();
333
- console.log('ChatGPT has finished loading.');
334
- })();
335
- ```
336
-
337
- ### isMobileDevice
338
-
339
- Returns a boolean value. `true` if the user device is mobile and `false` otherwise.
340
-
341
- Example code:
342
-
343
- ```js
344
- if (chatgpt.isMobileDevice()) {
345
- // Do something
346
- }
347
- ```
348
-
349
- ### printAllFunctions
350
-
351
- Prints all the library functions to the console.
352
-
353
- Example code:
354
-
355
- ```js
356
- chatgpt.printAllFunctions();
357
- ```
358
-
359
- ### randomFloat
360
-
361
- Returns a random, cryptographically secure float number between 0 (inclusive) and 1 (exclusive).
362
-
363
- Example code:
364
-
365
- ```js
366
- const randomNumber = chatgpt.randomFloat();
367
- console.log(randomNumber); // Example output: 0.9472113021060851
368
- ```
369
-
370
- ### renderHTML
371
-
372
- Cleans and renders given HTML code.
373
-
374
- **Parameters**:
375
-
376
- `node`: A string representing the HTML to be rendered.
377
-
378
- Example code:
379
-
380
- ```js
381
- document.body.append(
382
- chatgpt.renderHTML('<div>Hello World!</div>');
383
- );
384
- ```
385
-
386
- ### sentiment `async`
387
-
388
- Asks ChatGPT to analyze sentiment from a given text.
389
-
390
- **Parameters**:
391
-
392
- `text`: A string being the text to be analyzed.
393
-
394
- `entity` (optional): A string being the entity to analyze sentiment towards.
395
-
396
- Example code:
397
-
398
- ```js
399
- (async () => {
400
- const text = 'Are you an #OSS supporter? Do you love JavaScript? Then why not contribute to the future of #AI app development? https://chatgpt.js.org (a #100Builders project) is seeking collabs for exactly this! @withBackdrop';
401
- const sentiment = await chatgpt.sentiment(text, '100 Builders');
402
- console.log(sentiment);
403
-
404
- /* Example output:
405
- The sentiment of the text towards the entity "100 Builders" is strongly positive. The text encourages
406
- individuals who support open-source software (OSS) and have an affinity for JavaScript to get involved with
407
- the project. Phrases like "contribute to the future," "seeking collabs," and the inclusion of the hashtag
408
- #100Builders project indicate a positive and enthusiastic tone, promoting engagement and collaboration
409
- with the project. */
410
- })();
411
- ```
412
-
413
- ### suggest `async`
414
-
415
- Asks ChatGPT to suggest ideas.
416
-
417
- **Parameters**:
418
-
419
- `ideaType`: A string being the type of idea to suggest.
420
-
421
- `details` (optional): A string being details to fine-tune the suggestion.
422
-
423
- Example code:
424
-
425
- ```js
426
- (async () => {
427
- const suggestions = await chatgpt.suggest('names', 'baby boy');
428
- console.log(suggestions);
429
-
430
- /* Example output:
431
- 1. Liam
432
- 2. Noah
433
- 3. Ethan
434
- 4. Oliver
435
- 5. Jackson
436
- 6. Aiden
437
- 7. Lucas
438
- 8. Benjamin
439
- 9. Henry
440
- 10. Leo
441
- 11. Samuel
442
- 12. Caleb
443
- 13. Owen
444
- 14. Daniel
445
- 15. Elijah
446
- 16. Matthew
447
- 17. Alexander
448
- 18. James
449
- 19. Nathan
450
- 20. Gabriel */
451
- })();
452
- ```
453
-
454
- ### summarize `async`
455
-
456
- Asks ChatGPT to summarize given text.
457
-
458
- **Parameters**:
459
-
460
- `text`: A string being the text to be summarized.
461
-
462
- Example code:
463
-
464
- ```js
465
- (async () => {
466
- const summary = await chatgpt.summarize('A very long text...');
467
- console.log(summary); // Example output: 'A very short text...'
468
- })();
469
- ```
470
-
471
- ### translate `async`
472
-
473
- Asks ChatGPT to translate given text to a given language.
474
-
475
- **Parameters**:
476
-
477
- `text`: A string being the text to translate.
478
-
479
- `outputLang`: A string representing the output language of the translation.
480
-
481
- Example code:
482
-
483
- ```js
484
- (async () => {
485
- const translation = await chatgpt.translate('Hello, how are you?', 'spanish');
486
- console.log(translation); // Logs: 'Hola, ¿cómo estás?'
487
- })();
488
- ```
489
-
490
- ### uuidv4
491
-
492
- Example code:
493
-
494
- ```js
495
- const randomID = chatgpt.uuidv4();
496
- console.log(randomID); // Example output: '239067d1-bcb8-4fd7-91eb-9ab94619b7b3'
497
- ```
498
-
499
- ## Page theme
500
-
501
- ### activateDarkMode
502
-
503
- Changes the website theme to dark mode.
504
-
505
- Example code:
506
-
507
- ```js
508
- chatgpt.activateDarkMode();
509
- ```
510
-
511
- ### activateLightMode
512
-
513
- Changes the website theme to light mode.
514
-
515
- Example code:
516
-
517
- ```js
518
- chatgpt.activateLightMode();
519
- ```
520
-
521
- ### isDarkMode
522
-
523
- Returns a boolean value. `true` if the theme is dark mode, `false` otherwise.
524
-
525
- Example code:
526
-
527
- ```js
528
- console.log(chatgpt.settings.scheme.isDark()); // logs `true` or `false`
529
- ```
530
-
531
- ### isLightMode
532
-
533
- Returns a boolean value. `true` if the theme is light mode, `false` otherwise.
534
-
535
- Example code:
536
-
537
- ```js
538
- console.log(chatgpt.settings.scheme.isDark()); // logs `true` or `false`
539
- ```
540
-
541
- ### toggleScheme
542
-
543
- Toggles the theme between light and dark mode.
544
-
545
- Example code:
546
-
547
- ```js
548
- chatgpt.toggleScheme();
549
- ```
550
-
551
- ## In-site notifications
552
-
553
- ### alert
554
-
555
- Creates a static alert box which displays a message. Only a user interaction can close it. Returns the HTML `id` property of the alert box as a string.
556
-
557
- **Parameters**:
558
-
559
- `title` (optional): A string which is the title of the alert.
560
-
561
- `msg` (optional): A string which is the message to be displayed.
562
-
563
- `btns` (optional): An array of functions which will be rendered as clickable buttons.
564
-
565
- `checkbox` (optional): A function which will be rendered as a checkbox.
566
-
567
- `width` (optional): An integer representing the width of the alert box in `px`.
568
-
569
- Example code:
570
-
571
- ```js
572
- function doSomething() { /* Your code */ }
573
-
574
- function doSomethingElse() { /* Your code */ }
575
-
576
- function sayHello() { console.log('Hello!'); }
577
-
578
- const alertID = chatgpt.alert('Hello, world!', 'The sky is blue.', [doSomething, doSomethingElse], sayHello, 200);
579
- console.log(alertID); // Example output: '1693237957878'
580
- ```
581
-
582
- ### notify
583
-
584
- Displays a temporary notification at a specified position in the website.
585
-
586
- **Parameters**:
587
-
588
- `msg`: A string which is the message to be displayed.
589
-
590
- `position` (optional): A string specifying the position of the notification.
591
-
592
- `notifDuration` (optional): A float specifying the duration of the notification before it fades out.
593
-
594
- `shadow` (optional): A string specifying if the `box-shadow` CSS property should be used.
595
-
596
- Example code:
597
-
598
- ```js
599
- chatgpt.notify('Hello, world!', 'top left', 3, 'on');
600
- ```
601
-
602
- ## User session
603
-
604
- ### getAccessToken `async`
605
-
606
- Returns an account access token as a string.
607
-
608
- ```js
609
- (async () => {
610
- const token = await chatgpt.getAccessToken();
611
- console.log(token); // Example output: 'abcdef[...]'
612
- })();
613
- ```
614
-
615
- ### getAccountDetails `async`
616
-
617
- Returns a given account detail as a string.
618
-
619
- **Parameters**:
620
-
621
- `detail`: A string representing the account detail(s) that will be returned.
622
-
623
- Can be the following: `email`, `id`, `image`, `name`, `picture`. If a single detail is passed, it will be returned as a string, if multiple are passed instead, the function will return an object with the requested details. If no details are passed, the function will return an object with all the available details.
624
-
625
- ```js
626
- (async () => {
627
- const accountName = await chatgpt.getAccountDetails('name');
628
- console.log(accountName); // Example output: 'chatgpt.js'
629
-
630
- const accountData = await chatgpt.getAccountDetails('name', 'email');
631
- console.log(accountData);
632
- /* Example output:
633
- {
634
- name: 'chatgpt.js',
635
- email: 'showcase@chatgptjs.org'
636
- }
637
- */
638
- })();
639
- ```
640
-
641
- ### logout
642
-
643
- Logs out the user from the website.
644
-
645
- Example code:
646
-
647
- ```js
648
- chatgpt.logout();
649
- ```
650
-
651
- ## Chats
652
-
653
- ### askAndGetReply `async`
654
-
655
- Sends a given message to ChatGPT and returns the response as a string.
656
-
657
- Example code:
658
-
659
- ```js
660
- (async () => {
661
- const response = await chatgpt.askAndGetReply('Hello, ChatGPT');
662
- console.log(response); // Example output: 'Hello user, I'm ChatGPT!'
663
- })();
664
- ```
665
-
666
- ### clearChats `async`
667
-
668
- `method` (optional): The string `'api'` or `'dom'` representing the method to use.
669
-
670
- > **Note** _The API method does not update DOM chat list (until session refresh)_
671
-
672
- ### exportChat `async`
673
-
674
- Exports a given chat as a file.
675
-
676
- **Parameters**:
677
-
678
- `chatToGet` (optional): A string representing the chat to get the data from.
679
-
680
- Can be the following: `active`, the current chat, `latest`, the latest chat in the list, else the `index`, `title` or `id` of the chat to get. Default is `active` if in a chat, else `latest`.
681
-
682
- `format` (optional): A string representing the format of the export file.
683
-
684
- Can be the following: `html`, `md`, `pdf` or `text`. Defaults to `html`.
685
-
686
- Example code:
687
-
688
- ```js
689
- (async () => {
690
- await chatgpt.exportChat('latest', 'html'); // Downloads a '.html' file
691
- })();
692
- ```
693
-
694
- ### getChatData `async`
695
-
696
- Returns the requested chat data as a string (if single detail requested) or object of key-value pairs (if multiple details requested).
697
-
698
- **Parameters**:
699
-
700
- `chatToGet` (optional): A string representing the chat to get the data from.
701
-
702
- Can be the following: `active`, the current chat, `latest`, the latest chat in the list, else the `index`, `title` or `id` of the chat to get. Default is `active` if in a chat, else `latest`.
703
-
704
- `detailsToGet` (optional): A string or array of strings representing the chat data to retrieve.
705
-
706
- Can be the following: `all` to get all details, `id`, `title`, `create_time`, `update_time` or `msg`. To get a single detail, just use a string, to get multiple use an array of strings instead. Default is `all`.
707
-
708
- _**If `msg` is the requested detail, the following parameters can be used**_:
709
-
710
- `sender` (optional): A string representing the chat member to get the message(s) from.
711
-
712
- Can be the following: `user` to get the user message(s), `chatgpt` to get ChatGPT's response(s), `all`/`both` to get both of them. Default is `all`.
713
-
714
- `msgToGet` (optional): A string/number representing the chat message to retrieve.
715
-
716
- Can be the following: `all` to get all the messages in the chat, `latest` to get the latest message/response, or the `index` of the message. Default is `all`.
717
-
718
- > **Note** _If any **user** messages were edited, they are added to the index as newly sent messages_
719
-
720
- Example code **for all return types**:
721
-
722
- _**All details from specified chat**_
723
-
724
- ```js
725
- await chatgpt.getChatData();
726
- // or
727
- await chatgpt.getChatData('latest'); // can also be 'active', 'title of the chat' or 'id of the chat'
728
- // or
729
- await chatgpt.getChatData('latest', 'all');
730
- ```
731
-
732
- _Returns a JSON object_
733
-
734
- ```json
735
- {
736
- "create_time": "2023-07-19T13:24:05.618539+00:00",
737
- "id": "e193a219-2311-4232-95f5-8e3a0e466652",
738
- "title": "Lemons: Citrus Fruit Overview.",
739
- "update_time": "2023-07-19T13:24:18+00:00"
740
- }
741
- ```
742
-
743
- _**Specific detail(s) from specified chat**_
744
-
745
- ```js
746
- await chatgpt.getChatData('latest', ['id', 'title']);
747
- ```
748
-
749
- _Returns a JSON object_
750
-
751
- ```json
752
- {
753
- "id": "e193a219-2311-4232-95f5-8e3a0e466652",
754
- "title": "Lemons: Citrus Fruit Overview."
755
- }
756
- ```
757
-
758
- _**All messages from both participants in a specified chat**_
759
-
760
- ```js
761
- await chatgpt.getChatData('latest', 'msg');
762
- // or
763
- await chatgpt.getChatData('latest', 'msg', 'all'); // all/both
764
- // or
765
- await chatgpt.getChatData('latest', 'msg', 'all', 'all');
766
- ```
767
-
768
- _Returns an array of JSON objects_
769
-
770
- In case of a response being regenerated, the `chatgpt` object key will be converted to an array containing all the responses.
771
-
772
- ```json
773
- [
774
- {
775
- "user": "what are lemons",
776
- "chatgpt": "Lemons are a type of citrus fruit that belongs..."
777
- },
778
- {
779
- "user": "be more specific",
780
- "chatgpt": [
781
- "Certainly! Here are some more specific...",
782
- "Certainly! Here are some specific..." // regenerated responses!
783
- ]
784
- }
785
- ]
786
- ```
787
-
788
- _**All messages from a specific participant in a specified chat**_
789
-
790
- ```js
791
- await chatgpt.getChatData('latest', 'msg');
792
- // or
793
- await chatgpt.getChatData('latest', 'msg', 'chatgpt'); // user/chatgpt
794
- // or
795
- await chatgpt.getChatData('latest', 'msg', 'chatgpt', 'all');
796
- ```
797
-
798
- _Returns an array of strings/arrays_
799
-
800
- In case of a response being regenerated and the requested participant being `chatgpt`, it'll be converted to an array containing all the responses.
801
-
802
- ```json
803
- [
804
- "Lemons are a type of citrus fruit that belongs...",
805
- [
806
- "Certainly! Here are some more specific details...",
807
- "Certainly! Here are some specific..."
808
- ]
809
- ]
810
- ```
811
-
812
- _**One/latest message from both participants in a specified chat**_
813
-
814
- ```js
815
- await chatgpt.getChatData('latest', 'msg', 'all', 2); // can also be 'latest' message
816
- ```
817
-
818
- _Returns a JSON object_
819
-
820
- In case of a response being regenerated, the `chatgpt` object key will be converted to an array containing all the responses.
821
-
822
- ```json
823
- {
824
- "user": "be more specific",
825
- "chatgpt": [
826
- "Certainly! Here are some more specific...",
827
- "Certainly! Here are some specific..."
828
- ]
829
- }
830
- ```
831
-
832
- _**One/latest message from a specific participant in a specified chat**_
833
-
834
- ```js
835
- await chatgpt.getChatData('latest', 'msg', 'chatgpt', 2);
836
- ```
837
-
838
- _Returns a string or an array of strings_
839
-
840
- In case of a response being regenerated, the `chatgpt` object key will be converted to an array containing all the responses.
841
-
842
- ```json
843
- "Certainly! Here are some more specific..."
844
- // or
845
- [
846
- "Certainly! Here are some more specific...",
847
- "Certainly! Here are some specific..."
848
- ]
849
- ```
850
-
851
- ### getChatInput
852
-
853
- Returns the value of the chat input field as a string.
854
-
855
- Example code:
856
-
857
- ```js
858
- const chatInput = chatgpt.getChatInput();
859
- console.log(chatInput); // Example output: 'Hello from chatgpt.js!'
860
- ```
861
-
862
- ### getLastPrompt `async`
863
-
864
- Returns the last message sent by the user as a string.
865
-
866
- ```js
867
- (async () => {
868
- const message = await chatgpt.getLastPrompt();
869
- console.log(message); // Example output: 'Hello from chatgpt.js!'
870
- })();
871
- ```
872
-
873
- ### getLastResponse `async`
874
-
875
- Returns the last ChatGPT response as a string.
876
-
877
- ```js
878
- (async () => {
879
- const response = await chatgpt.getLastResponse();
880
- console.log(response); // Example output: 'I am ChatGPT!'
881
- })();
882
- ```
883
-
884
- ### getResponse
885
-
886
- If it's a previously created chat, read [chatgpt.getResponseFromDOM](#getresponsefromdom)
887
-
888
- If it's a new chat, read [chatgpt.getResponseFromAPI](#getresponsefromapi-async)
889
-
890
- ### getResponseFromAPI `async`
891
-
892
- Returns the Nth response ChatGPT has written in a Nth chat as a string.
893
-
894
- **Parameters**:
895
-
896
- `chatToGet` (optional): A number representing the index of the chat to get the response from. Defaults to `latest`.
897
-
898
- `responseToGet` (optional): A number representing the index of the response to get. Defaults to `latest`.
899
-
900
- Example code:
901
-
902
- ```js
903
- (async () => {
904
- const response = chatgpt.getResponseFromAPI();
905
- console.log(response); // Example output: 'Hello from ChatGPT!'
906
- })();
907
- ```
908
-
909
- ### getResponseFromDOM
910
-
911
- Returns the Nth response ChatGPT has written as a string.
912
-
913
- **Parameters**:
914
-
915
- `pos`: A string or integer representing the position of the wanted response.
916
-
917
- Example code:
918
-
919
- ```js
920
- var fifthResp;
921
-
922
- fifthResp = chatgpt.getResponseFromDOM(5); // Returns the 5th response
923
- fifthResp = chatgpt.getResponseFromDOM('fifth'); // Also returns the 5th response
924
- fifthResp = chatgpt.getResponseFromDOM('five'); // Returns the 5th response too
925
-
926
- console.log(fifthResp); // Example output: 'Hello from ChatGPT!'
927
- ```
928
-
929
- ### isIdle `async`
930
-
931
- Returns a boolean value. `true` if ChatGPT has finished generating a response, `false` otherwise.
932
-
933
- Example code:
934
-
935
- ```js
936
- (async () => {
937
- if (await chatgpt.isIdle()) {
938
- // Do something
939
- }
940
- })();
941
- ```
942
-
943
- ### regenerate
944
-
945
- Regenerates ChatGPT's response.
946
-
947
- Example code:
948
-
949
- ```js
950
- chatgpt.regenerate();
951
- ```
952
-
953
- ### resend `async`
954
-
955
- Re-sends the last user message.
956
-
957
- ```js
958
- (async () => {
959
- await chatgpt.resend();
960
- })();
961
- ```
962
-
963
- ### scrollToBottom
964
-
965
- Scrolls to the bottom of the chat.
966
-
967
- Example code:
968
-
969
- ```js
970
- chatgpt.scrollToBottom();
971
- ```
972
-
973
- ### send
974
-
975
- Sends a message into the chat.
976
-
977
- **Parameters**:
978
-
979
- `msg`: A string representing the message to send.
980
-
981
- `method` (optional): A string representing the method to send the message with, can only be `click`. Usually needed for mobile devices compatibility.
982
-
983
- Example code:
984
-
985
- ```js
986
- // Clicks the send button instead of triggering the 'Enter' key press.
987
- chatgpt.send('Hello, world!', 'click');
988
- ```
989
-
990
- ### sendInNewChat
991
-
992
- Creates a new chat and sends a message.
993
-
994
- **Parameters**:
995
-
996
- `msg`: A string representing the message to send.
997
-
998
- Example code:
999
-
1000
- ```js
1001
- chatgpt.sendInNewChat('Hello, world!');
1002
- ```
1003
-
1004
- ### shareChat `async`
1005
-
1006
- Makes the selected chat available to others. Returns the URL of the chat as a string.
1007
-
1008
- **Parameters**:
1009
-
1010
- `chatToGet` (optional): A number or string representing the `index`, `title` or `id` of the chat to share.
1011
-
1012
- `method` (optional): A string representing the method to share the chat with. Defaults to `clipboard`.
1013
-
1014
- Can be the following: `copy` or `clipboard` to copy the chat URL to clipboard, `alert`, `notify` or `notification` to create an [alert message](#alert) with the details about the shared chat in the website.
1015
-
1016
- ```js
1017
- (async () => {
1018
- await chatgpt.shareChat(1, 'copy'); // copy/clipboard
1019
- })();
1020
- ```
1021
-
1022
- ### speak
1023
-
1024
- Text To Speech (TTS) conversion of a given message.
1025
-
1026
- **Parameters**:
1027
-
1028
- `msg`: A string representing the message to TTS.
1029
-
1030
- `options` (optional): An object containing the options for the vocal synthesizer.
1031
-
1032
- Available options:
1033
-
1034
- - `voice`: A number representing the index of voices available on the user device.
1035
- - `pitch`: A float representing the pitch of the speech. From `0` to `2`.
1036
- - `speed`: A float representing the speed of the speech. From `0.1` to `10`.
1037
-
1038
- Example code:
1039
-
1040
- ```js
1041
- (async () => {
1042
- chatgpt.speak(await chatgpt.getLastResponse(), { voice: 1, pitch: 2, speed: 3 });
1043
- })();
1044
- ```
1045
-
1046
- ### startNewChat
1047
-
1048
- Creates a new chat.
1049
-
1050
- Example code:
1051
-
1052
- ```js
1053
- chatgpt.startNewChat();
1054
- ```
1055
-
1056
- ### stop
1057
-
1058
- Stops the generation of ChatGPT's response.
1059
-
1060
- Example code:
1061
-
1062
- ```js
1063
- chatgpt.stop();
1064
- ```
1065
-
1066
- ## DOM related
1067
-
1068
- ### getChatBox
1069
-
1070
- Returns the chat input as an HTML element.
1071
-
1072
- Example code:
1073
-
1074
- ```js
1075
- const chatbox = chatgpt.getChatBox();
1076
- console.log(chatbox.value); // Example output: 'Hello from chatgpt.js!'
1077
- ```
1078
-
1079
- ### getContinueGeneratingButton
1080
-
1081
- Returns the 'Continue generating' button as an HTML element.
1082
-
1083
- Example code:
1084
-
1085
- ```js
1086
- const continueButton = chatgpt.getContinueGeneratingButton();
1087
- continueButton.click();
1088
- ```
1089
-
1090
- ### getNewChatLink
1091
-
1092
- Returns the button which creates a new chat as an HTML element.
1093
-
1094
- Example code:
1095
-
1096
- ```js
1097
- const newChatLink = chatgpt.getNewChatLink();
1098
- newChatLink.click();
1099
- ```
1100
-
1101
- ### getRegenerateButton
1102
-
1103
- Returns the button which regenerates ChatGPT's response as an HTML element.
1104
-
1105
- Example code:
1106
-
1107
- ```js
1108
- const regenButton = chatgpt.getRegenerateButton();
1109
- regenButton.click();
1110
- ```
1111
-
1112
- ### getSendButton
1113
-
1114
- Returns the button which sends the message as an HTML element.
1115
-
1116
- Example code:
1117
-
1118
- ```js
1119
- const sendButton = chatgpt.getSendButton();
1120
- sendButton.click();
1121
- ```
1122
-
1123
- ### getStopGeneratingButton
1124
-
1125
- Returns the button which stops the generation of ChatGPT's response as an HTML element.
1126
-
1127
- Example code:
1128
-
1129
- ```js
1130
- const stopButton = chatgpt.getStopGeneratingButton();
1131
- stopButton.click();
1132
- ```
1133
-
1134
- # Library APIs
1135
-
1136
- ## autoRefresh `api`
1137
-
1138
- API related to keeping the user's session alive and fresh.
1139
-
1140
- #### activate
1141
-
1142
- Activates the auto-refresh functionality.
1143
-
1144
- **Parameters**:
1145
-
1146
- `interval` (optional): A number representing the interval in seconds between sessions refreshes. Defaults to `30`.
1147
-
1148
- Example code:
1149
-
1150
- ```js
1151
- chatgpt.autoRefresh.activate();
1152
- ```
1153
-
1154
- #### deactivate
1155
-
1156
- Deactivates the auto-refresh functionality.
1157
-
1158
- Example code:
1159
-
1160
- ```js
1161
- chatgpt.autoRefresh.deactivate();
1162
- ```
1163
-
1164
- #### nowTimeStamp
1165
-
1166
- Returns the current timestamp as a string (12-hour format).
1167
-
1168
- Example code:
1169
-
1170
- ```js
1171
- const timeStamp = chatgpt.autoRefresh.nowTimeStamp();
1172
- console.log(timeStamp); // Example output: '1:56:25 PM'
1173
- ```
1174
-
1175
- ## browser `api`
1176
-
1177
- ### isLightMode
1178
-
1179
- Returns a boolean value. `true` if system/browser scheme preference is set to light, `false` otherwise.
1180
-
1181
- Example code:
1182
-
1183
- ```js
1184
- console.log(chatgpt.browser.isLightMode()); // logs `true` or `false`
1185
- ```
1186
-
1187
- ### isDarkMode
1188
-
1189
- Returns a boolean value. `true` if system/browser scheme preference is set to dark, `false` otherwise.
1190
-
1191
- Example code:
1192
-
1193
- ```js
1194
- console.log(chatgpt.browser.isDarkMode()); // logs `true` or `false`
1195
- ```
1196
-
1197
- ### isChromium
1198
-
1199
- Returns a boolean value. `true` if the browser is Chromium and `false` otherwise.
1200
-
1201
- Example code:
1202
-
1203
- ```js
1204
- if (chatgpt.browser.isChromium()) {
1205
- // Do something
1206
- }
1207
- ```
1208
-
1209
- ### isFirefox
1210
-
1211
- Returns a boolean value. `true` if the browser is Firefox and `false` otherwise.
1212
-
1213
- Example code:
1214
-
1215
- ```js
1216
- if (chatgpt.browser.isFirefox()) {
1217
- // Do something
1218
- }
1219
- ```
1220
-
1221
- ### isFullScreen
1222
-
1223
- Returns a boolean value. `true` if the browser is fullscreen and `false` otherwise.
1224
-
1225
- Example code:
1226
-
1227
- ```js
1228
- if (chatgpt.browser.isFullScreen()) {
1229
- // Do something
1230
- }
1231
- ```
1232
-
1233
- ### isMobile
1234
-
1235
- Returns a boolean value. `true` if the browser is mobile and `false` otherwise.
1236
-
1237
- Example code:
1238
-
1239
- ```js
1240
- if (chatgpt.browser.isMobile()) {
1241
- // Do something
1242
- }
1243
- ```
1244
-
1245
- ## code `api`
1246
-
1247
- ### minify `async`
1248
-
1249
- Asks ChatGPT to minify the given code.
1250
-
1251
- **Parameters**:
1252
-
1253
- `code`: A string being the code to be minified.
1254
-
1255
- Example code:
1256
-
1257
- ```js
1258
- (async () => {
1259
- const minifiedCode = await chatgpt.code.minify(`
1260
- function autosizeBox() {
1261
- const newLength = replyBox.value.length
1262
- if (newLength < prevLength) { // if deleting txt
1263
- replyBox.style.height = 'auto' // ...auto-fit height
1264
- if (parseInt(getComputedStyle(replyBox).height) < 55) { // if down to one line
1265
- replyBox.style.height = '2.15rem' } // ...reset to original height
1266
- }
1267
- replyBox.style.height = replyBox.scrollHeight + 'px'
1268
- prevLength = newLength
1269
- }`);
1270
- console.log(minifiedCode);
1271
-
1272
- /* Logs:
1273
- 'function autosizeBox(){const n=replyBox.value.length;if(n<prevLength){replyBox.style.height='auto';if(parseInt(getComputedStyle(replyBox).height)<55){replyBox.style.height='2.15rem'}}replyBox.style.height=replyBox.scrollHeight+'px';prevLength=n}' */
1274
- })();
1275
- ```
1276
-
1277
- ### execute `async`
1278
-
1279
- Asks ChatGPT to execute the given code.
1280
-
1281
- **Parameters**:
1282
-
1283
- `code`: A string being the code to execute.
1284
-
1285
- Example code:
1286
-
1287
- ```js
1288
- (async () => {
1289
- console.log(await chatgpt.code.execute('return 6 + 5')); // logs '11'
1290
- })();
1291
- ```
1292
-
1293
- ### extract
1294
-
1295
- Extracts pure code from response.
1296
-
1297
- **Parameters**:
1298
-
1299
- `msg`: A string being the response to extract code from.
1300
-
1301
- Example code:
1302
-
1303
- ```js
1304
- (async () => {
1305
- chatgpt.send('What is a short script to delete files?');
1306
- await chatgpt.isIdle();
1307
- const response = await chatgpt.getChatData('active', 'msg', 'chatgpt', 'latest'),
1308
- scriptCode = chatgpt.code.extract(response);
1309
- console.log(scriptCode);
1310
-
1311
- /* Logs:
1312
- const fs = require('fs');
1313
-
1314
- // Specify the path of the file(s) you want to delete
1315
- const filePath = 'path/to/your/file.txt';
1316
-
1317
- // Delete the file
1318
- fs.unlink(filePath, (err) => {
1319
- if (err) {
1320
- console.error('Error deleting file:', err);
1321
- } else {
1322
- console.log('File deleted successfully');
1323
- }
1324
- }); */
1325
- })();
1326
- ```
1327
-
1328
- ### obfuscate `async`
1329
-
1330
- Asks ChatGPT to obfuscate the given code.
1331
-
1332
- **Parameters**:
1333
-
1334
- `code`: A string being the code to obfuscate.
1335
-
1336
- Example code:
1337
-
1338
- ```js
1339
- (async () => {
1340
- const code = `window[elem].addEventListener('mouseover', toggleTooltip)`
1341
- const obfuscatedCode = await chatgpt.code.obfuscate(code);
1342
- console.log(obfuscatedCode);
1343
-
1344
- /* Logs:
1345
- '(window[elem])[btoa('YWxlcnRWaWV3')](btoa('bW91c2VyYm94ZXJOYW1l'), btoa('dG9nZ2VkT3V0d2FsbA==')); */
1346
- })();
1347
- ```
1348
-
1349
- ### refactor `async`
1350
-
1351
- Asks ChatGPT to refactor the given code.
1352
-
1353
- **Parameters**:
1354
-
1355
- `code`: A string being the code to refactor.
1356
-
1357
- `objective` (optional): A string reprenting the objective of the refactoring. Defaults to `brevity`.
1358
-
1359
- Example code:
1360
-
1361
- ```js
1362
- (async () => {
1363
- const code = `
1364
- if (6 > 5) {
1365
- return true;
1366
- } else {
1367
- return false;
1368
- }`;
1369
- const refactoredCode = await chatgpt.code.refactor(code, 'brevity');
1370
- console.log(refactoredCode);
1371
-
1372
- /* Logs:
1373
- return 6 > 5; */
1374
- })();
1375
- ```
1376
-
1377
- ### review `async`
1378
-
1379
- Asks ChatGPT to review given code.
1380
-
1381
- **Parameters**:
1382
-
1383
- `code`: A string being the code to review.
1384
-
1385
- Example code:
1386
-
1387
- ```js
1388
- (async () => {
1389
- console.log(await chatgpt.code.review('btoa("Hello World")'));
1390
-
1391
- /* Example output:
1392
- The code appears to be correct. It uses the `btoa` function to encode the string "Hello World" in base64. */
1393
- })();
1394
- ```
1395
-
1396
- ### unminify `async`
1397
-
1398
- Asks ChatGPT to unminify the given code.
1399
-
1400
- **Parameters**:
1401
-
1402
- `code`: A string being the code to unminify.
1403
-
1404
- Example code:
1405
-
1406
- ```js
1407
- (async () => {
1408
- const code = `function autosizeBox(){const n=replyBox.value.length;if(n<prevLength){replyBox.style.height='auto';if(parseInt(getComputedStyle(replyBox).height)<55){replyBox.style.height='2.15rem'}}replyBox.style.height=replyBox.scrollHeight+'px';prevLength=n}`;
1409
-
1410
- const minifiedCode = await chatgpt.code.unminify(code);
1411
- console.log(minifiedCode);
1412
-
1413
- /* Logs:
1414
- function autosizeBox() {
1415
- const newLength = replyBox.value.length
1416
- if (newLength < prevLength) { // if deleting txt
1417
- replyBox.style.height = 'auto' // ...auto-fit height
1418
- if (parseInt(getComputedStyle(replyBox).height) < 55) { // if down to one line
1419
- replyBox.style.height = '2.15rem' } // ...reset to original height
1420
- }
1421
- replyBox.style.height = replyBox.scrollHeight + 'px'
1422
- prevLength = newLength
1423
- }` */
1424
- })();
1425
- ```
1426
-
1427
- ### write `async`
1428
-
1429
- Asks ChatGPT to write code given a prompt.
1430
-
1431
- **Parameters**:
1432
-
1433
- `prompt`: A string describing the code to generate.
1434
-
1435
- `outputLang`: A string representing the code language to generate the prompt with.
1436
-
1437
- Example code:
1438
-
1439
- ```js
1440
- (async () => {
1441
- const code = await chatgpt.code.write('Repeat a task every 10 seconds', 'javascript');
1442
- console.log(code);
1443
-
1444
- /* Logs:
1445
- setInterval(function() {
1446
- // Your task code here
1447
- }, 10000); */
1448
- })();
1449
- ```
1450
-
1451
- ## history `api`
1452
-
1453
- API related to the chat history.
1454
-
1455
- ### isOn
1456
-
1457
- Returns a boolean value. `true` if the chat history is enabled, `false` otherwise.
1458
-
1459
- Example code:
1460
-
1461
- ```js
1462
- if (chatgpt.history.isOn()) {
1463
- // Do something
1464
- }
1465
- ```
1466
-
1467
- ### isOff
1468
-
1469
- Returns a boolean value. `true` if the chat history is disabled, `false` otherwise.
1470
-
1471
- Example code:
1472
-
1473
- ```js
1474
- if (chatgpt.history.isOff()) {
1475
- // Do something
1476
- }
1477
- ```
1478
-
1479
- ### activate
1480
-
1481
- Activates the chat history.
1482
-
1483
- Example code:
1484
-
1485
- ```js
1486
- chatgpt.history.activate();
1487
- ```
1488
-
1489
- ### deactivate
1490
-
1491
- Deactivates the chat history.
1492
-
1493
- Example code:
1494
-
1495
- ```js
1496
- chatgpt.history.deactivate();
1497
- ```
1498
-
1499
- ### isLoaded `async`
1500
-
1501
- Resolves a promise when chat history has finished loading.
1502
-
1503
- Example code:
1504
-
1505
- ```js
1506
- (async () => {
1507
- await chatgpt.history.isLoaded();
1508
- console.log('ChatGPT history has finished loading.');
1509
- })();
1510
- ```
1511
-
1512
- ### toggle
1513
-
1514
- Toggles the chat history.
1515
-
1516
- Example code:
1517
-
1518
- ```js
1519
- chatgpt.history.toggle();
1520
- ```
1521
-
1522
- ## instructions `api`
1523
-
1524
- ### add `async`
1525
-
1526
- Adds a custom instruction for either the user or ChatGPT.
1527
-
1528
- **Parameters**:
1529
-
1530
- `instruction`: A string being the instruction to be added.
1531
-
1532
- `target`: A string representing the target of the instruction. Can be either `user` or `chatgpt`.
1533
-
1534
- Example code:
1535
-
1536
- ```js
1537
- (async () => {
1538
- await chatgpt.instructions.add('Detailed and well-explained answers', 'chatgpt');
1539
- })();
1540
- ```
1541
-
1542
- ### clear `async`
1543
-
1544
- Clears the custom instructions of either the user or ChatGPT.
1545
-
1546
- **Parameters**:
1547
-
1548
- `target`: A string representing the target of the instruction. Can be either `user` or `chatgpt`.
1549
-
1550
- Example code:
1551
-
1552
- ```js
1553
- (async () => {
1554
- await chatgpt.instructions.clear('user');
1555
- })();
1556
- ```
1557
-
1558
- ### turnOff `async`
1559
-
1560
- Turns off custom instructions.
1561
-
1562
- Example code:
1563
-
1564
- ```js
1565
- (async () => {
1566
- await chatgpt.instructions.turnOff();
1567
- })();
1568
- ```
1569
-
1570
- ### turnOn `async`
1571
-
1572
- Turns on custom instructions.
1573
-
1574
- Example code:
1575
-
1576
- ```js
1577
- (async () => {
1578
- await chatgpt.instructions.turnOn();
1579
- })();
1580
- ```
1581
-
1582
- ### toggle `async`
1583
-
1584
- Toggles on/off custom instructions.
1585
-
1586
- Example code:
1587
-
1588
- ```js
1589
- (async () => {
1590
- await chatgpt.instructions.toggle();
1591
- })();
1592
- ```
1593
-
1594
- ## menu `api`
1595
-
1596
- The small menu that shows up when clicking on the account button.
1597
-
1598
- ### open
1599
-
1600
- Opens the menu.
1601
-
1602
- Example code:
1603
-
1604
- ```js
1605
- chatgpt.menu.open();
1606
- ```
1607
-
1608
- ### close
1609
-
1610
- Closes the menu.
1611
-
1612
- Example code:
1613
-
1614
- ```js
1615
- chatgpt.menu.close();
1616
- ```
1617
-
1618
- ## response `api`
1619
-
1620
- API related to ChatGPT's responses.
1621
-
1622
- ### get
1623
-
1624
- If it's a previously created chat, read [chatgpt.getResponseFromDOM](#getresponsefromdom)
1625
-
1626
- If it's a new chat, read [chatgpt.getResponseFromAPI](#getresponsefromapi-async)
1627
-
1628
- ### getFromAPI `async`
1629
-
1630
- Read [chatgpt.getResponseFromAPI](#getresponsefromapi-async)
1631
-
1632
- ### getFromDOM
1633
-
1634
- Read [chatgpt.getResponseFromDOM](#getresponsefromdom)
1635
-
1636
- ### getLast `async`
1637
-
1638
- Read [chatgpt.getLastResponse](#getlastresponse-async)
1639
-
1640
- ### regenerate
1641
-
1642
- Read [chatgpt.regenerate](#regenerate)
1643
-
1644
- ### stopGenerating
1645
-
1646
- Read [chatgpt.stop](#stop)
1647
-
1648
- ## settings `api`
1649
-
1650
- API for interfacing with ChatGPT user settings.
1651
-
1652
- ### scheme `api subset`
1653
-
1654
- #### isDark
1655
-
1656
- Returns a boolean value. `true` if the theme is dark mode, `false` otherwise.
1657
-
1658
- Example code:
1659
-
1660
- ```js
1661
- console.log(chatgpt.settings.scheme.isDark()); // logs `true` or `false`
1662
- ````
1663
-
1664
- #### isLight
1665
-
1666
- Returns a boolean value. `true` if the theme is light mode, `false` otherwise.
1667
-
1668
- Example code:
1669
-
1670
- ```js
1671
- console.log(chatgpt.settings.scheme.isLight()); // logs `true` or `false`
1672
- ````
1673
-
1674
- #### set
1675
-
1676
- Sets the theme to `light`, `dark` or `system`.
1677
-
1678
- **Paremeters**:
1679
-
1680
- `value`: A string being the value to set the theme to.
1681
-
1682
- Example code:
1683
-
1684
- ```js
1685
- chatgpt.settings.scheme.set('dark');
1686
- ```
1687
-
1688
- #### toggle
1689
-
1690
- Toggles the theme between light and dark mode.
1691
-
1692
- Example code:
1693
-
1694
- ```js
1695
- chatgpt.settings.scheme.toggle();
1696
- ```
1697
-
1698
- ## sidebar `api`
1699
-
1700
- API related to the sidebar's behavior.
1701
-
1702
- ### append
1703
-
1704
- Appends a new element to the sidebar. Returns the `id` property of the element.
1705
-
1706
- **Parameters**:
1707
-
1708
- `element`: A string being the name of the element to append.
1709
-
1710
- Currently supported elements are [`button`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button) and [`dropdown`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/select).
1711
-
1712
- `attrs`: An object which contains the attributes of the element to append.
1713
-
1714
- _**Attributes for `button`**_
1715
-
1716
- `label`: A string being the label (displayed text) of the button. Defaults to `chatgpt.js button`.
1717
-
1718
- `icon`: A string being either a url to an image or a base64 encoded string of the image data. Defaults to [this icon](https://raw.githubusercontent.com/KudoAI/chatgpt.js/main/starters/chrome/extension/icons/icon128.png).
1719
-
1720
- `onclick`: A function which is called when the button is clicked. Defaults to `function() {}`.
1721
-
1722
- _**Attributes for `dropdown`**_
1723
-
1724
- `items`: An array of objects where the `text` key is the displayed text of the option, and the `value` key is the value of the option.
1725
-
1726
- Example item object:
1727
-
1728
- ```js
1729
- {
1730
- text: 'The text to display in the option',
1731
- value: 'The value of the option'
1732
- }
1733
- ```
1734
-
1735
- Example code:
1736
-
1737
- ```js
1738
- const buttonId = chatgpt.sidebar.append('button', {
1739
- label: 'I am a button!',
1740
- icon: 'https://chat.openai.com/favicon-32x32.png',
1741
- onclick: function() {
1742
- console.log('Clicked!');
1743
- }
1744
- });
1745
- console.log(buttonId); // Example output: 1693295258727
1746
-
1747
- const dropdownId = chatgpt.sidebar.append('dropdown', {
1748
- items: [
1749
- { text: 'Hello world', value: 'helloworld' },
1750
- { text: 'Hello there', value: 'hellothere' }
1751
- ]
1752
- });
1753
- console.log(dropdownId); // Example output: 1693294795240
1754
- ```
1755
-
1756
- ### isOn
1757
-
1758
- Returns a boolean value. `true` if the sidebar is open, `false` otherwise.
1759
-
1760
- Example code:
1761
-
1762
- ```js
1763
- if (chatgpt.sidebar.isOn()) {
1764
- // Do something
1765
- }
1766
- ```
1767
-
1768
- ### isOff
1769
-
1770
- Returns a boolean value. `true` if the sidebar is closed, `false` otherwise.
1771
-
1772
- Example code:
1773
-
1774
- ```js
1775
- if (chatgpt.sidebar.isOff()) {
1776
- // Do something
1777
- }
1778
- ```
1779
-
1780
- ### hide
1781
-
1782
- Hides the sidebar.
1783
-
1784
- Example code:
1785
-
1786
- ```js
1787
- chatgpt.sidebar.hide();
1788
- ```
1789
-
1790
- ### show
1791
-
1792
- Shows the sidebar.
1793
-
1794
- Example code:
1795
-
1796
- ```js
1797
- chatgpt.sidebar.show();
1798
- ```
1799
-
1800
- ### toggle
1801
-
1802
- Toggles the visibility of the sidebar.
1803
-
1804
- Example code:
1805
-
1806
- ```js
1807
- chatgpt.sidebar.toggle();
1808
- ```
1809
-
1810
- <br>
1811
- <br>
1812
-
1813
- [Discuss](https://github.com/kudoai/chatgpt.js/discussions) /
1814
- <a href="#">Back to top ↑</a>
1
+ <div align="center">
2
+
3
+ <picture>
4
+ <source type="image/png" media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/kudoai/chatgpt.js/main/media/images/logos/chatgpt.js/with-reflection/darkmode.png">
5
+ <img width=700 src="https://raw.githubusercontent.com/kudoai/chatgpt.js/main/media/images/logos/chatgpt.js/with-reflection/lightmode.png">
6
+ </picture>
7
+
8
+ **chatgpt.js** is a powerful JavaScript library that allows for super easy interaction w/ the ChatGPT DOM.
9
+
10
+ </div>
11
+
12
+ ## Table of contents
13
+
14
+ - [Importing the library](#importing-the-library)
15
+ - [ES6](#es6)
16
+ - [ES5](#es5)
17
+ - [Greasemonkey](#greasemonkey)
18
+ - [Chrome](#chrome)
19
+ - [Library methods](#library-methods)
20
+ - [General](#general)
21
+ - [detectLanguage `async`](#detectlanguage-async)
22
+ - [executeCode `async`](#executecode-async)
23
+ - [generateRandomIP](#generaterandomip)
24
+ - [get](#get)
25
+ - [getUserLanguage](#getuserlanguage)
26
+ - [isChromium](#ischromium)
27
+ - [isFirefox](#isfirefox)
28
+ - [isFullScreen](#isfullscreen)
29
+ - [isLoaded `async`](#isloaded-async)
30
+ - [isMobileDevice](#ismobiledevice)
31
+ - [printAllFunctions](#printallfunctions)
32
+ - [randomFloat](#randomfloat)
33
+ - [renderHTML](#renderhtml)
34
+ - [sentiment `async`](#sentiment-async)
35
+ - [suggest `async`](#suggest-async)
36
+ - [summarize `async`](#summarize-async)
37
+ - [translate `async`](#translate-async)
38
+ - [uuidv4](#uuidv4)
39
+ - [Page theme](#page-theme)
40
+ - [activateDarkMode](#activatedarkmode)
41
+ - [activateLightMode](#activatelightmode)
42
+ - [isDarkMode](#isdarkmode)
43
+ - [isLightMode](#islightmode)
44
+ - [toggleScheme](#togglescheme)
45
+ - [In-site notifications](#in-site-notifications)
46
+ - [alert](#alert)
47
+ - [notify](#notify)
48
+ - [User session](#user-session)
49
+ - [getAccessToken `async`](#getaccesstoken-async)
50
+ - [getAccountDetails `async`](#getaccountdetails-async)
51
+ - [logout](#logout)
52
+ - [Chats](#chats)
53
+ - [askAndGetReply `async`](#askandgetreply-async)
54
+ - [clearChats `async`](#clearchats-async)
55
+ - [exportChat `async`](#exportchat-async)
56
+ - [getChatData `async`](#getchatdata-async)
57
+ - [getChatInput](#getchatinput)
58
+ - [getLastPrompt `async`](#getlastprompt-async)
59
+ - [getLastResponse `async`](#getlastresponse-async)
60
+ - [getResponse](#getresponse)
61
+ - [getResponseFromAPI `async`](#getresponsefromapi-async)
62
+ - [getResponseFromDOM](#getresponsefromdom)
63
+ - [isIdle `async`](#isidle-async)
64
+ - [regenerate](#regenerate)
65
+ - [resend `async`](#resend-async)
66
+ - [scrollToBottom](#scrolltobottom)
67
+ - [send](#send)
68
+ - [sendInNewChat](#sendinnewchat)
69
+ - [shareChat `async`](#sharechat-async)
70
+ - [speak](#speak)
71
+ - [startNewChat](#startnewchat)
72
+ - [stop](#stop)
73
+ - [DOM related](#dom-related)
74
+ - [getChatBox](#getchatbox)
75
+ - [getContinueGeneratingButton](#getcontinuegeneratingbutton)
76
+ - [getNewChatLink](#getnewchatlink)
77
+ - [getRegenerateButton](#getregeneratebutton)
78
+ - [getSendButton](#getsendbutton)
79
+ - [getStopGeneratingButton](#getstopgeneratingbutton)
80
+ - [Library APIs](#library-apis)
81
+ - [autoRefresh `api`](#autorefresh-api)
82
+ - [activate](#activate)
83
+ - [deactivate](#deactivate)
84
+ - [nowTimeStamp](#nowtimestamp)
85
+ - [browser `api`](#browser-api)
86
+ - [isLightMode](#islightmode-1)
87
+ - [isDarkMode](#isdarkmode-1)
88
+ - [isChromium](#ischromium-1)
89
+ - [isFirefox](#isfirefox-1)
90
+ - [isFullScreen](#isfullscreen-1)
91
+ - [isMobile](#ismobile)
92
+ - [code `api`](#code-api)
93
+ - [minify `async`](#minify-async)
94
+ - [execute `async`](#execute-async)
95
+ - [extract](#extract)
96
+ - [obfuscate `async`](#obfuscate-async)
97
+ - [refactor `async`](#refactor-async)
98
+ - [review `async`](#review-async)
99
+ - [unminify `async`](#unminify-async)
100
+ - [write `async`](#write-async)
101
+ - [history `api`](#history-api)
102
+ - [isOn](#ison)
103
+ - [isOff](#isoff)
104
+ - [activate](#activate-1)
105
+ - [deactivate](#deactivate-1)
106
+ - [isLoaded](#isloaded-async-1)
107
+ - [toggle](#toggle)
108
+ - [instructions `api`](#instructions-api)
109
+ - [add `async`](#add-async)
110
+ - [clear `async`](#clear-async)
111
+ - [turnOff `async`](#turnoff-async)
112
+ - [turnOn `async`](#turnon-async)
113
+ - [toggle `async`](#toggle-async)
114
+ - [menu `api`](#menu-api)
115
+ - [open](#open)
116
+ - [close](#close)
117
+ - [response `api`](#response-api)
118
+ - [get](#get-1)
119
+ - [getFromAPI `async`](#getfromapi-async)
120
+ - [getFromDOM](#getfromdom)
121
+ - [getLast `async`](#getlast-async)
122
+ - [regenerate](#regenerate-1)
123
+ - [stopGenerating](#stopgenerating)
124
+ - [settings `api`](#settings-api)
125
+ - [scheme `api subset`](#scheme-api-subset)
126
+ - [isDark](#isdark)
127
+ - [isLight](#islight)
128
+ - [set](#set)
129
+ - [toggle](#toggle-1)
130
+ - [sidebar `api`](#sidebar-api)
131
+ - [append](#append)
132
+ - [isOn](#ison-1)
133
+ - [isOff](#isoff-1)
134
+ - [hide](#hide)
135
+ - [show](#show)
136
+ - [toggle](#toggle-2)
137
+
138
+ # Importing the library
139
+
140
+ > **Note** _To always import the latest version (NOT recommended in production!) replace the versioned jsDelivr URL with: `https://cdn.jsdelivr.net/npm/@kudoai/chatgpt.js/chatgpt.min.js`_
141
+
142
+ ## ES6
143
+
144
+ ```js
145
+ (async () => {
146
+ await import('https://cdn.jsdelivr.net/npm/@kudoai/chatgpt.js@2.6.5/dist/chatgpt.min.js');
147
+ // Your code here...
148
+ })();
149
+ ```
150
+
151
+ ## ES5
152
+
153
+ ```js
154
+ var xhr = new XMLHttpRequest();
155
+ xhr.open('GET', 'https://cdn.jsdelivr.net/npm/@kudoai/chatgpt.js@2.6.5/dist/chatgpt.min.js');
156
+ xhr.onload = function () {
157
+ if (xhr.status === 200) {
158
+ var chatgptJS = document.createElement('script');
159
+ chatgptJS.textContent = xhr.responseText;
160
+ document.head.append(chatgptJS);
161
+ yourCode(); // runs your code
162
+ }
163
+ };
164
+ xhr.send();
165
+
166
+ function yourCode() {
167
+ // Your code here...
168
+ }
169
+ ```
170
+
171
+ ## Greasemonkey
172
+
173
+ > **Note** _To use a starter template: [kudoai/chatgpt.js-greasemonkey-starter](https://github.com/kudoai/chatgpt.js-greasemonkey-starter)_
174
+
175
+ ```js
176
+ ...
177
+ // @require https://cdn.jsdelivr.net/npm/@kudoai/chatgpt.js@2.6.5/dist/chatgpt.min.js
178
+ // ==/UserScript==
179
+
180
+ // Your code here...
181
+ ```
182
+
183
+ ## Chrome
184
+
185
+ > **Note** _To use a starter template: [kudoai/chatgpt.js-chrome-starter](https://github.com/kudoai/chatgpt.js-chrome-starter)_
186
+
187
+ 1. Save https://raw.githubusercontent.com/kudoai/chatgpt.js/main/chatgpt.js to a subdirectory (`lib` in this example)
188
+
189
+ 2. Add ES6 export statement to end of `lib/chatgpt.js`
190
+ ```js
191
+ ...
192
+ export { chatgpt }
193
+ ```
194
+
195
+ 3. In project's (V3) `manifest.json`, add `lib/chatgpt.js` as a web accessible resource
196
+ ```json
197
+ "web_accessible_resources": [{
198
+ "matches": ["<all_urls>"],
199
+ "resources": ["lib/chatgpt.js"]
200
+ }],
201
+ ```
202
+
203
+ 4. In scripts that need `chatgpt.js` (foreground/background alike), import it like so:
204
+ ```js
205
+ (async () => {
206
+ const { chatgpt } = await import(chrome.runtime.getURL('lib/chatgpt.js'));
207
+ // Your code here...
208
+ })();
209
+ ```
210
+
211
+ # Library methods
212
+
213
+ Unless noted otherwise, methods are **synchronous**: they wait for the operation to finish, instead of returning immediately. If you need to know the result of calling **asynchronous** methods, use the returned promise or pass a callback function into the method.
214
+
215
+ ## General
216
+
217
+ ### detectLanguage `async`
218
+
219
+ Asks ChatGPT to detect the language of given text.
220
+
221
+ **Parameters**:
222
+
223
+ `text`: A string being the text to detect the language of.
224
+
225
+ Example code:
226
+
227
+ ```js
228
+ (async () => {
229
+ const language = await chatgpt.detectLanguage('我是一個大男孩');
230
+ console.log(language);
231
+ /* Logs:
232
+ Chinese (Traditional) */
233
+ })();
234
+ ```
235
+
236
+ ### executeCode `async`
237
+
238
+ Asks ChatGPT to execute the given code.
239
+
240
+ **Parameters**:
241
+
242
+ `code`: A string being the code to execute.
243
+
244
+ Example code:
245
+
246
+ ```js
247
+ (async () => {
248
+ console.log(await chatgpt.executeCode('return 6 + 5')); // logs '11'
249
+ })();
250
+ ```
251
+
252
+ ### generateRandomIP
253
+
254
+ Returns a random IP address as a string.
255
+
256
+ Example code:
257
+
258
+ ```js
259
+ const randomIP = chatgpt.generateRandomIP();
260
+ console.log(randomIP); // Example output: '161.192.110.125'
261
+ ```
262
+
263
+ ### get
264
+
265
+ Example code:
266
+
267
+ ```js
268
+ var response;
269
+
270
+ response = chatgpt.get('reply', 'last');
271
+ // Equivalent of
272
+ response = chatgpt.getLastResponse();
273
+ ```
274
+
275
+ ### getUserLanguage
276
+
277
+ Returns the user language as a string.
278
+
279
+ Example code:
280
+
281
+ ```js
282
+ const userLanguage = chatgpt.getUserLanguage();
283
+ console.log(userLanguage); // Example output: 'en-US'
284
+ ```
285
+
286
+ ### isChromium
287
+
288
+ Returns a boolean value. `true` if the browser is Chromium and `false` otherwise.
289
+
290
+ Example code:
291
+
292
+ ```js
293
+ if (chatgpt.isChromium()) {
294
+ // Do something
295
+ }
296
+ ```
297
+
298
+ ### isFirefox
299
+
300
+ Returns a boolean value. `true` if the browser is Firefox and `false` otherwise.
301
+
302
+ Example code:
303
+
304
+ ```js
305
+ if (chatgpt.isFirefox()) {
306
+ // Do something
307
+ }
308
+ ```
309
+
310
+ ### isFullScreen
311
+
312
+ Returns a boolean value. `true` if the website is fullscreen and `false` otherwise.
313
+
314
+ Example code:
315
+
316
+ ```js
317
+ if (chatgpt.isFullScreen()) {
318
+ // Do something
319
+ }
320
+ ```
321
+
322
+ ### isLoaded `async`
323
+
324
+ Resolves a promise when ChatGPT has finished loading.
325
+
326
+ Example code:
327
+
328
+ ```js
329
+ (async () => {
330
+ await chatgpt.isLoaded();
331
+ console.log('ChatGPT has finished loading.');
332
+ })();
333
+ ```
334
+
335
+ ### isMobileDevice
336
+
337
+ Returns a boolean value. `true` if the user device is mobile and `false` otherwise.
338
+
339
+ Example code:
340
+
341
+ ```js
342
+ if (chatgpt.isMobileDevice()) {
343
+ // Do something
344
+ }
345
+ ```
346
+
347
+ ### printAllFunctions
348
+
349
+ Prints all the library functions to the console.
350
+
351
+ Example code:
352
+
353
+ ```js
354
+ chatgpt.printAllFunctions();
355
+ ```
356
+
357
+ ### randomFloat
358
+
359
+ Returns a random, cryptographically secure float number between 0 (inclusive) and 1 (exclusive).
360
+
361
+ Example code:
362
+
363
+ ```js
364
+ const randomNumber = chatgpt.randomFloat();
365
+ console.log(randomNumber); // Example output: 0.9472113021060851
366
+ ```
367
+
368
+ ### renderHTML
369
+
370
+ Cleans and renders given HTML code.
371
+
372
+ **Parameters**:
373
+
374
+ `node`: A string representing the HTML to be rendered.
375
+
376
+ Example code:
377
+
378
+ ```js
379
+ document.body.append(
380
+ chatgpt.renderHTML('<div>Hello World!</div>');
381
+ );
382
+ ```
383
+
384
+ ### sentiment `async`
385
+
386
+ Asks ChatGPT to analyze sentiment from a given text.
387
+
388
+ **Parameters**:
389
+
390
+ `text`: A string being the text to be analyzed.
391
+
392
+ `entity` (optional): A string being the entity to analyze sentiment towards.
393
+
394
+ Example code:
395
+
396
+ ```js
397
+ (async () => {
398
+ const text = 'Are you an #OSS supporter? Do you love JavaScript? Then why not contribute to the future of #AI app development? https://chatgpt.js.org (a #100Builders project) is seeking collabs for exactly this! @withBackdrop';
399
+ const sentiment = await chatgpt.sentiment(text, '100 Builders');
400
+ console.log(sentiment);
401
+
402
+ /* Example output:
403
+ The sentiment of the text towards the entity "100 Builders" is strongly positive. The text encourages
404
+ individuals who support open-source software (OSS) and have an affinity for JavaScript to get involved with
405
+ the project. Phrases like "contribute to the future," "seeking collabs," and the inclusion of the hashtag
406
+ #100Builders project indicate a positive and enthusiastic tone, promoting engagement and collaboration
407
+ with the project. */
408
+ })();
409
+ ```
410
+
411
+ ### suggest `async`
412
+
413
+ Asks ChatGPT to suggest ideas.
414
+
415
+ **Parameters**:
416
+
417
+ `ideaType`: A string being the type of idea to suggest.
418
+
419
+ `details` (optional): A string being details to fine-tune the suggestion.
420
+
421
+ Example code:
422
+
423
+ ```js
424
+ (async () => {
425
+ const suggestions = await chatgpt.suggest('names', 'baby boy');
426
+ console.log(suggestions);
427
+
428
+ /* Example output:
429
+ 1. Liam
430
+ 2. Noah
431
+ 3. Ethan
432
+ 4. Oliver
433
+ 5. Jackson
434
+ 6. Aiden
435
+ 7. Lucas
436
+ 8. Benjamin
437
+ 9. Henry
438
+ 10. Leo
439
+ 11. Samuel
440
+ 12. Caleb
441
+ 13. Owen
442
+ 14. Daniel
443
+ 15. Elijah
444
+ 16. Matthew
445
+ 17. Alexander
446
+ 18. James
447
+ 19. Nathan
448
+ 20. Gabriel */
449
+ })();
450
+ ```
451
+
452
+ ### summarize `async`
453
+
454
+ Asks ChatGPT to summarize given text.
455
+
456
+ **Parameters**:
457
+
458
+ `text`: A string being the text to be summarized.
459
+
460
+ Example code:
461
+
462
+ ```js
463
+ (async () => {
464
+ const summary = await chatgpt.summarize('A very long text...');
465
+ console.log(summary); // Example output: 'A very short text...'
466
+ })();
467
+ ```
468
+
469
+ ### translate `async`
470
+
471
+ Asks ChatGPT to translate given text to a given language.
472
+
473
+ **Parameters**:
474
+
475
+ `text`: A string being the text to translate.
476
+
477
+ `outputLang`: A string representing the output language of the translation.
478
+
479
+ Example code:
480
+
481
+ ```js
482
+ (async () => {
483
+ const translation = await chatgpt.translate('Hello, how are you?', 'spanish');
484
+ console.log(translation); // Logs: 'Hola, ¿cómo estás?'
485
+ })();
486
+ ```
487
+
488
+ ### uuidv4
489
+
490
+ Example code:
491
+
492
+ ```js
493
+ const randomID = chatgpt.uuidv4();
494
+ console.log(randomID); // Example output: '239067d1-bcb8-4fd7-91eb-9ab94619b7b3'
495
+ ```
496
+
497
+ ## Page theme
498
+
499
+ ### activateDarkMode
500
+
501
+ Changes the website theme to dark mode.
502
+
503
+ Example code:
504
+
505
+ ```js
506
+ chatgpt.activateDarkMode();
507
+ ```
508
+
509
+ ### activateLightMode
510
+
511
+ Changes the website theme to light mode.
512
+
513
+ Example code:
514
+
515
+ ```js
516
+ chatgpt.activateLightMode();
517
+ ```
518
+
519
+ ### isDarkMode
520
+
521
+ Returns a boolean value. `true` if the theme is dark mode, `false` otherwise.
522
+
523
+ Example code:
524
+
525
+ ```js
526
+ console.log(chatgpt.settings.scheme.isDark()); // logs `true` or `false`
527
+ ```
528
+
529
+ ### isLightMode
530
+
531
+ Returns a boolean value. `true` if the theme is light mode, `false` otherwise.
532
+
533
+ Example code:
534
+
535
+ ```js
536
+ console.log(chatgpt.settings.scheme.isDark()); // logs `true` or `false`
537
+ ```
538
+
539
+ ### toggleScheme
540
+
541
+ Toggles the theme between light and dark mode.
542
+
543
+ Example code:
544
+
545
+ ```js
546
+ chatgpt.toggleScheme();
547
+ ```
548
+
549
+ ## In-site notifications
550
+
551
+ ### alert
552
+
553
+ Creates a static alert box which displays a message. Only a user interaction can close it. Returns the HTML `id` property of the alert box as a string.
554
+
555
+ **Parameters**:
556
+
557
+ `title` (optional): A string which is the title of the alert.
558
+
559
+ `msg` (optional): A string which is the message to be displayed.
560
+
561
+ `btns` (optional): An array of functions which will be rendered as clickable buttons.
562
+
563
+ `checkbox` (optional): A function which will be rendered as a checkbox.
564
+
565
+ `width` (optional): An integer representing the width of the alert box in `px`.
566
+
567
+ Example code:
568
+
569
+ ```js
570
+ function doSomething() { /* Your code */ }
571
+
572
+ function doSomethingElse() { /* Your code */ }
573
+
574
+ function sayHello() { console.log('Hello!'); }
575
+
576
+ const alertID = chatgpt.alert('Hello, world!', 'The sky is blue.', [doSomething, doSomethingElse], sayHello, 200);
577
+ console.log(alertID); // Example output: '1693237957878'
578
+ ```
579
+
580
+ ### notify
581
+
582
+ Displays a temporary notification at a specified position in the website.
583
+
584
+ **Parameters**:
585
+
586
+ `msg`: A string which is the message to be displayed.
587
+
588
+ `position` (optional): A string specifying the position of the notification.
589
+
590
+ `notifDuration` (optional): A float specifying the duration of the notification before it fades out.
591
+
592
+ `shadow` (optional): A string specifying if the `box-shadow` CSS property should be used.
593
+
594
+ Example code:
595
+
596
+ ```js
597
+ chatgpt.notify('Hello, world!', 'top left', 3, 'on');
598
+ ```
599
+
600
+ ## User session
601
+
602
+ ### getAccessToken `async`
603
+
604
+ Returns an account access token as a string.
605
+
606
+ ```js
607
+ (async () => {
608
+ const token = await chatgpt.getAccessToken();
609
+ console.log(token); // Example output: 'abcdef[...]'
610
+ })();
611
+ ```
612
+
613
+ ### getAccountDetails `async`
614
+
615
+ Returns a given account detail as a string.
616
+
617
+ **Parameters**:
618
+
619
+ `detail`: A string representing the account detail(s) that will be returned.
620
+
621
+ Can be the following: `email`, `id`, `image`, `name`, `picture`. If a single detail is passed, it will be returned as a string, if multiple are passed instead, the function will return an object with the requested details. If no details are passed, the function will return an object with all the available details.
622
+
623
+ ```js
624
+ (async () => {
625
+ const accountName = await chatgpt.getAccountDetails('name');
626
+ console.log(accountName); // Example output: 'chatgpt.js'
627
+
628
+ const accountData = await chatgpt.getAccountDetails('name', 'email');
629
+ console.log(accountData);
630
+ /* Example output:
631
+ {
632
+ name: 'chatgpt.js',
633
+ email: 'showcase@chatgptjs.org'
634
+ }
635
+ */
636
+ })();
637
+ ```
638
+
639
+ ### logout
640
+
641
+ Logs out the user from the website.
642
+
643
+ Example code:
644
+
645
+ ```js
646
+ chatgpt.logout();
647
+ ```
648
+
649
+ ## Chats
650
+
651
+ ### askAndGetReply `async`
652
+
653
+ Sends a given message to ChatGPT and returns the response as a string.
654
+
655
+ Example code:
656
+
657
+ ```js
658
+ (async () => {
659
+ const response = await chatgpt.askAndGetReply('Hello, ChatGPT');
660
+ console.log(response); // Example output: 'Hello user, I'm ChatGPT!'
661
+ })();
662
+ ```
663
+
664
+ ### clearChats `async`
665
+
666
+ `method` (optional): The string `'api'` or `'dom'` representing the method to use.
667
+
668
+ > **Note** _The API method does not update DOM chat list (until session refresh)_
669
+
670
+ ### exportChat `async`
671
+
672
+ Exports a given chat as a file.
673
+
674
+ **Parameters**:
675
+
676
+ `chatToGet` (optional): A string representing the chat to get the data from.
677
+
678
+ Can be the following: `active`, the current chat, `latest`, the latest chat in the list, else the `index`, `title` or `id` of the chat to get. Default is `active` if in a chat, else `latest`.
679
+
680
+ `format` (optional): A string representing the format of the export file.
681
+
682
+ Can be the following: `html`, `md`, `pdf` or `text`. Defaults to `html`.
683
+
684
+ Example code:
685
+
686
+ ```js
687
+ (async () => {
688
+ await chatgpt.exportChat('latest', 'html'); // Downloads a '.html' file
689
+ })();
690
+ ```
691
+
692
+ ### getChatData `async`
693
+
694
+ Returns the requested chat data as a string (if single detail requested) or object of key-value pairs (if multiple details requested).
695
+
696
+ **Parameters**:
697
+
698
+ `chatToGet` (optional): A string representing the chat to get the data from.
699
+
700
+ Can be the following: `active`, the current chat, `latest`, the latest chat in the list, else the `index`, `title` or `id` of the chat to get. Default is `active` if in a chat, else `latest`.
701
+
702
+ `detailsToGet` (optional): A string or array of strings representing the chat data to retrieve.
703
+
704
+ Can be the following: `all` to get all details, `id`, `title`, `create_time`, `update_time` or `msg`. To get a single detail, just use a string, to get multiple use an array of strings instead. Default is `all`.
705
+
706
+ _**If `msg` is the requested detail, the following parameters can be used**_:
707
+
708
+ `sender` (optional): A string representing the chat member to get the message(s) from.
709
+
710
+ Can be the following: `user` to get the user message(s), `chatgpt` to get ChatGPT's response(s), `all`/`both` to get both of them. Default is `all`.
711
+
712
+ `msgToGet` (optional): A string/number representing the chat message to retrieve.
713
+
714
+ Can be the following: `all` to get all the messages in the chat, `latest` to get the latest message/response, or the `index` of the message. Default is `all`.
715
+
716
+ > **Note** _If any **user** messages were edited, they are added to the index as newly sent messages_
717
+
718
+ Example code **for all return types**:
719
+
720
+ _**All details from specified chat**_
721
+
722
+ ```js
723
+ await chatgpt.getChatData();
724
+ // or
725
+ await chatgpt.getChatData('latest'); // can also be 'active', 'title of the chat' or 'id of the chat'
726
+ // or
727
+ await chatgpt.getChatData('latest', 'all');
728
+ ```
729
+
730
+ _Returns a JSON object_
731
+
732
+ ```json
733
+ {
734
+ "create_time": "2023-07-19T13:24:05.618539+00:00",
735
+ "id": "e193a219-2311-4232-95f5-8e3a0e466652",
736
+ "title": "Lemons: Citrus Fruit Overview.",
737
+ "update_time": "2023-07-19T13:24:18+00:00"
738
+ }
739
+ ```
740
+
741
+ _**Specific detail(s) from specified chat**_
742
+
743
+ ```js
744
+ await chatgpt.getChatData('latest', ['id', 'title']);
745
+ ```
746
+
747
+ _Returns a JSON object_
748
+
749
+ ```json
750
+ {
751
+ "id": "e193a219-2311-4232-95f5-8e3a0e466652",
752
+ "title": "Lemons: Citrus Fruit Overview."
753
+ }
754
+ ```
755
+
756
+ _**All messages from both participants in a specified chat**_
757
+
758
+ ```js
759
+ await chatgpt.getChatData('latest', 'msg');
760
+ // or
761
+ await chatgpt.getChatData('latest', 'msg', 'all'); // all/both
762
+ // or
763
+ await chatgpt.getChatData('latest', 'msg', 'all', 'all');
764
+ ```
765
+
766
+ _Returns an array of JSON objects_
767
+
768
+ In case of a response being regenerated, the `chatgpt` object key will be converted to an array containing all the responses.
769
+
770
+ ```json
771
+ [
772
+ {
773
+ "user": "what are lemons",
774
+ "chatgpt": "Lemons are a type of citrus fruit that belongs..."
775
+ },
776
+ {
777
+ "user": "be more specific",
778
+ "chatgpt": [
779
+ "Certainly! Here are some more specific...",
780
+ "Certainly! Here are some specific..." // regenerated responses!
781
+ ]
782
+ }
783
+ ]
784
+ ```
785
+
786
+ _**All messages from a specific participant in a specified chat**_
787
+
788
+ ```js
789
+ await chatgpt.getChatData('latest', 'msg');
790
+ // or
791
+ await chatgpt.getChatData('latest', 'msg', 'chatgpt'); // user/chatgpt
792
+ // or
793
+ await chatgpt.getChatData('latest', 'msg', 'chatgpt', 'all');
794
+ ```
795
+
796
+ _Returns an array of strings/arrays_
797
+
798
+ In case of a response being regenerated and the requested participant being `chatgpt`, it'll be converted to an array containing all the responses.
799
+
800
+ ```json
801
+ [
802
+ "Lemons are a type of citrus fruit that belongs...",
803
+ [
804
+ "Certainly! Here are some more specific details...",
805
+ "Certainly! Here are some specific..."
806
+ ]
807
+ ]
808
+ ```
809
+
810
+ _**One/latest message from both participants in a specified chat**_
811
+
812
+ ```js
813
+ await chatgpt.getChatData('latest', 'msg', 'all', 2); // can also be 'latest' message
814
+ ```
815
+
816
+ _Returns a JSON object_
817
+
818
+ In case of a response being regenerated, the `chatgpt` object key will be converted to an array containing all the responses.
819
+
820
+ ```json
821
+ {
822
+ "user": "be more specific",
823
+ "chatgpt": [
824
+ "Certainly! Here are some more specific...",
825
+ "Certainly! Here are some specific..."
826
+ ]
827
+ }
828
+ ```
829
+
830
+ _**One/latest message from a specific participant in a specified chat**_
831
+
832
+ ```js
833
+ await chatgpt.getChatData('latest', 'msg', 'chatgpt', 2);
834
+ ```
835
+
836
+ _Returns a string or an array of strings_
837
+
838
+ In case of a response being regenerated, the `chatgpt` object key will be converted to an array containing all the responses.
839
+
840
+ ```json
841
+ "Certainly! Here are some more specific..."
842
+ // or
843
+ [
844
+ "Certainly! Here are some more specific...",
845
+ "Certainly! Here are some specific..."
846
+ ]
847
+ ```
848
+
849
+ ### getChatInput
850
+
851
+ Returns the value of the chat input field as a string.
852
+
853
+ Example code:
854
+
855
+ ```js
856
+ const chatInput = chatgpt.getChatInput();
857
+ console.log(chatInput); // Example output: 'Hello from chatgpt.js!'
858
+ ```
859
+
860
+ ### getLastPrompt `async`
861
+
862
+ Returns the last message sent by the user as a string.
863
+
864
+ ```js
865
+ (async () => {
866
+ const message = await chatgpt.getLastPrompt();
867
+ console.log(message); // Example output: 'Hello from chatgpt.js!'
868
+ })();
869
+ ```
870
+
871
+ ### getLastResponse `async`
872
+
873
+ Returns the last ChatGPT response as a string.
874
+
875
+ ```js
876
+ (async () => {
877
+ const response = await chatgpt.getLastResponse();
878
+ console.log(response); // Example output: 'I am ChatGPT!'
879
+ })();
880
+ ```
881
+
882
+ ### getResponse
883
+
884
+ If it's a previously created chat, read [chatgpt.getResponseFromDOM](#getresponsefromdom)
885
+
886
+ If it's a new chat, read [chatgpt.getResponseFromAPI](#getresponsefromapi-async)
887
+
888
+ ### getResponseFromAPI `async`
889
+
890
+ Returns the Nth response ChatGPT has written in a Nth chat as a string.
891
+
892
+ **Parameters**:
893
+
894
+ `chatToGet` (optional): A number representing the index of the chat to get the response from. Defaults to `latest`.
895
+
896
+ `responseToGet` (optional): A number representing the index of the response to get. Defaults to `latest`.
897
+
898
+ Example code:
899
+
900
+ ```js
901
+ (async () => {
902
+ const response = chatgpt.getResponseFromAPI();
903
+ console.log(response); // Example output: 'Hello from ChatGPT!'
904
+ })();
905
+ ```
906
+
907
+ ### getResponseFromDOM
908
+
909
+ Returns the Nth response ChatGPT has written as a string.
910
+
911
+ **Parameters**:
912
+
913
+ `pos`: A string or integer representing the position of the wanted response.
914
+
915
+ Example code:
916
+
917
+ ```js
918
+ var fifthResp;
919
+
920
+ fifthResp = chatgpt.getResponseFromDOM(5); // Returns the 5th response
921
+ fifthResp = chatgpt.getResponseFromDOM('fifth'); // Also returns the 5th response
922
+ fifthResp = chatgpt.getResponseFromDOM('five'); // Returns the 5th response too
923
+
924
+ console.log(fifthResp); // Example output: 'Hello from ChatGPT!'
925
+ ```
926
+
927
+ ### isIdle `async`
928
+
929
+ Returns a boolean value. `true` if ChatGPT has finished generating a response, `false` otherwise.
930
+
931
+ Example code:
932
+
933
+ ```js
934
+ (async () => {
935
+ if (await chatgpt.isIdle()) {
936
+ // Do something
937
+ }
938
+ })();
939
+ ```
940
+
941
+ ### regenerate
942
+
943
+ Regenerates ChatGPT's response.
944
+
945
+ Example code:
946
+
947
+ ```js
948
+ chatgpt.regenerate();
949
+ ```
950
+
951
+ ### resend `async`
952
+
953
+ Re-sends the last user message.
954
+
955
+ ```js
956
+ (async () => {
957
+ await chatgpt.resend();
958
+ })();
959
+ ```
960
+
961
+ ### scrollToBottom
962
+
963
+ Scrolls to the bottom of the chat.
964
+
965
+ Example code:
966
+
967
+ ```js
968
+ chatgpt.scrollToBottom();
969
+ ```
970
+
971
+ ### send
972
+
973
+ Sends a message into the chat.
974
+
975
+ **Parameters**:
976
+
977
+ `msg`: A string representing the message to send.
978
+
979
+ `method` (optional): A string representing the method to send the message with, can only be `click`. Usually needed for mobile devices compatibility.
980
+
981
+ Example code:
982
+
983
+ ```js
984
+ // Clicks the send button instead of triggering the 'Enter' key press.
985
+ chatgpt.send('Hello, world!', 'click');
986
+ ```
987
+
988
+ ### sendInNewChat
989
+
990
+ Creates a new chat and sends a message.
991
+
992
+ **Parameters**:
993
+
994
+ `msg`: A string representing the message to send.
995
+
996
+ Example code:
997
+
998
+ ```js
999
+ chatgpt.sendInNewChat('Hello, world!');
1000
+ ```
1001
+
1002
+ ### shareChat `async`
1003
+
1004
+ Makes the selected chat available to others. Returns the URL of the chat as a string.
1005
+
1006
+ **Parameters**:
1007
+
1008
+ `chatToGet` (optional): A number or string representing the `index`, `title` or `id` of the chat to share.
1009
+
1010
+ `method` (optional): A string representing the method to share the chat with. Defaults to `clipboard`.
1011
+
1012
+ Can be the following: `copy` or `clipboard` to copy the chat URL to clipboard, `alert`, `notify` or `notification` to create an [alert message](#alert) with the details about the shared chat in the website.
1013
+
1014
+ ```js
1015
+ (async () => {
1016
+ await chatgpt.shareChat(1, 'copy'); // copy/clipboard
1017
+ })();
1018
+ ```
1019
+
1020
+ ### speak
1021
+
1022
+ Text To Speech (TTS) conversion of a given message.
1023
+
1024
+ **Parameters**:
1025
+
1026
+ `msg`: A string representing the message to TTS.
1027
+
1028
+ `options` (optional): An object containing the options for the vocal synthesizer.
1029
+
1030
+ Available options:
1031
+
1032
+ - `voice`: A number representing the index of voices available on the user device.
1033
+ - `pitch`: A float representing the pitch of the speech. From `0` to `2`.
1034
+ - `speed`: A float representing the speed of the speech. From `0.1` to `10`.
1035
+
1036
+ Example code:
1037
+
1038
+ ```js
1039
+ (async () => {
1040
+ chatgpt.speak(await chatgpt.getLastResponse(), { voice: 1, pitch: 2, speed: 3 });
1041
+ })();
1042
+ ```
1043
+
1044
+ ### startNewChat
1045
+
1046
+ Creates a new chat.
1047
+
1048
+ Example code:
1049
+
1050
+ ```js
1051
+ chatgpt.startNewChat();
1052
+ ```
1053
+
1054
+ ### stop
1055
+
1056
+ Stops the generation of ChatGPT's response.
1057
+
1058
+ Example code:
1059
+
1060
+ ```js
1061
+ chatgpt.stop();
1062
+ ```
1063
+
1064
+ ## DOM related
1065
+
1066
+ ### getChatBox
1067
+
1068
+ Returns the chat input as an HTML element.
1069
+
1070
+ Example code:
1071
+
1072
+ ```js
1073
+ const chatbox = chatgpt.getChatBox();
1074
+ console.log(chatbox.value); // Example output: 'Hello from chatgpt.js!'
1075
+ ```
1076
+
1077
+ ### getContinueGeneratingButton
1078
+
1079
+ Returns the 'Continue generating' button as an HTML element.
1080
+
1081
+ Example code:
1082
+
1083
+ ```js
1084
+ const continueButton = chatgpt.getContinueGeneratingButton();
1085
+ continueButton.click();
1086
+ ```
1087
+
1088
+ ### getNewChatLink
1089
+
1090
+ Returns the button which creates a new chat as an HTML element.
1091
+
1092
+ Example code:
1093
+
1094
+ ```js
1095
+ const newChatLink = chatgpt.getNewChatLink();
1096
+ newChatLink.click();
1097
+ ```
1098
+
1099
+ ### getRegenerateButton
1100
+
1101
+ Returns the button which regenerates ChatGPT's response as an HTML element.
1102
+
1103
+ Example code:
1104
+
1105
+ ```js
1106
+ const regenButton = chatgpt.getRegenerateButton();
1107
+ regenButton.click();
1108
+ ```
1109
+
1110
+ ### getSendButton
1111
+
1112
+ Returns the button which sends the message as an HTML element.
1113
+
1114
+ Example code:
1115
+
1116
+ ```js
1117
+ const sendButton = chatgpt.getSendButton();
1118
+ sendButton.click();
1119
+ ```
1120
+
1121
+ ### getStopGeneratingButton
1122
+
1123
+ Returns the button which stops the generation of ChatGPT's response as an HTML element.
1124
+
1125
+ Example code:
1126
+
1127
+ ```js
1128
+ const stopButton = chatgpt.getStopGeneratingButton();
1129
+ stopButton.click();
1130
+ ```
1131
+
1132
+ # Library APIs
1133
+
1134
+ ## autoRefresh `api`
1135
+
1136
+ API related to keeping the user's session alive and fresh.
1137
+
1138
+ #### activate
1139
+
1140
+ Activates the auto-refresh functionality.
1141
+
1142
+ **Parameters**:
1143
+
1144
+ `interval` (optional): A number representing the interval in seconds between sessions refreshes. Defaults to `30`.
1145
+
1146
+ Example code:
1147
+
1148
+ ```js
1149
+ chatgpt.autoRefresh.activate();
1150
+ ```
1151
+
1152
+ #### deactivate
1153
+
1154
+ Deactivates the auto-refresh functionality.
1155
+
1156
+ Example code:
1157
+
1158
+ ```js
1159
+ chatgpt.autoRefresh.deactivate();
1160
+ ```
1161
+
1162
+ #### nowTimeStamp
1163
+
1164
+ Returns the current timestamp as a string (12-hour format).
1165
+
1166
+ Example code:
1167
+
1168
+ ```js
1169
+ const timeStamp = chatgpt.autoRefresh.nowTimeStamp();
1170
+ console.log(timeStamp); // Example output: '1:56:25 PM'
1171
+ ```
1172
+
1173
+ ## browser `api`
1174
+
1175
+ ### isLightMode
1176
+
1177
+ Returns a boolean value. `true` if system/browser scheme preference is set to light, `false` otherwise.
1178
+
1179
+ Example code:
1180
+
1181
+ ```js
1182
+ console.log(chatgpt.browser.isLightMode()); // logs `true` or `false`
1183
+ ```
1184
+
1185
+ ### isDarkMode
1186
+
1187
+ Returns a boolean value. `true` if system/browser scheme preference is set to dark, `false` otherwise.
1188
+
1189
+ Example code:
1190
+
1191
+ ```js
1192
+ console.log(chatgpt.browser.isDarkMode()); // logs `true` or `false`
1193
+ ```
1194
+
1195
+ ### isChromium
1196
+
1197
+ Returns a boolean value. `true` if the browser is Chromium and `false` otherwise.
1198
+
1199
+ Example code:
1200
+
1201
+ ```js
1202
+ if (chatgpt.browser.isChromium()) {
1203
+ // Do something
1204
+ }
1205
+ ```
1206
+
1207
+ ### isFirefox
1208
+
1209
+ Returns a boolean value. `true` if the browser is Firefox and `false` otherwise.
1210
+
1211
+ Example code:
1212
+
1213
+ ```js
1214
+ if (chatgpt.browser.isFirefox()) {
1215
+ // Do something
1216
+ }
1217
+ ```
1218
+
1219
+ ### isFullScreen
1220
+
1221
+ Returns a boolean value. `true` if the browser is fullscreen and `false` otherwise.
1222
+
1223
+ Example code:
1224
+
1225
+ ```js
1226
+ if (chatgpt.browser.isFullScreen()) {
1227
+ // Do something
1228
+ }
1229
+ ```
1230
+
1231
+ ### isMobile
1232
+
1233
+ Returns a boolean value. `true` if the browser is mobile and `false` otherwise.
1234
+
1235
+ Example code:
1236
+
1237
+ ```js
1238
+ if (chatgpt.browser.isMobile()) {
1239
+ // Do something
1240
+ }
1241
+ ```
1242
+
1243
+ ## code `api`
1244
+
1245
+ ### minify `async`
1246
+
1247
+ Asks ChatGPT to minify the given code.
1248
+
1249
+ **Parameters**:
1250
+
1251
+ `code`: A string being the code to be minified.
1252
+
1253
+ Example code:
1254
+
1255
+ ```js
1256
+ (async () => {
1257
+ const minifiedCode = await chatgpt.code.minify(`
1258
+ function autosizeBox() {
1259
+ const newLength = replyBox.value.length
1260
+ if (newLength < prevLength) { // if deleting txt
1261
+ replyBox.style.height = 'auto' // ...auto-fit height
1262
+ if (parseInt(getComputedStyle(replyBox).height) < 55) { // if down to one line
1263
+ replyBox.style.height = '2.15rem' } // ...reset to original height
1264
+ }
1265
+ replyBox.style.height = replyBox.scrollHeight + 'px'
1266
+ prevLength = newLength
1267
+ }`);
1268
+ console.log(minifiedCode);
1269
+
1270
+ /* Logs:
1271
+ 'function autosizeBox(){const n=replyBox.value.length;if(n<prevLength){replyBox.style.height='auto';if(parseInt(getComputedStyle(replyBox).height)<55){replyBox.style.height='2.15rem'}}replyBox.style.height=replyBox.scrollHeight+'px';prevLength=n}' */
1272
+ })();
1273
+ ```
1274
+
1275
+ ### execute `async`
1276
+
1277
+ Asks ChatGPT to execute the given code.
1278
+
1279
+ **Parameters**:
1280
+
1281
+ `code`: A string being the code to execute.
1282
+
1283
+ Example code:
1284
+
1285
+ ```js
1286
+ (async () => {
1287
+ console.log(await chatgpt.code.execute('return 6 + 5')); // logs '11'
1288
+ })();
1289
+ ```
1290
+
1291
+ ### extract
1292
+
1293
+ Extracts pure code from response.
1294
+
1295
+ **Parameters**:
1296
+
1297
+ `msg`: A string being the response to extract code from.
1298
+
1299
+ Example code:
1300
+
1301
+ ```js
1302
+ (async () => {
1303
+ chatgpt.send('What is a short script to delete files?');
1304
+ await chatgpt.isIdle();
1305
+ const response = await chatgpt.getChatData('active', 'msg', 'chatgpt', 'latest'),
1306
+ scriptCode = chatgpt.code.extract(response);
1307
+ console.log(scriptCode);
1308
+
1309
+ /* Logs:
1310
+ const fs = require('fs');
1311
+
1312
+ // Specify the path of the file(s) you want to delete
1313
+ const filePath = 'path/to/your/file.txt';
1314
+
1315
+ // Delete the file
1316
+ fs.unlink(filePath, (err) => {
1317
+ if (err) {
1318
+ console.error('Error deleting file:', err);
1319
+ } else {
1320
+ console.log('File deleted successfully');
1321
+ }
1322
+ }); */
1323
+ })();
1324
+ ```
1325
+
1326
+ ### obfuscate `async`
1327
+
1328
+ Asks ChatGPT to obfuscate the given code.
1329
+
1330
+ **Parameters**:
1331
+
1332
+ `code`: A string being the code to obfuscate.
1333
+
1334
+ Example code:
1335
+
1336
+ ```js
1337
+ (async () => {
1338
+ const code = `window[elem].addEventListener('mouseover', toggleTooltip)`
1339
+ const obfuscatedCode = await chatgpt.code.obfuscate(code);
1340
+ console.log(obfuscatedCode);
1341
+
1342
+ /* Logs:
1343
+ '(window[elem])[btoa('YWxlcnRWaWV3')](btoa('bW91c2VyYm94ZXJOYW1l'), btoa('dG9nZ2VkT3V0d2FsbA==')); */
1344
+ })();
1345
+ ```
1346
+
1347
+ ### refactor `async`
1348
+
1349
+ Asks ChatGPT to refactor the given code.
1350
+
1351
+ **Parameters**:
1352
+
1353
+ `code`: A string being the code to refactor.
1354
+
1355
+ `objective` (optional): A string reprenting the objective of the refactoring. Defaults to `brevity`.
1356
+
1357
+ Example code:
1358
+
1359
+ ```js
1360
+ (async () => {
1361
+ const code = `
1362
+ if (6 > 5) {
1363
+ return true;
1364
+ } else {
1365
+ return false;
1366
+ }`;
1367
+ const refactoredCode = await chatgpt.code.refactor(code, 'brevity');
1368
+ console.log(refactoredCode);
1369
+
1370
+ /* Logs:
1371
+ return 6 > 5; */
1372
+ })();
1373
+ ```
1374
+
1375
+ ### review `async`
1376
+
1377
+ Asks ChatGPT to review given code.
1378
+
1379
+ **Parameters**:
1380
+
1381
+ `code`: A string being the code to review.
1382
+
1383
+ Example code:
1384
+
1385
+ ```js
1386
+ (async () => {
1387
+ console.log(await chatgpt.code.review('btoa("Hello World")'));
1388
+
1389
+ /* Example output:
1390
+ The code appears to be correct. It uses the `btoa` function to encode the string "Hello World" in base64. */
1391
+ })();
1392
+ ```
1393
+
1394
+ ### unminify `async`
1395
+
1396
+ Asks ChatGPT to unminify the given code.
1397
+
1398
+ **Parameters**:
1399
+
1400
+ `code`: A string being the code to unminify.
1401
+
1402
+ Example code:
1403
+
1404
+ ```js
1405
+ (async () => {
1406
+ const code = `function autosizeBox(){const n=replyBox.value.length;if(n<prevLength){replyBox.style.height='auto';if(parseInt(getComputedStyle(replyBox).height)<55){replyBox.style.height='2.15rem'}}replyBox.style.height=replyBox.scrollHeight+'px';prevLength=n}`;
1407
+
1408
+ const minifiedCode = await chatgpt.code.unminify(code);
1409
+ console.log(minifiedCode);
1410
+
1411
+ /* Logs:
1412
+ function autosizeBox() {
1413
+ const newLength = replyBox.value.length
1414
+ if (newLength < prevLength) { // if deleting txt
1415
+ replyBox.style.height = 'auto' // ...auto-fit height
1416
+ if (parseInt(getComputedStyle(replyBox).height) < 55) { // if down to one line
1417
+ replyBox.style.height = '2.15rem' } // ...reset to original height
1418
+ }
1419
+ replyBox.style.height = replyBox.scrollHeight + 'px'
1420
+ prevLength = newLength
1421
+ }` */
1422
+ })();
1423
+ ```
1424
+
1425
+ ### write `async`
1426
+
1427
+ Asks ChatGPT to write code given a prompt.
1428
+
1429
+ **Parameters**:
1430
+
1431
+ `prompt`: A string describing the code to generate.
1432
+
1433
+ `outputLang`: A string representing the code language to generate the prompt with.
1434
+
1435
+ Example code:
1436
+
1437
+ ```js
1438
+ (async () => {
1439
+ const code = await chatgpt.code.write('Repeat a task every 10 seconds', 'javascript');
1440
+ console.log(code);
1441
+
1442
+ /* Logs:
1443
+ setInterval(function() {
1444
+ // Your task code here
1445
+ }, 10000); */
1446
+ })();
1447
+ ```
1448
+
1449
+ ## history `api`
1450
+
1451
+ API related to the chat history.
1452
+
1453
+ ### isOn
1454
+
1455
+ Returns a boolean value. `true` if the chat history is enabled, `false` otherwise.
1456
+
1457
+ Example code:
1458
+
1459
+ ```js
1460
+ if (chatgpt.history.isOn()) {
1461
+ // Do something
1462
+ }
1463
+ ```
1464
+
1465
+ ### isOff
1466
+
1467
+ Returns a boolean value. `true` if the chat history is disabled, `false` otherwise.
1468
+
1469
+ Example code:
1470
+
1471
+ ```js
1472
+ if (chatgpt.history.isOff()) {
1473
+ // Do something
1474
+ }
1475
+ ```
1476
+
1477
+ ### activate
1478
+
1479
+ Activates the chat history.
1480
+
1481
+ Example code:
1482
+
1483
+ ```js
1484
+ chatgpt.history.activate();
1485
+ ```
1486
+
1487
+ ### deactivate
1488
+
1489
+ Deactivates the chat history.
1490
+
1491
+ Example code:
1492
+
1493
+ ```js
1494
+ chatgpt.history.deactivate();
1495
+ ```
1496
+
1497
+ ### isLoaded `async`
1498
+
1499
+ Resolves a promise when chat history has finished loading.
1500
+
1501
+ Example code:
1502
+
1503
+ ```js
1504
+ (async () => {
1505
+ await chatgpt.history.isLoaded();
1506
+ console.log('ChatGPT history has finished loading.');
1507
+ })();
1508
+ ```
1509
+
1510
+ ### toggle
1511
+
1512
+ Toggles the chat history.
1513
+
1514
+ Example code:
1515
+
1516
+ ```js
1517
+ chatgpt.history.toggle();
1518
+ ```
1519
+
1520
+ ## instructions `api`
1521
+
1522
+ ### add `async`
1523
+
1524
+ Adds a custom instruction for either the user or ChatGPT.
1525
+
1526
+ **Parameters**:
1527
+
1528
+ `instruction`: A string being the instruction to be added.
1529
+
1530
+ `target`: A string representing the target of the instruction. Can be either `user` or `chatgpt`.
1531
+
1532
+ Example code:
1533
+
1534
+ ```js
1535
+ (async () => {
1536
+ await chatgpt.instructions.add('Detailed and well-explained answers', 'chatgpt');
1537
+ })();
1538
+ ```
1539
+
1540
+ ### clear `async`
1541
+
1542
+ Clears the custom instructions of either the user or ChatGPT.
1543
+
1544
+ **Parameters**:
1545
+
1546
+ `target`: A string representing the target of the instruction. Can be either `user` or `chatgpt`.
1547
+
1548
+ Example code:
1549
+
1550
+ ```js
1551
+ (async () => {
1552
+ await chatgpt.instructions.clear('user');
1553
+ })();
1554
+ ```
1555
+
1556
+ ### turnOff `async`
1557
+
1558
+ Turns off custom instructions.
1559
+
1560
+ Example code:
1561
+
1562
+ ```js
1563
+ (async () => {
1564
+ await chatgpt.instructions.turnOff();
1565
+ })();
1566
+ ```
1567
+
1568
+ ### turnOn `async`
1569
+
1570
+ Turns on custom instructions.
1571
+
1572
+ Example code:
1573
+
1574
+ ```js
1575
+ (async () => {
1576
+ await chatgpt.instructions.turnOn();
1577
+ })();
1578
+ ```
1579
+
1580
+ ### toggle `async`
1581
+
1582
+ Toggles on/off custom instructions.
1583
+
1584
+ Example code:
1585
+
1586
+ ```js
1587
+ (async () => {
1588
+ await chatgpt.instructions.toggle();
1589
+ })();
1590
+ ```
1591
+
1592
+ ## menu `api`
1593
+
1594
+ The small menu that shows up when clicking on the account button.
1595
+
1596
+ ### open
1597
+
1598
+ Opens the menu.
1599
+
1600
+ Example code:
1601
+
1602
+ ```js
1603
+ chatgpt.menu.open();
1604
+ ```
1605
+
1606
+ ### close
1607
+
1608
+ Closes the menu.
1609
+
1610
+ Example code:
1611
+
1612
+ ```js
1613
+ chatgpt.menu.close();
1614
+ ```
1615
+
1616
+ ## response `api`
1617
+
1618
+ API related to ChatGPT's responses.
1619
+
1620
+ ### get
1621
+
1622
+ If it's a previously created chat, read [chatgpt.getResponseFromDOM](#getresponsefromdom)
1623
+
1624
+ If it's a new chat, read [chatgpt.getResponseFromAPI](#getresponsefromapi-async)
1625
+
1626
+ ### getFromAPI `async`
1627
+
1628
+ Read [chatgpt.getResponseFromAPI](#getresponsefromapi-async)
1629
+
1630
+ ### getFromDOM
1631
+
1632
+ Read [chatgpt.getResponseFromDOM](#getresponsefromdom)
1633
+
1634
+ ### getLast `async`
1635
+
1636
+ Read [chatgpt.getLastResponse](#getlastresponse-async)
1637
+
1638
+ ### regenerate
1639
+
1640
+ Read [chatgpt.regenerate](#regenerate)
1641
+
1642
+ ### stopGenerating
1643
+
1644
+ Read [chatgpt.stop](#stop)
1645
+
1646
+ ## settings `api`
1647
+
1648
+ API for interfacing with ChatGPT user settings.
1649
+
1650
+ ### scheme `api subset`
1651
+
1652
+ #### isDark
1653
+
1654
+ Returns a boolean value. `true` if the theme is dark mode, `false` otherwise.
1655
+
1656
+ Example code:
1657
+
1658
+ ```js
1659
+ console.log(chatgpt.settings.scheme.isDark()); // logs `true` or `false`
1660
+ ````
1661
+
1662
+ #### isLight
1663
+
1664
+ Returns a boolean value. `true` if the theme is light mode, `false` otherwise.
1665
+
1666
+ Example code:
1667
+
1668
+ ```js
1669
+ console.log(chatgpt.settings.scheme.isLight()); // logs `true` or `false`
1670
+ ````
1671
+
1672
+ #### set
1673
+
1674
+ Sets the theme to `light`, `dark` or `system`.
1675
+
1676
+ **Paremeters**:
1677
+
1678
+ `value`: A string being the value to set the theme to.
1679
+
1680
+ Example code:
1681
+
1682
+ ```js
1683
+ chatgpt.settings.scheme.set('dark');
1684
+ ```
1685
+
1686
+ #### toggle
1687
+
1688
+ Toggles the theme between light and dark mode.
1689
+
1690
+ Example code:
1691
+
1692
+ ```js
1693
+ chatgpt.settings.scheme.toggle();
1694
+ ```
1695
+
1696
+ ## sidebar `api`
1697
+
1698
+ API related to the sidebar's behavior.
1699
+
1700
+ ### append
1701
+
1702
+ Appends a new element to the sidebar. Returns the `id` property of the element.
1703
+
1704
+ **Parameters**:
1705
+
1706
+ `element`: A string being the name of the element to append.
1707
+
1708
+ Currently supported elements are [`button`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button) and [`dropdown`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/select).
1709
+
1710
+ `attrs`: An object which contains the attributes of the element to append.
1711
+
1712
+ _**Attributes for `button`**_
1713
+
1714
+ `label`: A string being the label (displayed text) of the button. Defaults to `chatgpt.js button`.
1715
+
1716
+ `icon`: A string being either a url to an image or a base64 encoded string of the image data. Defaults to [this icon](https://raw.githubusercontent.com/KudoAI/chatgpt.js/main/starters/chrome/extension/icons/icon128.png).
1717
+
1718
+ `onclick`: A function which is called when the button is clicked. Defaults to `function() {}`.
1719
+
1720
+ _**Attributes for `dropdown`**_
1721
+
1722
+ `items`: An array of objects where the `text` key is the displayed text of the option, and the `value` key is the value of the option.
1723
+
1724
+ Example item object:
1725
+
1726
+ ```js
1727
+ {
1728
+ text: 'The text to display in the option',
1729
+ value: 'The value of the option'
1730
+ }
1731
+ ```
1732
+
1733
+ Example code:
1734
+
1735
+ ```js
1736
+ const buttonId = chatgpt.sidebar.append('button', {
1737
+ label: 'I am a button!',
1738
+ icon: 'https://chat.openai.com/favicon-32x32.png',
1739
+ onclick: function() {
1740
+ console.log('Clicked!');
1741
+ }
1742
+ });
1743
+ console.log(buttonId); // Example output: 1693295258727
1744
+
1745
+ const dropdownId = chatgpt.sidebar.append('dropdown', {
1746
+ items: [
1747
+ { text: 'Hello world', value: 'helloworld' },
1748
+ { text: 'Hello there', value: 'hellothere' }
1749
+ ]
1750
+ });
1751
+ console.log(dropdownId); // Example output: 1693294795240
1752
+ ```
1753
+
1754
+ ### isOn
1755
+
1756
+ Returns a boolean value. `true` if the sidebar is open, `false` otherwise.
1757
+
1758
+ Example code:
1759
+
1760
+ ```js
1761
+ if (chatgpt.sidebar.isOn()) {
1762
+ // Do something
1763
+ }
1764
+ ```
1765
+
1766
+ ### isOff
1767
+
1768
+ Returns a boolean value. `true` if the sidebar is closed, `false` otherwise.
1769
+
1770
+ Example code:
1771
+
1772
+ ```js
1773
+ if (chatgpt.sidebar.isOff()) {
1774
+ // Do something
1775
+ }
1776
+ ```
1777
+
1778
+ ### hide
1779
+
1780
+ Hides the sidebar.
1781
+
1782
+ Example code:
1783
+
1784
+ ```js
1785
+ chatgpt.sidebar.hide();
1786
+ ```
1787
+
1788
+ ### show
1789
+
1790
+ Shows the sidebar.
1791
+
1792
+ Example code:
1793
+
1794
+ ```js
1795
+ chatgpt.sidebar.show();
1796
+ ```
1797
+
1798
+ ### toggle
1799
+
1800
+ Toggles the visibility of the sidebar.
1801
+
1802
+ Example code:
1803
+
1804
+ ```js
1805
+ chatgpt.sidebar.toggle();
1806
+ ```
1807
+
1808
+ <br>
1809
+ <br>
1810
+
1811
+ [Discuss](https://github.com/kudoai/chatgpt.js/discussions) /
1812
+ <a href="#">Back to top ↑</a>