@kudoai/chatgpt.js 2.6.7 → 2.6.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +9 -0
- package/README.md +30 -34
- package/chatgpt.js +2001 -2060
- package/dist/chatgpt.min.js +9 -3
- package/docs/README.md +30 -34
- package/docs/SECURITY.md +25 -25
- package/docs/USERGUIDE.md +6 -65
- package/package.json +73 -73
- package/starters/chrome/LICENSE.md +31 -43
- package/starters/chrome/docs/README.md +93 -93
- package/starters/chrome/docs/SECURITY.md +17 -17
- package/starters/chrome/extension/background.js +14 -14
- package/starters/chrome/extension/content.js +62 -62
- package/starters/chrome/extension/lib/chatgpt.js +2002 -2061
- package/starters/chrome/extension/lib/settings-utils.js +24 -24
- package/starters/chrome/extension/manifest.json +24 -24
- package/starters/chrome/extension/popup/index.html +62 -62
- package/starters/chrome/extension/popup/popup.js +92 -92
- package/starters/chrome/extension/popup/style.css +55 -55
- package/starters/docs/LICENSE.md +13 -25
- package/starters/docs/README.md +29 -29
- package/starters/greasemonkey/LICENSE.md +31 -43
- package/starters/greasemonkey/chatgpt.js-greasemonkey-starter.user.js +5 -5
- package/starters/greasemonkey/docs/README.md +7 -7
- package/starters/greasemonkey/docs/SECURITY.md +17 -17
- package/LICENSE +0 -21
- package/docs/de/LICENSE.md +0 -29
- package/docs/de/README.md +0 -343
- package/docs/de/SECURITY.md +0 -25
- package/docs/es/LICENSE.md +0 -29
- package/docs/es/README.md +0 -343
- package/docs/es/SECURITY.md +0 -25
- package/docs/fr/LICENSE.md +0 -29
- package/docs/fr/README.md +0 -343
- package/docs/fr/SECURITY.md +0 -25
- package/docs/hi/LICENSE.md +0 -29
- package/docs/hi/README.md +0 -344
- package/docs/hi/SECURITY.md +0 -25
- package/docs/it/LICENSE.md +0 -27
- package/docs/it/README.md +0 -343
- package/docs/it/SECURITY.md +0 -25
- package/docs/ja/LICENSE.md +0 -29
- package/docs/ja/README.md +0 -343
- package/docs/ja/SECURITY.md +0 -25
- package/docs/ko/LICENSE.md +0 -32
- package/docs/ko/README.md +0 -348
- package/docs/ko/SECURITY.md +0 -25
- package/docs/ne/LICENSE.md +0 -35
- package/docs/ne/README.md +0 -344
- package/docs/ne/SECURITY.md +0 -25
- package/docs/nl/LICENSE.md +0 -29
- package/docs/nl/README.md +0 -343
- package/docs/nl/SECURITY.md +0 -25
- package/docs/pt/LICENSE.md +0 -29
- package/docs/pt/README.md +0 -343
- package/docs/pt/SECURITY.md +0 -25
- package/docs/vi/LICENSE.md +0 -29
- package/docs/vi/README.md +0 -343
- package/docs/vi/SECURITY.md +0 -25
- package/docs/zh-cn/LICENSE.md +0 -29
- package/docs/zh-cn/README.md +0 -343
- package/docs/zh-cn/SECURITY.md +0 -25
- package/docs/zh-tw/LICENSE.md +0 -29
- package/docs/zh-tw/README.md +0 -342
- package/docs/zh-tw/SECURITY.md +0 -25
- package/starters/chrome/docs/de/LICENSE.md +0 -31
- package/starters/chrome/docs/de/README.md +0 -93
- package/starters/chrome/docs/es/LICENSE.md +0 -31
- package/starters/chrome/docs/es/README.md +0 -93
- package/starters/chrome/docs/fr/LICENSE.md +0 -31
- package/starters/chrome/docs/fr/README.md +0 -93
- package/starters/chrome/docs/hi/LICENSE.md +0 -31
- package/starters/chrome/docs/hi/README.md +0 -93
- package/starters/chrome/docs/hi/SECURITY.md +0 -17
- package/starters/chrome/docs/it/LICENSE.md +0 -29
- package/starters/chrome/docs/it/README.md +0 -93
- package/starters/chrome/docs/ja/LICENSE.md +0 -31
- package/starters/chrome/docs/ja/README.md +0 -93
- package/starters/chrome/docs/ko/LICENSE.md +0 -34
- package/starters/chrome/docs/ko/README.md +0 -93
- package/starters/chrome/docs/nl/LICENSE.md +0 -30
- package/starters/chrome/docs/nl/README.md +0 -93
- package/starters/chrome/docs/pt/LICENSE.md +0 -31
- package/starters/chrome/docs/pt/README.md +0 -93
- package/starters/chrome/docs/vi/LICENSE.md +0 -31
- package/starters/chrome/docs/vi/README.md +0 -93
- package/starters/chrome/docs/zh-cn/LICENSE.md +0 -31
- package/starters/chrome/docs/zh-cn/README.md +0 -93
- package/starters/chrome/docs/zh-cn/SECURITY.md +0 -17
- package/starters/chrome/docs/zh-tw/LICENSE.md +0 -31
- package/starters/chrome/docs/zh-tw/README.md +0 -93
- package/starters/docs/de/LICENSE.md +0 -13
- package/starters/docs/de/README.md +0 -29
- package/starters/docs/es/LICENSE.md +0 -13
- package/starters/docs/es/README.md +0 -29
- package/starters/docs/fr/LICENSE.md +0 -13
- package/starters/docs/fr/README.md +0 -29
- package/starters/docs/hi/LICENSE.md +0 -13
- package/starters/docs/hi/README.md +0 -29
- package/starters/docs/it/LICENSE.md +0 -11
- package/starters/docs/it/README.md +0 -29
- package/starters/docs/ja/LICENSE.md +0 -13
- package/starters/docs/ja/README.md +0 -30
- package/starters/docs/ko/LICENSE.md +0 -16
- package/starters/docs/ko/README.md +0 -29
- package/starters/docs/nl/LICENSE.md +0 -13
- package/starters/docs/nl/README.md +0 -29
- package/starters/docs/pt/LICENSE.md +0 -13
- package/starters/docs/pt/README.md +0 -29
- package/starters/docs/vi/LICENSE.md +0 -13
- package/starters/docs/vi/README.md +0 -29
- package/starters/docs/zh-cn/LICENSE.md +0 -13
- package/starters/docs/zh-cn/README.md +0 -30
- package/starters/docs/zh-tw/LICENSE.md +0 -13
- package/starters/docs/zh-tw/README.md +0 -29
- package/starters/greasemonkey/docs/de/LICENSE.md +0 -31
- package/starters/greasemonkey/docs/es/LICENSE.md +0 -31
- package/starters/greasemonkey/docs/fr/LICENSE.md +0 -31
- package/starters/greasemonkey/docs/hi/LICENSE.md +0 -31
- package/starters/greasemonkey/docs/hi/SECURITY.md +0 -17
- package/starters/greasemonkey/docs/it/LICENSE.md +0 -29
- package/starters/greasemonkey/docs/ja/LICENSE.md +0 -31
- package/starters/greasemonkey/docs/ko/LICENSE.md +0 -34
- package/starters/greasemonkey/docs/nl/LICENSE.md +0 -30
- package/starters/greasemonkey/docs/pt/LICENSE.md +0 -31
- package/starters/greasemonkey/docs/vi/LICENSE.md +0 -31
- package/starters/greasemonkey/docs/zh-cn/LICENSE.md +0 -31
- package/starters/greasemonkey/docs/zh-cn/SECURITY.md +0 -17
- package/starters/greasemonkey/docs/zh-tw/LICENSE.md +0 -31
package/chatgpt.js
CHANGED
|
@@ -1,2060 +1,2001 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Source: https://github.com/KudoAI/chatgpt.js
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
localStorage.
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
isFFtmScript = isFFuserScript && GM_info.scriptHandler == 'Tampermonkey';
|
|
29
|
-
|
|
30
|
-
// Define
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
xhr.
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
'.chatgpt-modal {'
|
|
134
|
-
+ '
|
|
135
|
-
+ '
|
|
136
|
-
|
|
137
|
-
+ '
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
+
|
|
145
|
-
+
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
+
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
.replace(
|
|
200
|
-
.
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
const
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
//
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
setTimeout(() => { // delay
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
modalContainer.
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
const
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
},
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
if (
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
await chatgpt.
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
if (!
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
const
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
xhr
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
},
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
if (
|
|
962
|
-
else
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
if (!
|
|
985
|
-
return console.error(`
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
},
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
notificationDiv.
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
const
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
//
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
notificationDiv.
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
//
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
//
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
const
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
if (
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
});});};
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
const
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
}
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
},
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
['refactor', 'rewrite'],
|
|
2003
|
-
['regenerate', 'regen'],
|
|
2004
|
-
['render', 'parse'],
|
|
2005
|
-
['reply', 'response'],
|
|
2006
|
-
['sentiment', 'attitude', 'emotion', 'feeling', 'opinion', 'perception'],
|
|
2007
|
-
['speak', 'say', 'speech', 'talk', 'tts'],
|
|
2008
|
-
['summarize', 'tldr'],
|
|
2009
|
-
['unminify', 'beautify', 'prettify', 'prettyPrint']
|
|
2010
|
-
];
|
|
2011
|
-
const camelCaser = (words) => {
|
|
2012
|
-
return words.map((word, index) => index === 0 || word == 's' ? word : word.charAt(0).toUpperCase() + word.slice(1)).join(''); };
|
|
2013
|
-
for (const prop in chatgpt) {
|
|
2014
|
-
|
|
2015
|
-
// Create new function for each alias
|
|
2016
|
-
for (const subAliases of functionAliases) {
|
|
2017
|
-
if (subAliases.includes(prop)) {
|
|
2018
|
-
if (subAliases.some(element => element.includes('.'))) {
|
|
2019
|
-
const nestedFunction = subAliases.find(element => element.includes('.')).split('.')[1];
|
|
2020
|
-
for (const nestAlias of subAliases) {
|
|
2021
|
-
if (/^(\w+)/.exec(nestAlias)[1] !== prop) { // don't alias og function
|
|
2022
|
-
chatgpt[nestAlias] = chatgpt[prop][nestedFunction]; // make new function, reference og one
|
|
2023
|
-
}}} else { // alias direct functions
|
|
2024
|
-
for (const dirAlias of subAliases) {
|
|
2025
|
-
if (dirAlias !== prop) { // don't alias og function
|
|
2026
|
-
chatgpt[dirAlias] = chatgpt[prop]; // make new function, reference og one
|
|
2027
|
-
}}}
|
|
2028
|
-
}}
|
|
2029
|
-
|
|
2030
|
-
do { // create new function per synonym per word per function
|
|
2031
|
-
var newFunctionsCreated = false;
|
|
2032
|
-
for (const funcName in chatgpt) {
|
|
2033
|
-
if (typeof chatgpt[funcName] == 'function') {
|
|
2034
|
-
const funcWords = funcName.split(/(?=[A-Zs])/); // split function name into constituent words
|
|
2035
|
-
for (const funcWord of funcWords) {
|
|
2036
|
-
const synonymValues = [].concat(...synonyms // flatten into single array w/ word's synonyms
|
|
2037
|
-
.filter(arr => arr.includes(funcWord.toLowerCase())) // filter in relevant synonym sub-arrays
|
|
2038
|
-
.map(arr => arr.filter(synonym => synonym !== funcWord.toLowerCase()))); // filter out matching word
|
|
2039
|
-
for (const synonym of synonymValues) { // create function per synonym
|
|
2040
|
-
const newFuncName = camelCaser(funcWords.map(word => (word == funcWord ? synonym : word)));
|
|
2041
|
-
if (!chatgpt[newFuncName]) { // don't alias existing functions
|
|
2042
|
-
chatgpt[newFuncName] = chatgpt[funcName]; // make new function, reference og one
|
|
2043
|
-
newFunctionsCreated = true;
|
|
2044
|
-
}}}}}} while (newFunctionsCreated); // loop over new functions to encompass all variations
|
|
2045
|
-
}
|
|
2046
|
-
|
|
2047
|
-
// Prefix console logs w/ '🤖 chatgpt.js >> '
|
|
2048
|
-
const consolePrefix = '🤖 chatgpt.js >> ', ogError = console.error, ogInfo = console.info;
|
|
2049
|
-
console.error = (...args) => {
|
|
2050
|
-
if (!args[0].startsWith(consolePrefix)) ogError(consolePrefix + args[0], ...args.slice(1));
|
|
2051
|
-
else ogError(...args);
|
|
2052
|
-
};
|
|
2053
|
-
console.info = (msg) => {
|
|
2054
|
-
if (!msg.startsWith(consolePrefix)) ogInfo(consolePrefix + msg);
|
|
2055
|
-
else ogInfo(msg);
|
|
2056
|
-
};
|
|
2057
|
-
|
|
2058
|
-
// Export chatgpt object
|
|
2059
|
-
try { window.chatgpt = chatgpt; } catch (err) {} // for Greasemonkey
|
|
2060
|
-
try { module.exports = chatgpt; } catch (err) {} // for CommonJS
|
|
1
|
+
// © 2023–2024 KudoAI & contributors under the MIT license.
|
|
2
|
+
// Source: https://github.com/KudoAI/chatgpt.js
|
|
3
|
+
// User guide: https://chatgptjs.org/userguide
|
|
4
|
+
// Latest minified release: https://cdn.jsdelivr.net/npm/@kudoai/chatgpt.js/chatgpt.min.js
|
|
5
|
+
|
|
6
|
+
// Init endpoints
|
|
7
|
+
const endpoints = {
|
|
8
|
+
assets: 'https://raw.githubusercontent.com/KudoAI/chatgpt.js/main',
|
|
9
|
+
openAI: {
|
|
10
|
+
session: 'https://chat.openai.com/api/auth/session',
|
|
11
|
+
chats: 'https://chat.openai.com/backend-api/conversations',
|
|
12
|
+
chat: 'https://chat.openai.com/backend-api/conversation',
|
|
13
|
+
share_create: 'https://chat.openai.com/backend-api/share/create',
|
|
14
|
+
share: 'https://chat.openai.com/backend-api/share',
|
|
15
|
+
instructions: 'https://chat.openai.com/backend-api/user_system_messages'
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
// Init feedback properties
|
|
20
|
+
localStorage.alertQueue = JSON.stringify([]);
|
|
21
|
+
localStorage.notifyProps = JSON.stringify({
|
|
22
|
+
queue: { topRight: [], bottomRight: [], bottomLeft: [], topLeft: [] },
|
|
23
|
+
lastNthAudio: 0 // to prevent immediate repetition of base sound
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
// Init environment flags
|
|
27
|
+
const isFFuserScript = navigator.userAgent.includes('Firefox') && typeof unsafeWindow != 'undefined',
|
|
28
|
+
isFFtmScript = isFFuserScript && GM_info.scriptHandler == 'Tampermonkey';
|
|
29
|
+
|
|
30
|
+
// Define chatgpt.methods
|
|
31
|
+
const chatgpt = { // eslint-disable-line no-redeclare
|
|
32
|
+
openAIaccessToken: {},
|
|
33
|
+
|
|
34
|
+
actAs: function(persona) {
|
|
35
|
+
// Prompts ChatGPT to act as a persona from https://github.com/KudoAI/chat-prompts/blob/main/personas.json
|
|
36
|
+
|
|
37
|
+
const promptsUrl = 'https://raw.githubusercontent.com/KudoAI/chat-prompts/main/dist/personas.min.json';
|
|
38
|
+
return new Promise((resolve, reject) => {
|
|
39
|
+
const xhr = new XMLHttpRequest();
|
|
40
|
+
xhr.open('GET', promptsUrl, true); xhr.send();
|
|
41
|
+
xhr.onload = () => {
|
|
42
|
+
if (xhr.status !== 200) return reject('🤖 chatgpt.js >> Request failed. Cannot retrieve prompts data.');
|
|
43
|
+
const data = JSON.parse(xhr.responseText).personas;
|
|
44
|
+
if (!persona) {
|
|
45
|
+
console.log('\n%c🤖 chatgpt.js personas\n',
|
|
46
|
+
'font-family: sans-serif ; font-size: xxx-large ; font-weight: bold');
|
|
47
|
+
for (const prompt of data) // list personas
|
|
48
|
+
console.log(`%c${ prompt.title }`, 'font-family: monospace ; font-size: larger ;');
|
|
49
|
+
return resolve();
|
|
50
|
+
}
|
|
51
|
+
const selectedPrompt = data.find(obj => obj.title.toLowerCase() == persona.toLowerCase());
|
|
52
|
+
if (!selectedPrompt)
|
|
53
|
+
return reject(`🤖 chatgpt.js >> Persona '${ persona }' was not found!`);
|
|
54
|
+
chatgpt.send(selectedPrompt.prompt, 'click');
|
|
55
|
+
console.info(`Loading ${ persona } persona...`);
|
|
56
|
+
chatgpt.isIdle().then(() => { console.info('Persona activated!'); });
|
|
57
|
+
return resolve();
|
|
58
|
+
};
|
|
59
|
+
});
|
|
60
|
+
},
|
|
61
|
+
|
|
62
|
+
activateDarkMode: function() {
|
|
63
|
+
document.documentElement.classList.replace('light', 'dark');
|
|
64
|
+
document.documentElement.style.colorScheme = 'dark';
|
|
65
|
+
localStorage.setItem('theme', 'dark');
|
|
66
|
+
},
|
|
67
|
+
|
|
68
|
+
activateLightMode: function() {
|
|
69
|
+
document.documentElement.classList.replace('dark', 'light');
|
|
70
|
+
document.documentElement.style.colorScheme = 'light';
|
|
71
|
+
localStorage.setItem('theme', 'light');
|
|
72
|
+
},
|
|
73
|
+
|
|
74
|
+
alert: function(title, msg, btns, checkbox, width) {
|
|
75
|
+
// [ title/msg = strings, btns = [named functions], checkbox = named function, width (px) = int ] = optional
|
|
76
|
+
// * Spaces are inserted into button labels by parsing function names in camel/kebab/snake case
|
|
77
|
+
|
|
78
|
+
const scheme = chatgpt.isDarkMode() ? 'dark' : 'light',
|
|
79
|
+
isMobile = chatgpt.browser.isMobile();
|
|
80
|
+
|
|
81
|
+
// Create modal parent/children elements
|
|
82
|
+
const modalContainer = document.createElement('div');
|
|
83
|
+
modalContainer.id = Math.floor(chatgpt.randomFloat() * 1000000) + Date.now();
|
|
84
|
+
modalContainer.classList.add('chatgpt-modal'); // add class to main div
|
|
85
|
+
const modal = document.createElement('div'),
|
|
86
|
+
modalTitle = document.createElement('h2'),
|
|
87
|
+
modalMessage = document.createElement('p');
|
|
88
|
+
|
|
89
|
+
// Create/append/update modal style (if missing or outdated)
|
|
90
|
+
const thisUpdated = 20231203; // datestamp of last edit for this file's `modalStyle`
|
|
91
|
+
let modalStyle = document.querySelector('#chatgpt-modal-style'); // try to select existing style
|
|
92
|
+
if (!modalStyle || parseInt(modalStyle.getAttribute('last-updated'), 10) < thisUpdated) { // if missing or outdated
|
|
93
|
+
if (!modalStyle) { // outright missing, create/id/attr/append it first
|
|
94
|
+
modalStyle = document.createElement('style'); modalStyle.id = 'chatgpt-modal-style';
|
|
95
|
+
modalStyle.setAttribute('last-updated', thisUpdated.toString());
|
|
96
|
+
document.head.append(modalStyle);
|
|
97
|
+
}
|
|
98
|
+
modalStyle.innerText = ( // update prev/new style contents
|
|
99
|
+
|
|
100
|
+
// Background styles
|
|
101
|
+
'.chatgpt-modal {'
|
|
102
|
+
+ 'position: fixed ; top: 0 ; left: 0 ; width: 100% ; height: 100% ;' // expand to full view-port
|
|
103
|
+
+ 'background-color: rgba(67, 70, 72, 0) ;' // init dim bg but no opacity
|
|
104
|
+
+ 'transition: background-color 0.05s ease ;' // speed to transition in show alert routine
|
|
105
|
+
+ 'display: flex ; justify-content: center ; align-items: center ; z-index: 9999 }' // align
|
|
106
|
+
|
|
107
|
+
// Alert styles
|
|
108
|
+
+ '.chatgpt-modal > div {'
|
|
109
|
+
+ 'opacity: 0 ; transform: translateX(-2px) translateY(5px) ; max-width: 75vw ; word-wrap: break-word ;'
|
|
110
|
+
+ 'transition: opacity 0.1s cubic-bezier(.165,.84,.44,1), transform 0.2s cubic-bezier(.165,.84,.44,1) ;'
|
|
111
|
+
+ `background-color: ${ scheme == 'dark' ? 'black' : 'white' } ;`
|
|
112
|
+
+ ( scheme != 'dark' ? 'border: 1px solid rgba(0, 0, 0, 0.3) ;' : '' )
|
|
113
|
+
+ 'padding: 20px ; margin: 12px 23px ; border-radius: 15px ; box-shadow: 0 30px 60px rgba(0, 0, 0, .12) ;'
|
|
114
|
+
+ ' -webkit-user-select: none ; -moz-user-select: none ; -ms-user-select: none ; user-select: none ; }'
|
|
115
|
+
+ '.chatgpt-modal h2 { margin-bottom: 9px }'
|
|
116
|
+
+ `.chatgpt-modal a { color: ${ scheme == 'dark' ? '#00cfff' : '#1e9ebb' }}`
|
|
117
|
+
+ '.chatgpt-modal.animated > div { opacity: 1 ; transform: translateX(0) translateY(0) }'
|
|
118
|
+
+ '@keyframes alert-zoom-fade-out { 0% { opacity: 1 ; transform: scale(1) }'
|
|
119
|
+
+ '50% { opacity: 0.25 ; transform: scale(1.05) }'
|
|
120
|
+
+ '100% { opacity: 0 ; transform: scale(1.35) }}'
|
|
121
|
+
|
|
122
|
+
// Button styles
|
|
123
|
+
+ '.modal-buttons { display: flex ; justify-content: flex-end ; margin: 20px -5px -3px 0 ;'
|
|
124
|
+
+ ( isMobile ? 'flex-direction: column-reverse' : '' ) + '}'
|
|
125
|
+
+ '.chatgpt-modal button {'
|
|
126
|
+
+ `margin-left: ${ isMobile ? 0 : 10}px ; padding: ${ isMobile ? 15 : 4}px 18px ; border-radius: 15px ;`
|
|
127
|
+
+ ( isMobile ? 'margin-top: 5px ; margin-bottom: 3px ;' : '')
|
|
128
|
+
+ `border: 1px solid ${ scheme == 'dark' ? 'white' : 'black' }}`
|
|
129
|
+
+ '.primary-modal-btn {'
|
|
130
|
+
+ `border: 1px solid ${ scheme == 'dark' ? 'white' : 'black' } ;`
|
|
131
|
+
+ `background: ${ scheme == 'dark' ? 'white' : 'black' } ;`
|
|
132
|
+
+ `color: ${ scheme == 'dark' ? 'black' : 'white' }}`
|
|
133
|
+
+ '.chatgpt-modal button:hover { color: #3d5d71 ; border-color: #6d9cb9 ;'
|
|
134
|
+
+ 'background-color: ' + ( scheme == 'dark' ? '#00cfff' : '#9cdaff' ) + ';'
|
|
135
|
+
+ 'box-shadow: 2px 1px ' + ( scheme == 'dark' ? '54px #00cfff' : '30px #9cdaff' ) + '}'
|
|
136
|
+
+ '.modal-close-btn {'
|
|
137
|
+
+ 'cursor: pointer ; width: 20px ; height: 20px ; float: right ; position: relative ; right: -2px }'
|
|
138
|
+
+ '.modal-close-btn svg { margin: 5px 5px }' // center SVG for hover overlay
|
|
139
|
+
+ `.modal-close-btn:hover { background-color: #f2f2f2${ scheme == 'dark' ? '00' : '' }}`
|
|
140
|
+
|
|
141
|
+
// Checkbox styles
|
|
142
|
+
+ '.chatgpt-modal .checkbox-group { display: flex ; margin-top: -18px }'
|
|
143
|
+
+ '.chatgpt-modal .checkbox-group label {'
|
|
144
|
+
+ 'font-size: .7rem ; margin: -.04rem 0 0px .3rem ;'
|
|
145
|
+
+ `color: ${ scheme == 'dark' ? '#e1e1e1' : '#1e1e1e' }}`
|
|
146
|
+
+ '.chatgpt-modal input[type="checkbox"] { transform: scale(0.7) ;'
|
|
147
|
+
+ `border: 1px solid ${ scheme == 'dark' ? 'white' : 'black' }}`
|
|
148
|
+
+ '.chatgpt-modal input[type="checkbox"]:checked {'
|
|
149
|
+
+ `border: 1px solid ${ scheme == 'dark' ? 'white' : 'black' } ;`
|
|
150
|
+
+ 'background-color: black ; position: inherit }'
|
|
151
|
+
+ '.chatgpt-modal input[type="checkbox"]:focus { outline: none ; box-shadow: none }'
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Insert text into elements
|
|
156
|
+
modalTitle.innerText = title || '';
|
|
157
|
+
modalMessage.innerText = msg || ''; this.renderHTML(modalMessage);
|
|
158
|
+
|
|
159
|
+
// Create/append buttons (if provided) to buttons div
|
|
160
|
+
const modalButtons = document.createElement('div');
|
|
161
|
+
modalButtons.classList.add('modal-buttons');
|
|
162
|
+
if (btns) { // are supplied
|
|
163
|
+
if (!Array.isArray(btns)) btns = [btns]; // convert single button to array if necessary
|
|
164
|
+
btns.forEach((buttonFn) => { // create title-cased labels + attach listeners
|
|
165
|
+
const button = document.createElement('button');
|
|
166
|
+
button.textContent = buttonFn.name
|
|
167
|
+
.replace(/[_-]\w/g, match => match.slice(1).toUpperCase()) // convert snake/kebab to camel case
|
|
168
|
+
.replace(/([A-Z])/g, ' $1') // insert spaces
|
|
169
|
+
.replace(/^\w/, firstChar => firstChar.toUpperCase()); // capitalize first letter
|
|
170
|
+
button.addEventListener('click', () => { dismissAlert(); buttonFn(); });
|
|
171
|
+
modalButtons.insertBefore(button, modalButtons.firstChild); // insert button to left
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// Create/append OK/dismiss button to buttons div
|
|
176
|
+
const dismissBtn = document.createElement('button');
|
|
177
|
+
dismissBtn.textContent = btns ? 'Dismiss' : 'OK';
|
|
178
|
+
modalButtons.insertBefore(dismissBtn, modalButtons.firstChild);
|
|
179
|
+
|
|
180
|
+
// Highlight primary button
|
|
181
|
+
modalButtons.lastChild.classList.add('primary-modal-btn');
|
|
182
|
+
|
|
183
|
+
// Create/append checkbox (if provided) to checkbox group div
|
|
184
|
+
const checkboxDiv = document.createElement('div');
|
|
185
|
+
if (checkbox) { // is supplied
|
|
186
|
+
checkboxDiv.classList.add('checkbox-group');
|
|
187
|
+
const checkboxFn = checkbox, // assign the named function to checkboxFn
|
|
188
|
+
checkboxInput = document.createElement('input');
|
|
189
|
+
checkboxInput.type = 'checkbox';
|
|
190
|
+
checkboxInput.addEventListener('change', checkboxFn);
|
|
191
|
+
|
|
192
|
+
// Create/show label
|
|
193
|
+
const checkboxLabel = document.createElement('label');
|
|
194
|
+
checkboxLabel.addEventListener('click', () => {
|
|
195
|
+
checkboxInput.checked = !checkboxInput.checked; checkboxFn(); });
|
|
196
|
+
checkboxLabel.textContent = checkboxFn.name.charAt(0).toUpperCase() // capitalize first char
|
|
197
|
+
+ checkboxFn.name.slice(1) // format remaining chars
|
|
198
|
+
.replace(/([A-Z])/g, (match, letter) => ' ' + letter.toLowerCase()) // insert spaces, convert to lowercase
|
|
199
|
+
.replace(/\b(\w+)nt\b/gi, '$1n\'t') // insert apostrophe in 'nt' suffixes
|
|
200
|
+
.trim(); // trim leading/trailing spaces
|
|
201
|
+
|
|
202
|
+
checkboxDiv.append(checkboxInput); checkboxDiv.append(checkboxLabel);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// Create close button
|
|
206
|
+
const closeBtn = document.createElement('div');
|
|
207
|
+
closeBtn.title = 'Close'; closeBtn.classList.add('modal-close-btn');
|
|
208
|
+
const closeSVG = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
|
|
209
|
+
closeSVG.setAttribute('height', '10px');
|
|
210
|
+
closeSVG.setAttribute('viewBox', '0 0 14 14');
|
|
211
|
+
closeSVG.setAttribute('fill', 'none');
|
|
212
|
+
const closeSVGpath = document.createElementNS('http://www.w3.org/2000/svg', 'path');
|
|
213
|
+
closeSVGpath.setAttribute('fill-rule', 'evenodd');
|
|
214
|
+
closeSVGpath.setAttribute('clip-rule', 'evenodd');
|
|
215
|
+
closeSVGpath.setAttribute('fill', chatgpt.isDarkMode() ? 'white' : 'black');
|
|
216
|
+
closeSVGpath.setAttribute('d', 'M13.7071 1.70711C14.0976 1.31658 14.0976 0.683417 13.7071 0.292893C13.3166 -0.0976312 12.6834 -0.0976312 12.2929 0.292893L7 5.58579L1.70711 0.292893C1.31658 -0.0976312 0.683417 -0.0976312 0.292893 0.292893C-0.0976312 0.683417 -0.0976312 1.31658 0.292893 1.70711L5.58579 7L0.292893 12.2929C-0.0976312 12.6834 -0.0976312 13.3166 0.292893 13.7071C0.683417 14.0976 1.31658 14.0976 1.70711 13.7071L7 8.41421L12.2929 13.7071C12.6834 14.0976 13.3166 14.0976 13.7071 13.7071C14.0976 13.3166 14.0976 12.6834 13.7071 12.2929L8.41421 7L13.7071 1.70711Z');
|
|
217
|
+
closeSVG.append(closeSVGpath); closeBtn.append(closeSVG);
|
|
218
|
+
|
|
219
|
+
// Assemble/append div
|
|
220
|
+
const modalElems = [closeBtn, modalTitle, modalMessage, modalButtons, checkboxDiv];
|
|
221
|
+
modalElems.forEach((elem) => { modal.append(elem); });
|
|
222
|
+
modal.style.width = `${ width || 458 }px`;
|
|
223
|
+
modalContainer.append(modal); document.body.append(modalContainer);
|
|
224
|
+
|
|
225
|
+
// Enqueue alert
|
|
226
|
+
let alertQueue = JSON.parse(localStorage.alertQueue);
|
|
227
|
+
alertQueue.push(modalContainer.id);
|
|
228
|
+
localStorage.alertQueue = JSON.stringify(alertQueue);
|
|
229
|
+
|
|
230
|
+
// Show alert if none active
|
|
231
|
+
modalContainer.style.display = 'none';
|
|
232
|
+
if (alertQueue.length === 1) {
|
|
233
|
+
modalContainer.style.display = '';
|
|
234
|
+
setTimeout(() => { // delay non-0 opacity's for transition fx
|
|
235
|
+
modalContainer.style.backgroundColor = (
|
|
236
|
+
`rgba(67, 70, 72, ${ scheme === 'dark' ? 0.62 : 0 })`);
|
|
237
|
+
modalContainer.classList.add('animated'); }, 100);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// Define click/key handlers
|
|
241
|
+
const clickHandler = event => { // explicitly defined to support removal post-dismissal
|
|
242
|
+
if (event.target == event.currentTarget || event.target instanceof SVGPathElement) dismissAlert(); };
|
|
243
|
+
const keyHandler = event => { // to dismiss active alert
|
|
244
|
+
const dismissKeys = [13, 27]; // enter/esc
|
|
245
|
+
if (dismissKeys.includes(event.keyCode)) {
|
|
246
|
+
for (const alertId of alertQueue) { // look to handle only if triggering alert is active
|
|
247
|
+
const alert = document.getElementById(alertId);
|
|
248
|
+
if (alert && alert.style.display !== 'none') { // active alert found
|
|
249
|
+
if (event.keyCode === 27) dismissAlert(); // if esc pressed, dismiss alert & do nothing
|
|
250
|
+
else if (event.keyCode === 13) { // else if enter pressed
|
|
251
|
+
const mainButton = alert.querySelector('.modal-buttons').lastChild; // look for main button
|
|
252
|
+
if (mainButton) { mainButton.click(); event.preventDefault(); } // click if found
|
|
253
|
+
} return;
|
|
254
|
+
}}}};
|
|
255
|
+
|
|
256
|
+
// Add listeners to dismiss alert
|
|
257
|
+
const dismissElems = [modalContainer, closeBtn, closeSVG, dismissBtn];
|
|
258
|
+
dismissElems.forEach(elem => {
|
|
259
|
+
elem.addEventListener('click', clickHandler); });
|
|
260
|
+
document.addEventListener('keydown', keyHandler);
|
|
261
|
+
|
|
262
|
+
// Define alert dismisser
|
|
263
|
+
const dismissAlert = () => {
|
|
264
|
+
modalContainer.style.backgroundColor = 'transparent';
|
|
265
|
+
modal.style.animation = 'alert-zoom-fade-out 0.075s ease-out';
|
|
266
|
+
setTimeout(() => { // delay removal for fade-out
|
|
267
|
+
|
|
268
|
+
// Remove alert
|
|
269
|
+
modalContainer.remove(); // ...from DOM
|
|
270
|
+
alertQueue = JSON.parse(localStorage.alertQueue);
|
|
271
|
+
alertQueue.shift(); // + memory
|
|
272
|
+
localStorage.alertQueue = JSON.stringify(alertQueue); // + storage
|
|
273
|
+
|
|
274
|
+
// Remove all listeners to prevent memory leaks
|
|
275
|
+
dismissElems.forEach(elem => { elem.removeEventListener('click', clickHandler); });
|
|
276
|
+
document.removeEventListener('keydown', keyHandler);
|
|
277
|
+
|
|
278
|
+
// Check for pending alerts in queue
|
|
279
|
+
if (alertQueue.length > 0) {
|
|
280
|
+
const nextAlert = document.getElementById(alertQueue[0]);
|
|
281
|
+
setTimeout(() => {
|
|
282
|
+
nextAlert.style.display = '';
|
|
283
|
+
setTimeout(() => { nextAlert.classList.add('animated'); }, 100);
|
|
284
|
+
}, 500);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
}, 50);
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
return modalContainer.id; // if assignment used
|
|
291
|
+
},
|
|
292
|
+
|
|
293
|
+
askAndGetReply: async function(query) {
|
|
294
|
+
chatgpt.send(query); await chatgpt.isIdle();
|
|
295
|
+
return chatgpt.getChatData('active', 'msg', 'chatgpt', 'latest');
|
|
296
|
+
},
|
|
297
|
+
|
|
298
|
+
autoRefresh: {
|
|
299
|
+
activate: function(interval) {
|
|
300
|
+
if (this.isActive) { // already running, do nothing
|
|
301
|
+
console.log('↻ ChatGPT >> [' + chatgpt.autoRefresh.nowTimeStamp() + '] Auto refresh already active!'); return; }
|
|
302
|
+
|
|
303
|
+
const autoRefresh = this;
|
|
304
|
+
|
|
305
|
+
// Run main activate routine
|
|
306
|
+
this.toggle.refreshFrame();
|
|
307
|
+
const scheduleRefreshes = interval => {
|
|
308
|
+
const randomDelay = Math.max(2, Math.floor(chatgpt.randomFloat() * 21 - 10)); // set random delay up to ±10 secs
|
|
309
|
+
autoRefresh.isActive = setTimeout(() => {
|
|
310
|
+
const manifestScript = document.querySelector('script[src*="_ssgManifest.js"]');
|
|
311
|
+
document.querySelector('#refresh-frame').src = manifestScript.src + '?' + Date.now();
|
|
312
|
+
console.log('↻ ChatGPT >> [' + autoRefresh.nowTimeStamp() + '] ChatGPT session refreshed');
|
|
313
|
+
scheduleRefreshes(interval);
|
|
314
|
+
}, (interval + randomDelay) * 1000);
|
|
315
|
+
};
|
|
316
|
+
scheduleRefreshes( interval ? parseInt(interval, 10) : 30 );
|
|
317
|
+
console.log('↻ ChatGPT >> [' + chatgpt.autoRefresh.nowTimeStamp() + '] Auto refresh activated');
|
|
318
|
+
|
|
319
|
+
// Add listener to send beacons in Chromium to thwart auto-discards if Page Visibility API supported
|
|
320
|
+
if (navigator.userAgent.includes('Chrome') && typeof document.hidden !== 'undefined') {
|
|
321
|
+
document.addEventListener('visibilitychange', this.toggle.beacons); }
|
|
322
|
+
},
|
|
323
|
+
|
|
324
|
+
deactivate: function() {
|
|
325
|
+
if (this.isActive) {
|
|
326
|
+
this.toggle.refreshFrame();
|
|
327
|
+
document.removeEventListener('visibilitychange', this.toggle.beacons);
|
|
328
|
+
clearTimeout(this.isActive); this.isActive = null;
|
|
329
|
+
console.log('↻ ChatGPT >> [' + chatgpt.autoRefresh.nowTimeStamp() + '] Auto refresh de-activated');
|
|
330
|
+
} else { console.log('↻ ChatGPT >> [' + chatgpt.autoRefresh.nowTimeStamp() + '] Auto refresh already inactive!'); }
|
|
331
|
+
},
|
|
332
|
+
|
|
333
|
+
nowTimeStamp: function() {
|
|
334
|
+
const now = new Date();
|
|
335
|
+
const hours = now.getHours() % 12 || 12; // Convert to 12-hour format
|
|
336
|
+
let minutes = now.getMinutes(), seconds = now.getSeconds();
|
|
337
|
+
if (minutes < 10) minutes = '0' + minutes; if (seconds < 10) seconds = '0' + seconds;
|
|
338
|
+
const meridiem = now.getHours() < 12 ? 'AM' : 'PM';
|
|
339
|
+
return hours + ':' + minutes + ':' + seconds + ' ' + meridiem;
|
|
340
|
+
},
|
|
341
|
+
|
|
342
|
+
toggle: {
|
|
343
|
+
|
|
344
|
+
beacons: function() {
|
|
345
|
+
if (chatgpt.autoRefresh.beaconID) {
|
|
346
|
+
clearInterval(chatgpt.autoRefresh.beaconID); chatgpt.autoRefresh.beaconID = null;
|
|
347
|
+
console.log('↻ ChatGPT >> [' + chatgpt.autoRefresh.nowTimeStamp() + '] Beacons de-activated');
|
|
348
|
+
} else {
|
|
349
|
+
chatgpt.autoRefresh.beaconID = setInterval(() => {
|
|
350
|
+
navigator.sendBeacon('https://httpbin.org/post', new Uint8Array());
|
|
351
|
+
console.log('↻ ChatGPT >> [' + chatgpt.autoRefresh.nowTimeStamp() + '] Beacon sent');
|
|
352
|
+
}, 90000);
|
|
353
|
+
console.log('↻ ChatGPT >> [' + chatgpt.autoRefresh.nowTimeStamp() + '] Beacons activated');
|
|
354
|
+
}
|
|
355
|
+
},
|
|
356
|
+
|
|
357
|
+
refreshFrame: function() {
|
|
358
|
+
let refreshFrame = document.querySelector('#refresh-frame');
|
|
359
|
+
if (refreshFrame) refreshFrame.remove();
|
|
360
|
+
else {
|
|
361
|
+
refreshFrame = Object.assign(document.createElement('iframe'),
|
|
362
|
+
{ id: 'refresh-frame', style: 'display: none' });
|
|
363
|
+
document.head.prepend(refreshFrame);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
},
|
|
368
|
+
|
|
369
|
+
browser: {
|
|
370
|
+
|
|
371
|
+
isLightMode: function() { return window.matchMedia?.('(prefers-color-scheme: light)')?.matches; },
|
|
372
|
+
isDarkMode: function() { return window.matchMedia?.('(prefers-color-scheme: dark)')?.matches; },
|
|
373
|
+
isChromium: function() { return navigator.userAgent.includes('Chrome'); },
|
|
374
|
+
isFirefox: function() { return navigator.userAgent.includes('Firefox'); },
|
|
375
|
+
|
|
376
|
+
isFullScreen: function() {
|
|
377
|
+
const userAgentStr = navigator.userAgent;
|
|
378
|
+
return userAgentStr.includes('Chrome') ? window.matchMedia('(display-mode: fullscreen)').matches
|
|
379
|
+
: userAgentStr.includes('Firefox') ? window.fullScreen
|
|
380
|
+
: /MSIE|rv:/.test(userAgentStr) ? document.msFullscreenElement : document.webkitIsFullScreen;
|
|
381
|
+
},
|
|
382
|
+
|
|
383
|
+
isMobile: function() {
|
|
384
|
+
return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent); }
|
|
385
|
+
},
|
|
386
|
+
|
|
387
|
+
clearChats: async function(method) {
|
|
388
|
+
|
|
389
|
+
// Validate method arg
|
|
390
|
+
const validMethods = ['api', 'dom'];
|
|
391
|
+
method = (method || 'dom').trim().toLowerCase(); // set to 'dom' by default
|
|
392
|
+
if (method && !validMethods.includes(method))
|
|
393
|
+
return console.log(`Method argument must be one of: [${ validMethods }]`);
|
|
394
|
+
|
|
395
|
+
if (method == 'dom') {
|
|
396
|
+
try { await chatgpt.getChatData(); } catch { return; } // check if chat history exists
|
|
397
|
+
chatgpt.menu.open(); setTimeout(() => { // open settings
|
|
398
|
+
const settingsBtn = document.querySelector(
|
|
399
|
+
'a[role="menuitem"] svg path[d*="M11.6439 3C10.9352"]').parentNode.parentNode;
|
|
400
|
+
if (settingsBtn) settingsBtn.click();
|
|
401
|
+
setTimeout(() => { // clear chats
|
|
402
|
+
const settingsBtns = document.querySelectorAll('[id*=radix] button'),
|
|
403
|
+
deleteBtn = settingsBtns[settingsBtns.length - 1];
|
|
404
|
+
if (deleteBtn) deleteBtn.click();
|
|
405
|
+
setTimeout(() => { // confirm clear
|
|
406
|
+
document.querySelector('button[class*="danger"').click();
|
|
407
|
+
}, 10); }, 333); }, 10);
|
|
408
|
+
|
|
409
|
+
} else { // API method
|
|
410
|
+
// NOTE: DOM is not updated to reflect new empty chat list (until session refresh)
|
|
411
|
+
|
|
412
|
+
return new Promise((resolve, reject) => {
|
|
413
|
+
chatgpt.getAccessToken().then(token => {
|
|
414
|
+
const xhr = new XMLHttpRequest();
|
|
415
|
+
xhr.open('PATCH', endpoints.openAI.chats, true);
|
|
416
|
+
xhr.setRequestHeader('Content-Type', 'application/json');
|
|
417
|
+
xhr.setRequestHeader('Authorization', 'Bearer ' + token);
|
|
418
|
+
xhr.onload = () => {
|
|
419
|
+
if (xhr.status !== 200) return reject('🤖 chatgpt.js >> Request failed. Cannot clear chats.');
|
|
420
|
+
console.info('Chats successfully cleared'); resolve();
|
|
421
|
+
};
|
|
422
|
+
xhr.send(JSON.stringify({ is_visible: false }));
|
|
423
|
+
}).catch(reject);
|
|
424
|
+
});
|
|
425
|
+
}
|
|
426
|
+
},
|
|
427
|
+
|
|
428
|
+
code: {
|
|
429
|
+
// Tip: Use template literals for easier passing of code arguments. Ensure backticks and `$`s are escaped (using `\`)
|
|
430
|
+
|
|
431
|
+
execute: async function(code) {
|
|
432
|
+
if (!code) return console.error('Code argument not supplied. Pass some code!');
|
|
433
|
+
if (typeof code !== 'string') return console.error('Code argument must be a string!');
|
|
434
|
+
chatgpt.send('Display the output as if you were terminal:\n\n' + code);
|
|
435
|
+
console.info('Executing code...');
|
|
436
|
+
await chatgpt.isIdle();
|
|
437
|
+
return chatgpt.code.extract(await chatgpt.getChatData('active', 'msg', 'chatgpt', 'latest'));
|
|
438
|
+
},
|
|
439
|
+
|
|
440
|
+
extract: function(msg) { // extract pure code from response (targets last block)
|
|
441
|
+
const codeBlocks = msg.match(/(?<=```.*\n)[\s\S]*?(?=```)/g);
|
|
442
|
+
return codeBlocks ? codeBlocks[codeBlocks.length - 1] : msg;
|
|
443
|
+
},
|
|
444
|
+
|
|
445
|
+
minify: async function(code) {
|
|
446
|
+
if (!code) return console.error('Code argument not supplied. Pass some code!');
|
|
447
|
+
if (typeof code !== 'string') return console.error('Code argument must be a string!');
|
|
448
|
+
chatgpt.send('Minify the following code:\n\n' + code);
|
|
449
|
+
console.info('Minifying code...');
|
|
450
|
+
await chatgpt.isIdle();
|
|
451
|
+
return chatgpt.code.extract(await chatgpt.getChatData('active', 'msg', 'chatgpt', 'latest'));
|
|
452
|
+
},
|
|
453
|
+
|
|
454
|
+
obfuscate: async function(code) {
|
|
455
|
+
if (!code) return console.error('Code argument not supplied. Pass some code!');
|
|
456
|
+
if (typeof code !== 'string') return console.error('Code argument must be a string!');
|
|
457
|
+
chatgpt.send('Obfuscate the following code:\n\n' + code);
|
|
458
|
+
console.info('Obfuscating code...');
|
|
459
|
+
await chatgpt.isIdle();
|
|
460
|
+
return chatgpt.code.extract(await chatgpt.getChatData('active', 'msg', 'chatgpt', 'latest'));
|
|
461
|
+
},
|
|
462
|
+
|
|
463
|
+
refactor: async function(code, objective) {
|
|
464
|
+
if (!code) return console.error('Code (1st) argument not supplied. Pass some code!');
|
|
465
|
+
for (let i = 0; i < arguments.length; i++) if (typeof arguments[i] !== 'string')
|
|
466
|
+
return console.error(`Argument ${ i + 1 } must be a string.`);
|
|
467
|
+
chatgpt.send('Refactor the following code for ' + (objective || 'brevity') + ':\n\n' + code);
|
|
468
|
+
console.info('Refactoring code...');
|
|
469
|
+
await chatgpt.isIdle();
|
|
470
|
+
return chatgpt.code.extract(await chatgpt.getChatData('active', 'msg', 'chatgpt', 'latest'));
|
|
471
|
+
},
|
|
472
|
+
|
|
473
|
+
review: async function(code) {
|
|
474
|
+
if (!code) return console.error('Code argument not supplied. Pass some code!');
|
|
475
|
+
if (typeof code !== 'string') return console.error('Code argument must be a string!');
|
|
476
|
+
chatgpt.send('Review the following code for me:\n\n' + code);
|
|
477
|
+
console.info('Reviewing code...');
|
|
478
|
+
await chatgpt.isIdle();
|
|
479
|
+
return chatgpt.getChatData('active', 'msg', 'chatgpt', 'latest');
|
|
480
|
+
},
|
|
481
|
+
|
|
482
|
+
unminify: async function(code) {
|
|
483
|
+
if (!code) return console.error('Code argument not supplied. Pass some code!');
|
|
484
|
+
if (typeof code !== 'string') return console.error('Code argument must be a string!');
|
|
485
|
+
chatgpt.send('Unminify the following code.:\n\n' + code);
|
|
486
|
+
console.info('Unminifying code...');
|
|
487
|
+
await chatgpt.isIdle();
|
|
488
|
+
return chatgpt.code.extract(await chatgpt.getChatData('active', 'msg', 'chatgpt', 'latest'));
|
|
489
|
+
},
|
|
490
|
+
|
|
491
|
+
write: async function(prompt, outputLang) {
|
|
492
|
+
if (!prompt) return console.error('Prompt (1st) argument not supplied. Pass a prompt!');
|
|
493
|
+
if (!outputLang) return console.error('outputLang (2nd) argument not supplied. Pass a language!');
|
|
494
|
+
for (let i = 0; i < arguments.length; i++) if (typeof arguments[i] !== 'string')
|
|
495
|
+
return console.error(`Argument ${ i + 1 } must be a string.`);
|
|
496
|
+
chatgpt.send(prompt + '\n\nWrite this as code in ' + outputLang);
|
|
497
|
+
console.info('Writing code...');
|
|
498
|
+
await chatgpt.isIdle();
|
|
499
|
+
return chatgpt.code.extract(await chatgpt.getChatData('active', 'msg', 'chatgpt', 'latest'));
|
|
500
|
+
}
|
|
501
|
+
},
|
|
502
|
+
|
|
503
|
+
detectLanguage: async function(text) {
|
|
504
|
+
if (!text) return console.error('Text argument not supplied. Pass some text!');
|
|
505
|
+
if (typeof text !== 'string') return console.error('Text argument must be a string!');
|
|
506
|
+
chatgpt.send('Detect the language of the following text:\n\n' + text
|
|
507
|
+
+ '\n\nOnly respond with the name of the language');
|
|
508
|
+
console.info('Reviewing text...');
|
|
509
|
+
await chatgpt.isIdle();
|
|
510
|
+
return chatgpt.getChatData('active', 'msg', 'chatgpt', 'latest');
|
|
511
|
+
},
|
|
512
|
+
|
|
513
|
+
executeCode: function() { chatgpt.code.execute(); },
|
|
514
|
+
|
|
515
|
+
exportChat: async function(chatToGet, format) {
|
|
516
|
+
// chatToGet = 'active' (default) | 'latest' | index|title|id of chat to get
|
|
517
|
+
// format = 'html' (default) | 'md' | 'pdf' | 'text'
|
|
518
|
+
|
|
519
|
+
// Init args
|
|
520
|
+
chatToGet = !chatToGet ? 'active' // default to 'active' if unpassed
|
|
521
|
+
: Number.isInteger(chatToGet) || /^\d+$/.test(chatToGet) ? // else if string/int num passed
|
|
522
|
+
parseInt(chatToGet, 10) // parse as integer
|
|
523
|
+
: chatToGet; // else preserve non-num string as 'active', 'latest' or title/id of chat to get
|
|
524
|
+
format = format.toLowerCase() || 'html'; // default to 'html' if unpassed
|
|
525
|
+
|
|
526
|
+
// Create transcript + filename
|
|
527
|
+
console.info('Generating transcript...');
|
|
528
|
+
let transcript = '', filename;
|
|
529
|
+
if (/te?xt/.test(format)) { // generate plain transcript + filename for TXT export
|
|
530
|
+
|
|
531
|
+
// Format filename using date/time
|
|
532
|
+
const now = new Date(),
|
|
533
|
+
day = now.getDate().toString().padStart(2, '0'),
|
|
534
|
+
month = (now.getMonth() + 1).toString().padStart(2, '0'),
|
|
535
|
+
year = now.getFullYear(),
|
|
536
|
+
hour = now.getHours().toString().padStart(2, '0'),
|
|
537
|
+
minute = now.getMinutes().toString().padStart(2, '0');
|
|
538
|
+
filename = `ChatGPT_${ day }-${ month }-${ year }_${ hour }-${ minute }.txt`;
|
|
539
|
+
|
|
540
|
+
// Create transcript from active chat
|
|
541
|
+
if (chatToGet == 'active' && /\/\w{8}-\w{4}-\w{4}-\w{4}-\w{12}$/.test(window.location.href)) {
|
|
542
|
+
const chatDivs = document.querySelectorAll('main > div > div > div > div > div > div[class*=group]');
|
|
543
|
+
if (chatDivs.length === 0) return console.error('Chat is empty!');
|
|
544
|
+
const msgs = []; let isUserMsg = true;
|
|
545
|
+
chatDivs.forEach((div) => {
|
|
546
|
+
const sender = isUserMsg ? 'USER' : 'CHATGPT'; isUserMsg = !isUserMsg;
|
|
547
|
+
let msg = Array.from(div.childNodes).map(node => node.innerText)
|
|
548
|
+
.join('\n\n') // insert double line breaks between paragraphs
|
|
549
|
+
.replace('Copy code', '');
|
|
550
|
+
msgs.push(sender + ': ' + msg);
|
|
551
|
+
});
|
|
552
|
+
transcript = msgs.join('\n\n');
|
|
553
|
+
|
|
554
|
+
// ...or from getChatData(chatToGet)
|
|
555
|
+
} else {
|
|
556
|
+
for (const entry of await chatgpt.getChatData(chatToGet, 'msg', 'both', 'all')) {
|
|
557
|
+
transcript += `USER: ${ entry.user }\n\n`;
|
|
558
|
+
transcript += `CHATGPT: ${ entry.chatgpt }\n\n`;
|
|
559
|
+
}}
|
|
560
|
+
|
|
561
|
+
} else { // generate rich transcript + filename for HTML/MD/PDF export
|
|
562
|
+
|
|
563
|
+
// Fetch HTML transcript from OpenAI
|
|
564
|
+
const response = await fetch(await chatgpt.shareChat(chatToGet)),
|
|
565
|
+
htmlContent = await response.text();
|
|
566
|
+
|
|
567
|
+
// Format filename after <title>
|
|
568
|
+
const parser = new DOMParser(),
|
|
569
|
+
parsedHtml = parser.parseFromString(htmlContent, 'text/html');
|
|
570
|
+
filename = parsedHtml.querySelector('title').textContent + '.html';
|
|
571
|
+
|
|
572
|
+
// Convert relative CSS paths to absolute ones
|
|
573
|
+
const cssLinks = parsedHtml.querySelectorAll('link[rel="stylesheet"]');
|
|
574
|
+
cssLinks.forEach(link => {
|
|
575
|
+
const href = link.getAttribute('href');
|
|
576
|
+
if (href?.startsWith('/')) link.setAttribute('href', 'https://chat.openai.com' + href);
|
|
577
|
+
});
|
|
578
|
+
|
|
579
|
+
// Serialize updated HTML to string
|
|
580
|
+
transcript = new XMLSerializer().serializeToString(parsedHtml);
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
// Export transcript
|
|
584
|
+
console.info(`Exporting transcript as ${ format.toUpperCase() }...`);
|
|
585
|
+
if (format == 'pdf') { // convert SVGs + launch PDF printer
|
|
586
|
+
|
|
587
|
+
// Convert SVG icons to data URLs for proper PDF rendering
|
|
588
|
+
transcript = transcript.replace(/<svg.*?<\/svg>/g, (match) => {
|
|
589
|
+
const dataURL = 'data:image/svg+xml,' + encodeURIComponent(match);
|
|
590
|
+
return `<img src="${ dataURL }">`;
|
|
591
|
+
});
|
|
592
|
+
|
|
593
|
+
// Launch PDF printer
|
|
594
|
+
const transcriptPopup = window.open('', '', 'toolbar=0, location=0, menubar=0, height=600, width=800');
|
|
595
|
+
transcriptPopup.document.write(transcript);
|
|
596
|
+
setTimeout(() => { transcriptPopup.print({ toPDF: true }); }, 100);
|
|
597
|
+
|
|
598
|
+
} else { // auto-save to file
|
|
599
|
+
|
|
600
|
+
if (format == 'md') { // remove extraneous HTML + fix file extension
|
|
601
|
+
const mdMatch = /<.*(?:<h1(.|\n)*?href=".*?continue[^"]*".*?\/a>.*?)<[^/]/.exec(transcript)[1];
|
|
602
|
+
transcript = mdMatch || transcript; filename = filename.replace('.html', '.md');
|
|
603
|
+
}
|
|
604
|
+
const blob = new Blob([transcript],
|
|
605
|
+
{ type: 'text/' + ( format == 'html' ? 'html' : format == 'md' ? 'markdown' : 'plain' )});
|
|
606
|
+
const link = document.createElement('a'), blobURL = URL.createObjectURL(blob);
|
|
607
|
+
link.href = blobURL; link.download = filename; document.body.append(link);
|
|
608
|
+
link.click(); document.body.removeChild(link); URL.revokeObjectURL(blobURL);
|
|
609
|
+
}
|
|
610
|
+
},
|
|
611
|
+
|
|
612
|
+
extractCode: function() { chatgpt.code.extract(); },
|
|
613
|
+
|
|
614
|
+
generateRandomIP: function() {
|
|
615
|
+
const ip = Array.from({length: 4}, () => Math.floor(chatgpt.randomFloat() * 256)).join('.');
|
|
616
|
+
console.info('IP generated: ' + ip);
|
|
617
|
+
return ip;
|
|
618
|
+
},
|
|
619
|
+
|
|
620
|
+
get: function(targetType, targetName = '') {
|
|
621
|
+
// targetType = 'button'|'link'|'div'|'response'
|
|
622
|
+
// targetName = from get[targetName][targetType] methods, e.g. 'send'
|
|
623
|
+
|
|
624
|
+
// Validate argument types to be string only
|
|
625
|
+
if (typeof targetType !== 'string' || typeof targetName !== 'string') {
|
|
626
|
+
throw new TypeError('Invalid arguments. Both arguments must be strings.'); }
|
|
627
|
+
|
|
628
|
+
// Validate targetType
|
|
629
|
+
if (!targetTypes.includes(targetType.toLowerCase())) {
|
|
630
|
+
throw new Error('Invalid targetType: ' + targetType
|
|
631
|
+
+ '. Valid values are: ' + JSON.stringify(targetTypes)); }
|
|
632
|
+
|
|
633
|
+
// Validate targetName scoped to pre-validated targetType
|
|
634
|
+
const targetNames = [], reTargetName = new RegExp('^get(.*)' + targetType + '$', 'i');
|
|
635
|
+
for (const prop in chatgpt) {
|
|
636
|
+
if (typeof chatgpt[prop] == 'function' && reTargetName.test(prop)) {
|
|
637
|
+
targetNames.push( // add found targetName to valid array
|
|
638
|
+
prop.replace(reTargetName, '$1').toLowerCase());
|
|
639
|
+
}}
|
|
640
|
+
if (!targetNames.includes(targetName.toLowerCase())) {
|
|
641
|
+
throw new Error('Invalid targetName: ' + targetName + '. '
|
|
642
|
+
+ (targetNames.length > 0 ? 'Valid values are: ' + JSON.stringify(targetNames)
|
|
643
|
+
: 'targetType ' + targetType.toLowerCase() + ' does not require additional options.'));
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
// Call target function using pre-validated name components
|
|
647
|
+
const targetFuncNameLower = ('get' + targetName + targetType).toLowerCase();
|
|
648
|
+
const targetFuncName = Object.keys(this).find( // find originally cased target function name
|
|
649
|
+
(name) => { return name.toLowerCase() == targetFuncNameLower; }); // test for match
|
|
650
|
+
return this[targetFuncName](); // call found function
|
|
651
|
+
},
|
|
652
|
+
|
|
653
|
+
getAccessToken: function() {
|
|
654
|
+
return new Promise((resolve, reject) => {
|
|
655
|
+
if (Object.keys(chatgpt.openAIaccessToken).length > 0 && // populated
|
|
656
|
+
(Date.parse(chatgpt.openAIaccessToken.expireDate) - Date.parse(new Date()) >= 0)) // not expired
|
|
657
|
+
return resolve(chatgpt.openAIaccessToken.token);
|
|
658
|
+
const xhr = new XMLHttpRequest();
|
|
659
|
+
xhr.open('GET', endpoints.openAI.session, true);
|
|
660
|
+
xhr.setRequestHeader('Content-Type', 'application/json');
|
|
661
|
+
xhr.onload = () => {
|
|
662
|
+
if (xhr.status !== 200) return reject('🤖 chatgpt.js >> Request failed. Cannot retrieve access token.');
|
|
663
|
+
console.info('Token expiration: ' + new Date(JSON.parse(xhr.responseText).expires).toLocaleString().replace(',', ' at'));
|
|
664
|
+
chatgpt.openAIaccessToken = {
|
|
665
|
+
token: JSON.parse(xhr.responseText).accessToken,
|
|
666
|
+
expireDate: JSON.parse(xhr.responseText).expires
|
|
667
|
+
};
|
|
668
|
+
return resolve(chatgpt.openAIaccessToken.token);
|
|
669
|
+
};
|
|
670
|
+
xhr.send();
|
|
671
|
+
});
|
|
672
|
+
},
|
|
673
|
+
|
|
674
|
+
getAccountDetails: function(...details) {
|
|
675
|
+
// details = [email|id|image|name|picture] = optional
|
|
676
|
+
|
|
677
|
+
// Build details array
|
|
678
|
+
const validDetails = [ 'email', 'id', 'image', 'name', 'picture' ];
|
|
679
|
+
details = ( !arguments[0] ? validDetails // no details passed, populate w/ all valid ones
|
|
680
|
+
: Array.isArray(arguments[0]) ? arguments[0] // details array passed, do nothing
|
|
681
|
+
: Array.from(arguments) ); // details arg(s) passed, convert to array
|
|
682
|
+
|
|
683
|
+
// Validate detail args
|
|
684
|
+
for (const detail of details) {
|
|
685
|
+
if (!validDetails.includes(detail)) { return console.error(
|
|
686
|
+
'Invalid detail arg \'' + detail + '\' supplied. Valid details are:\n'
|
|
687
|
+
+ ' [' + validDetails + ']'); }}
|
|
688
|
+
|
|
689
|
+
// Return account details
|
|
690
|
+
return new Promise((resolve, reject) => {
|
|
691
|
+
const xhr = new XMLHttpRequest();
|
|
692
|
+
xhr.open('GET', endpoints.openAI.session, true);
|
|
693
|
+
xhr.setRequestHeader('Content-Type', 'application/json');
|
|
694
|
+
xhr.onload = () => {
|
|
695
|
+
if (xhr.status === 200) {
|
|
696
|
+
const data = JSON.parse(xhr.responseText).user, detailsToReturn = {};
|
|
697
|
+
for (const detail of details) detailsToReturn[detail] = data[detail];
|
|
698
|
+
return resolve(detailsToReturn);
|
|
699
|
+
} else return reject('🤖 chatgpt.js >> Request failed. Cannot retrieve account details.');
|
|
700
|
+
};
|
|
701
|
+
xhr.send();
|
|
702
|
+
});
|
|
703
|
+
},
|
|
704
|
+
|
|
705
|
+
getChatBox: function() { return document.getElementById('prompt-textarea'); },
|
|
706
|
+
|
|
707
|
+
getChatData: function(chatToGet = 1, detailsToGet = 'all', sender = 'all', msgToGet = 'all') {
|
|
708
|
+
// chatToGet = 'active' | 'latest' | index|title|id of chat to get (defaults to active OpenAI chat > latest chat)
|
|
709
|
+
// detailsToGet = 'all' | [ 'id' | 'title' | 'create_time' | 'update_time' | 'msg' ] (defaults to 'all', excludes msg's)
|
|
710
|
+
// sender = ( 'all' | 'both' ) | 'user' | 'chatgpt' (defaults to 'all', requires 2nd param = 'msg')
|
|
711
|
+
// msgToGet = 'all' | 'latest' | index of msg to get (defaults to 'all', requires 2nd param = 'msg')
|
|
712
|
+
|
|
713
|
+
// Init args
|
|
714
|
+
const validDetails = [ 'all', 'id', 'title', 'create_time', 'update_time', 'msg' ];
|
|
715
|
+
const validSenders = [ 'all', 'both', 'user', 'chatgpt' ];
|
|
716
|
+
chatToGet = !chatToGet ? 'active' // if '' passed, set to active
|
|
717
|
+
: Number.isInteger(chatToGet) || /^\d+$/.test(chatToGet) ? // else if string/int num passed
|
|
718
|
+
( parseInt(chatToGet, 10) === 0 ? 0 : parseInt(chatToGet, 10) - 1 ) // ...offset -1 or keep as 0
|
|
719
|
+
: chatToGet; // else preserve non-num string as 'active', 'latest' or title/id of chat to get
|
|
720
|
+
detailsToGet = ['all', ''].includes(detailsToGet) ? // if '' or 'all' passed
|
|
721
|
+
validDetails.filter(detail => /^(?!all$|msg$).*/.test(detail)) // populate w/ [validDetails] except 'all' & 'msg'
|
|
722
|
+
: Array.isArray(detailsToGet) ? detailsToGet : [detailsToGet]; // else convert to array if needed
|
|
723
|
+
sender = !sender ? 'all' // if '' or unpassed, set to 'all'
|
|
724
|
+
: validSenders.includes(sender) ? sender : 'invalid'; // else set to validSenders or 'invalid'
|
|
725
|
+
msgToGet = Number.isInteger(msgToGet) || /^\d+$/.test(msgToGet) ? // if string/int num passed
|
|
726
|
+
( parseInt(msgToGet, 10) === 0 ? 0 : parseInt(msgToGet, 10) - 1 ) // ...offset -1 or keep as 0
|
|
727
|
+
: ['all', 'latest'].includes(msgToGet.toLowerCase()) ? // else if 'all' or 'latest' passed
|
|
728
|
+
msgToGet.toLowerCase() // ...preserve it
|
|
729
|
+
: !msgToGet ? 'all' // else if '', set to 'all'
|
|
730
|
+
: 'invalid'; // else set 'invalid' for validation step
|
|
731
|
+
|
|
732
|
+
// Validate args
|
|
733
|
+
for (const detail of detailsToGet) {
|
|
734
|
+
if (!validDetails.includes(detail)) { return console.error(
|
|
735
|
+
'Invalid detail arg \'' + detail + '\' passed. Valid details are:\n'
|
|
736
|
+
+ ' [' + validDetails + ']'); }}
|
|
737
|
+
if (sender == 'invalid') { return console.error(
|
|
738
|
+
'Invalid sender arg passed. Valid senders are:\n'
|
|
739
|
+
+ ' [' + validSenders + ']'); }
|
|
740
|
+
if (msgToGet == 'invalid') { return console.error(
|
|
741
|
+
'Invalid msgToGet arg passed. Valid msg\'s to get are:\n'
|
|
742
|
+
+ ' [ \'all\' | \'latest\' | index of msg to get ]'); }
|
|
743
|
+
|
|
744
|
+
const getChatDetails = (token, detailsToGet) => {
|
|
745
|
+
const re_chatID = /\w{8}-\w{4}-\w{4}-\w{4}-\w{12}/;
|
|
746
|
+
return new Promise((resolve, reject) => {
|
|
747
|
+
const xhr = new XMLHttpRequest();
|
|
748
|
+
xhr.open('GET', endpoints.openAI.chats, true);
|
|
749
|
+
xhr.setRequestHeader('Content-Type', 'application/json');
|
|
750
|
+
xhr.setRequestHeader('Authorization', 'Bearer ' + token);
|
|
751
|
+
xhr.onload = () => {
|
|
752
|
+
if (xhr.status !== 200) return reject('🤖 chatgpt.js >> Request failed. Cannot retrieve chat details.');
|
|
753
|
+
const data = JSON.parse(xhr.responseText).items;
|
|
754
|
+
if (data.length <= 0) return reject('🤖 chatgpt.js >> Chat list is empty.');
|
|
755
|
+
const detailsToReturn = {};
|
|
756
|
+
|
|
757
|
+
// Return by index if num, 'latest', or 'active' passed but not truly active
|
|
758
|
+
if (Number.isInteger(chatToGet) || chatToGet == 'latest' ||
|
|
759
|
+
(chatToGet == 'active' && !new RegExp('\/' + re_chatID.source + '$').test(window.location.href))) {
|
|
760
|
+
chatToGet = Number.isInteger(chatToGet) ? chatToGet : 0; // preserve index, otherwise get latest
|
|
761
|
+
if (chatToGet > data.length) { // reject if index out-of-bounds
|
|
762
|
+
return reject('🤖 chatgpt.js >> Chat with index ' + ( chatToGet + 1 )
|
|
763
|
+
+ ' is out of bounds. Only ' + data.length + ' chats exist!'); }
|
|
764
|
+
for (const detail of detailsToGet) detailsToReturn[detail] = data[chatToGet][detail];
|
|
765
|
+
return resolve(detailsToReturn);
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
// Return by title, ID or active chat
|
|
769
|
+
const chatIdentifier = ( // determine to check by ID or title
|
|
770
|
+
chatToGet == 'active' || new RegExp('^' + re_chatID.source + '$').test(chatToGet) ? 'id' : 'title' );
|
|
771
|
+
if (chatToGet == 'active') // replace chatToGet w/ actual ID
|
|
772
|
+
chatToGet = re_chatID.exec(window.location.href)[0];
|
|
773
|
+
let idx, chatFound; // index of potentially found chat, flag if found
|
|
774
|
+
for (idx = 0; idx < data.length; idx++) { // search for id/title to set chatFound flag
|
|
775
|
+
if (data[idx][chatIdentifier] == chatToGet) { chatFound = true; break; }}
|
|
776
|
+
if (!chatFound) // exit
|
|
777
|
+
return reject('🤖 chatgpt.js >> No chat with ' + chatIdentifier + ' = ' + chatToGet + ' found.');
|
|
778
|
+
for (const detail of detailsToGet) detailsToReturn[detail] = data[idx][detail];
|
|
779
|
+
return resolve(detailsToReturn);
|
|
780
|
+
};
|
|
781
|
+
xhr.send();
|
|
782
|
+
});};
|
|
783
|
+
|
|
784
|
+
const getChatMsgs = token => {
|
|
785
|
+
return new Promise((resolve, reject) => {
|
|
786
|
+
const xhr = new XMLHttpRequest();
|
|
787
|
+
getChatDetails(token, ['id']).then(chat => {
|
|
788
|
+
xhr.open('GET', `${endpoints.openAI.chat}/${chat.id}`, true);
|
|
789
|
+
xhr.setRequestHeader('Content-Type', 'application/json');
|
|
790
|
+
xhr.setRequestHeader('Authorization', 'Bearer ' + token);
|
|
791
|
+
xhr.onload = () => {
|
|
792
|
+
if (xhr.status !== 200) return reject('🤖 chatgpt.js >> Request failed. Cannot retrieve chat messages.');
|
|
793
|
+
|
|
794
|
+
// Init const's
|
|
795
|
+
const data = JSON.parse(xhr.responseText).mapping; // Get chat messages
|
|
796
|
+
const userMessages = [], chatGPTMessages = [], msgsToReturn = [];
|
|
797
|
+
|
|
798
|
+
// Fill [userMessages]
|
|
799
|
+
for (const key in data)
|
|
800
|
+
if (data[key].message != null && data[key].message.author.role == 'user')
|
|
801
|
+
userMessages.push({ id: data[key].id, msg: data[key].message });
|
|
802
|
+
userMessages.sort((a, b) => a.msg.create_time - b.msg.create_time); // sort in chronological order
|
|
803
|
+
|
|
804
|
+
if (parseInt(msgToGet, 10) + 1 > userMessages.length) // reject if index out of bounds
|
|
805
|
+
return reject('🤖 chatgpt.js >> Message/response with index ' + ( msgToGet + 1)
|
|
806
|
+
+ ' is out of bounds. Only ' + userMessages.length + ' messages/responses exist!');
|
|
807
|
+
|
|
808
|
+
// Fill [chatGPTMessages]
|
|
809
|
+
for (const userMessage of userMessages) {
|
|
810
|
+
let sub = [];
|
|
811
|
+
for (const key in data) {
|
|
812
|
+
if (data[key].message != null && data[key].message.author.role == 'assistant' && data[key].parent == userMessage.id) {
|
|
813
|
+
sub.push(data[key].message);
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
sub.sort((a, b) => a.create_time - b.create_time); // sort in chronological order
|
|
817
|
+
sub = sub.map(x => { // pull out msgs after sorting
|
|
818
|
+
switch(x.content.content_type) {
|
|
819
|
+
case 'code': return x.content.text;
|
|
820
|
+
case 'text': return x.content.parts[0];
|
|
821
|
+
default: return;
|
|
822
|
+
}
|
|
823
|
+
});
|
|
824
|
+
sub = sub.length === 1 ? sub[0] : sub; // convert not regenerated responses to strings
|
|
825
|
+
chatGPTMessages.push(sub); // array of arrays (length > 1 = regenerated responses)
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
if (sender == 'user') // Fill [msgsToReturn] with user messages
|
|
829
|
+
for (const userMessage in userMessages)
|
|
830
|
+
msgsToReturn.push(userMessages[userMessage].msg.content.parts[0]);
|
|
831
|
+
else if (sender == 'chatgpt') // Fill [msgsToReturn] with ChatGPT responses
|
|
832
|
+
for (const chatGPTMessage of chatGPTMessages)
|
|
833
|
+
msgsToReturn.push(msgToGet == 'latest' ? chatGPTMessages[chatGPTMessages.length - 1] : chatGPTMessage );
|
|
834
|
+
else { // Fill [msgsToReturn] with objects of user messages and chatgpt response(s)
|
|
835
|
+
let i = 0;
|
|
836
|
+
for (const message in userMessages) {
|
|
837
|
+
msgsToReturn.push({
|
|
838
|
+
user: userMessages[message].msg.content.parts[0],
|
|
839
|
+
chatgpt: msgToGet == 'latest' ? chatGPTMessages[i][chatGPTMessages[i].length - 1] : chatGPTMessages[i]
|
|
840
|
+
});
|
|
841
|
+
i++;
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
return resolve(msgToGet == 'all' ? msgsToReturn // if 'all' passed, return array
|
|
845
|
+
: msgToGet == 'latest' ? msgsToReturn[msgsToReturn.length - 1] // else if 'latest' passed, return latest
|
|
846
|
+
: msgsToReturn[msgToGet] ); // else return element of array
|
|
847
|
+
};
|
|
848
|
+
xhr.send();
|
|
849
|
+
});});};
|
|
850
|
+
|
|
851
|
+
// Return chat data
|
|
852
|
+
return new Promise(resolve => { chatgpt.getAccessToken().then(token => {
|
|
853
|
+
if (!detailsToGet.includes('msg')) getChatDetails(token, detailsToGet).then(data => {
|
|
854
|
+
return resolve(data); // get just the chat details
|
|
855
|
+
});
|
|
856
|
+
else getChatMsgs(token).then(messages => { return resolve(messages); }); // otherwise get specific msg's
|
|
857
|
+
});});
|
|
858
|
+
},
|
|
859
|
+
|
|
860
|
+
getChatInput: function() { return chatgpt.getChatBox().value; },
|
|
861
|
+
|
|
862
|
+
getContinueGeneratingButton: function() {
|
|
863
|
+
for (const svg of document.querySelectorAll('form button svg')) {
|
|
864
|
+
if (svg.querySelector('polygon[points*="11 19 2 12 11 5 11 19"]'))
|
|
865
|
+
return svg.parentNode.parentNode;
|
|
866
|
+
}},
|
|
867
|
+
|
|
868
|
+
getLastPrompt: function() { return chatgpt.getChatData('active', 'msg', 'user', 'latest'); },
|
|
869
|
+
getLastResponse: function() { return chatgpt.getChatData('active', 'msg', 'chatgpt', 'latest'); },
|
|
870
|
+
|
|
871
|
+
getNewChatLink: function() {
|
|
872
|
+
for (const navLink of document.querySelectorAll('nav a')) {
|
|
873
|
+
if (/(new|clear) chat/i.test(navLink.text)) {
|
|
874
|
+
return navLink;
|
|
875
|
+
}}},
|
|
876
|
+
|
|
877
|
+
getRegenerateButton: function() {
|
|
878
|
+
for (const mainSVG of document.querySelectorAll('main svg')) {
|
|
879
|
+
if (mainSVG.querySelector('path[d*="M4.5 2.5C5.05228"]')) // regen icon found
|
|
880
|
+
return mainSVG.parentNode.parentNode;
|
|
881
|
+
}},
|
|
882
|
+
|
|
883
|
+
getResponse: function() {
|
|
884
|
+
// * Returns response via DOM by index arg if OpenAI chat page is active, otherwise uses API w/ following args:
|
|
885
|
+
// chatToGet = index|title|id of chat to get (defaults to latest if '' unpassed)
|
|
886
|
+
// responseToGet = index of response to get (defaults to latest if '' unpassed)
|
|
887
|
+
// regenResponseToGet = index of regenerated response to get (defaults to latest if '' unpassed)
|
|
888
|
+
|
|
889
|
+
if (window.location.href.startsWith('https://chat.openai.com/c/'))
|
|
890
|
+
return chatgpt.getResponseFromDOM.apply(null, arguments);
|
|
891
|
+
else return chatgpt.getResponseFromAPI.apply(null, arguments);
|
|
892
|
+
},
|
|
893
|
+
|
|
894
|
+
getResponseFromAPI: function(chatToGet, responseToGet) { return chatgpt.response.getFromAPI(chatToGet, responseToGet); },
|
|
895
|
+
getResponseFromDOM: function(pos) { return chatgpt.response.getFromDOM(pos); },
|
|
896
|
+
getSendButton: function() { return document.querySelector('form button[class*="bottom"]'); },
|
|
897
|
+
|
|
898
|
+
getStopGeneratingButton: function() {
|
|
899
|
+
for (const svg of document.querySelectorAll('form button svg')) {
|
|
900
|
+
if (svg.querySelector('path[d*="2 0 0 1 2"]'))
|
|
901
|
+
return svg.parentNode;
|
|
902
|
+
}},
|
|
903
|
+
|
|
904
|
+
getUserLanguage: function() {
|
|
905
|
+
return navigator.languages[0] || navigator.language || navigator.browserLanguage ||
|
|
906
|
+
navigator.systemLanguage || navigator.userLanguage || ''; },
|
|
907
|
+
|
|
908
|
+
history: {
|
|
909
|
+
isLoaded: function() {
|
|
910
|
+
return new Promise(resolve => {
|
|
911
|
+
const checkChatHistory = () => {
|
|
912
|
+
if (document.querySelector('nav')) resolve(true);
|
|
913
|
+
else setTimeout(checkChatHistory, 100);
|
|
914
|
+
};
|
|
915
|
+
checkChatHistory();
|
|
916
|
+
});}
|
|
917
|
+
},
|
|
918
|
+
|
|
919
|
+
instructions: {
|
|
920
|
+
// NOTE: DOM is not updated to reflect new instructions added/removed or toggle state (until session refresh)
|
|
921
|
+
|
|
922
|
+
add: function(instruction, target) {
|
|
923
|
+
if (!instruction) return console.error('Please provide an instruction');
|
|
924
|
+
if (typeof instruction !== 'string') return console.error('Instruction must be a string');
|
|
925
|
+
const validTargets = ['user', 'chatgpt']; // valid targets
|
|
926
|
+
if (!target) return console.error('Please provide a valid target!');
|
|
927
|
+
if (typeof target !== 'string') return console.error('Target must be a string');
|
|
928
|
+
target = target.toLowerCase(); // lowercase target
|
|
929
|
+
if (!validTargets.includes(target))
|
|
930
|
+
return console.error(`Invalid target ${target}. Valid targets are [${validTargets}]`);
|
|
931
|
+
|
|
932
|
+
instruction = `\n\n${instruction}`; // add 2 newlines to the new instruction
|
|
933
|
+
|
|
934
|
+
return new Promise(resolve => {
|
|
935
|
+
chatgpt.getAccessToken().then(async token => {
|
|
936
|
+
const instructionsData = await this.fetchData();
|
|
937
|
+
|
|
938
|
+
// Concatenate old instructions with new instruction
|
|
939
|
+
if (target == 'user') instructionsData.about_user_message += instruction;
|
|
940
|
+
else if (target == 'chatgpt') instructionsData.about_model_message += instruction;
|
|
941
|
+
|
|
942
|
+
await this.sendRequest('POST', token, instructionsData);
|
|
943
|
+
return resolve();
|
|
944
|
+
});
|
|
945
|
+
});
|
|
946
|
+
},
|
|
947
|
+
|
|
948
|
+
clear: function(target) {
|
|
949
|
+
const validTargets = ['user', 'chatgpt']; // valid targets
|
|
950
|
+
if (!target) return console.error('Please provide a valid target!');
|
|
951
|
+
if (typeof target !== 'string') return console.error('Target must be a string');
|
|
952
|
+
target = target.toLowerCase(); // lowercase target
|
|
953
|
+
if (!validTargets.includes(target))
|
|
954
|
+
return console.error(`Invalid target ${target}. Valid targets are [${validTargets}]`);
|
|
955
|
+
|
|
956
|
+
return new Promise(resolve => {
|
|
957
|
+
chatgpt.getAccessToken().then(async token => {
|
|
958
|
+
const instructionsData = await this.fetchData();
|
|
959
|
+
|
|
960
|
+
// Clear target's instructions
|
|
961
|
+
if (target == 'user') instructionsData.about_user_message = '';
|
|
962
|
+
else if (target == 'chatgpt') instructionsData.about_model_message = '';
|
|
963
|
+
|
|
964
|
+
await this.sendRequest('POST', token, instructionsData);
|
|
965
|
+
return resolve();
|
|
966
|
+
});});
|
|
967
|
+
},
|
|
968
|
+
|
|
969
|
+
fetchData: function() {
|
|
970
|
+
// INTERNAL METHOD
|
|
971
|
+
return new Promise(resolve => {
|
|
972
|
+
chatgpt.getAccessToken().then(async token => {
|
|
973
|
+
return resolve(await this.sendRequest('GET', token)); // Return API data
|
|
974
|
+
});});
|
|
975
|
+
},
|
|
976
|
+
|
|
977
|
+
sendRequest: function(method, token, body) {
|
|
978
|
+
// INTERNAL METHOD
|
|
979
|
+
// Validate args
|
|
980
|
+
for (let i = 0; i < arguments.length - 1; i++) if (typeof arguments[i] !== 'string')
|
|
981
|
+
return console.error(`Argument ${ i + 1 } must be a string`);
|
|
982
|
+
const validMethods = ['POST', 'GET'];
|
|
983
|
+
method = (method || '').trim().toUpperCase();
|
|
984
|
+
if (!method || !validMethods.includes(method)) // reject if not valid method
|
|
985
|
+
return console.error(`Valid methods are ${ validMethods }`);
|
|
986
|
+
if (!token) return console.error('Please provide a valid access token!');
|
|
987
|
+
if (body && typeof body !== 'object') // reject if body is passed but not an object
|
|
988
|
+
return console.error(`Invalid body data type. Got ${ typeof body }, expected object`);
|
|
989
|
+
|
|
990
|
+
return new Promise((resolve, reject) => {
|
|
991
|
+
const xhr = new XMLHttpRequest();
|
|
992
|
+
xhr.open(method, endpoints.openAI.instructions, true);
|
|
993
|
+
// Set headers
|
|
994
|
+
xhr.setRequestHeader('Accept-Language', 'en-US');
|
|
995
|
+
xhr.setRequestHeader('Authorization', 'Bearer ' + token);
|
|
996
|
+
if (method == 'POST') xhr.setRequestHeader('Content-Type', 'application/json');
|
|
997
|
+
|
|
998
|
+
xhr.onload = () => {
|
|
999
|
+
const responseData = JSON.parse(xhr.responseText);
|
|
1000
|
+
if (xhr.status === 422)
|
|
1001
|
+
return reject('🤖 chatgpt.js >> Character limit exceeded. Custom instructions can have a maximum length of 1500 characters.');
|
|
1002
|
+
else if (xhr.status === 403 && responseData.detail.reason == 'content_policy')
|
|
1003
|
+
return reject('🤖 chatgpt.js >> ' + responseData.detail.description);
|
|
1004
|
+
else if (xhr.status !== 200)
|
|
1005
|
+
return reject('🤖 chatgpt.js >> Request failed. Cannot contact custom instructions endpoint.');
|
|
1006
|
+
console.info(`Custom instructions successfully contacted with method ${ method }`);
|
|
1007
|
+
return resolve(responseData || {}); // return response data no matter what the method is
|
|
1008
|
+
};
|
|
1009
|
+
xhr.send(JSON.stringify(body) || ''); // if body is passed send it, else just send the request
|
|
1010
|
+
});
|
|
1011
|
+
},
|
|
1012
|
+
|
|
1013
|
+
turnOff: function() {
|
|
1014
|
+
return new Promise(resolve => {
|
|
1015
|
+
chatgpt.getAccessToken().then(async token => {
|
|
1016
|
+
const instructionsData = await this.fetchData();
|
|
1017
|
+
instructionsData.enabled = false;
|
|
1018
|
+
await this.sendRequest('POST', token, instructionsData);
|
|
1019
|
+
return resolve();
|
|
1020
|
+
});
|
|
1021
|
+
});
|
|
1022
|
+
},
|
|
1023
|
+
|
|
1024
|
+
turnOn: function() {
|
|
1025
|
+
return new Promise(resolve => {
|
|
1026
|
+
chatgpt.getAccessToken().then(async token => {
|
|
1027
|
+
const instructionsData = await this.fetchData();
|
|
1028
|
+
instructionsData.enabled = true;
|
|
1029
|
+
await this.sendRequest('POST', token, instructionsData);
|
|
1030
|
+
return resolve();
|
|
1031
|
+
});
|
|
1032
|
+
});
|
|
1033
|
+
},
|
|
1034
|
+
|
|
1035
|
+
toggle: function() {
|
|
1036
|
+
return new Promise(resolve => {
|
|
1037
|
+
this.fetchData().then(async instructionsData => {
|
|
1038
|
+
await (instructionsData.enabled ? this.turnOff() : this.turnOn());
|
|
1039
|
+
return resolve();
|
|
1040
|
+
});});
|
|
1041
|
+
}
|
|
1042
|
+
},
|
|
1043
|
+
|
|
1044
|
+
isChromium: function() { return chatgpt.browser.isChromium(); },
|
|
1045
|
+
isDarkMode: function() { return document.documentElement.classList.toString().includes('dark'); },
|
|
1046
|
+
isFirefox: function() { return chatgpt.browser.isFirefox(); },
|
|
1047
|
+
isFullScreen: function() { return chatgpt.browser.isFullScreen(); },
|
|
1048
|
+
|
|
1049
|
+
isIdle: function() {
|
|
1050
|
+
return new Promise(resolve => {
|
|
1051
|
+
const intervalId = setInterval(() => {
|
|
1052
|
+
if (chatgpt.getRegenerateButton()) {
|
|
1053
|
+
clearInterval(intervalId); resolve(true);
|
|
1054
|
+
}}, 100);});},
|
|
1055
|
+
|
|
1056
|
+
isLoaded: function() {
|
|
1057
|
+
return new Promise(resolve => {
|
|
1058
|
+
const intervalId = setInterval(() => {
|
|
1059
|
+
if (document.querySelector('nav button[id*="menu"]')) {
|
|
1060
|
+
clearInterval(intervalId); setTimeout(() => { resolve(true); }, 500);
|
|
1061
|
+
}}, 100);});},
|
|
1062
|
+
|
|
1063
|
+
isLightMode: function() { return document.documentElement.classList.toString().includes('light'); },
|
|
1064
|
+
isMobileDevice: function() { return chatgpt.browser.isMobile(); },
|
|
1065
|
+
|
|
1066
|
+
logout: function() { window.location.href = 'https://chat.openai.com/auth/logout'; },
|
|
1067
|
+
|
|
1068
|
+
menu: {
|
|
1069
|
+
elements: [],
|
|
1070
|
+
addedEvent: false,
|
|
1071
|
+
|
|
1072
|
+
append: function(element, attrs = {}) {
|
|
1073
|
+
// element = 'button' | 'dropdown' REQUIRED (no default value)
|
|
1074
|
+
// attrs = { ... }
|
|
1075
|
+
// attrs for 'button': 'icon' = src string, 'label' = string, 'onclick' = function
|
|
1076
|
+
// attrs for 'dropdown': 'items' = [ { text: string, value: string }, ... ] array of objects
|
|
1077
|
+
// where 'text' is the displayed text of the option and 'value' is the value of the option
|
|
1078
|
+
|
|
1079
|
+
const validElements = ['button', 'dropdown'];
|
|
1080
|
+
if (!element || typeof element !== 'string') // element not passed or invalid type
|
|
1081
|
+
return console.error('🤖 chatgpt.js >> Please supply a valid string element name!');
|
|
1082
|
+
element = element.toLowerCase();
|
|
1083
|
+
if (!validElements.includes(element)) // element not in list
|
|
1084
|
+
return console.error(`🤖 chatgpt.js >> Invalid element! Valid elements are [${validElements}]`);
|
|
1085
|
+
|
|
1086
|
+
const newElement = document.createElement(
|
|
1087
|
+
element == 'dropdown' ? 'select' :
|
|
1088
|
+
element == 'button' ? 'a' : element
|
|
1089
|
+
);
|
|
1090
|
+
newElement.id = Math.floor(chatgpt.randomFloat() * 1000000) + Date.now(); // add random id to the element
|
|
1091
|
+
|
|
1092
|
+
if (element == 'button') {
|
|
1093
|
+
newElement.textContent = attrs?.label && typeof attrs.label == 'string'
|
|
1094
|
+
? attrs.label
|
|
1095
|
+
: 'chatgpt.js button';
|
|
1096
|
+
|
|
1097
|
+
const icon = document.createElement('img');
|
|
1098
|
+
icon.src = attrs?.icon && typeof attrs.icon == 'string' // can also be base64 encoded image string
|
|
1099
|
+
? attrs.icon // add icon to button element if given, else default one
|
|
1100
|
+
: ( endpoints.assets + '/starters/chrome/extension/icons/icon128.png' );
|
|
1101
|
+
icon.width = 18;
|
|
1102
|
+
newElement.insertBefore(icon, newElement.firstChild);
|
|
1103
|
+
|
|
1104
|
+
newElement.onclick = attrs?.onclick && typeof attrs.onclick == 'function'
|
|
1105
|
+
? attrs.onclick
|
|
1106
|
+
: function() {};
|
|
1107
|
+
}
|
|
1108
|
+
|
|
1109
|
+
else if (element == 'dropdown') {
|
|
1110
|
+
if (!attrs?.items || // there no are options to add
|
|
1111
|
+
!Array.isArray(attrs.items) || // it's not an array
|
|
1112
|
+
!attrs.items.length) // the array is empty
|
|
1113
|
+
attrs.items = [{ text: '🤖 chatgpt.js option', value: 'chatgpt.js option value' }]; // set default dropdown entry
|
|
1114
|
+
|
|
1115
|
+
if (!attrs.items.every(el => typeof el == 'object')) // the entries of the array are not objects
|
|
1116
|
+
return console.error('\'items\' must be an array of objects!');
|
|
1117
|
+
|
|
1118
|
+
newElement.style = 'background-color: #000; width: 100%; border: none;';
|
|
1119
|
+
|
|
1120
|
+
attrs.items.forEach(item => {
|
|
1121
|
+
const optionElement = document.createElement('option');
|
|
1122
|
+
optionElement.textContent = item?.text;
|
|
1123
|
+
optionElement.value = item?.value;
|
|
1124
|
+
newElement.add(optionElement);
|
|
1125
|
+
});
|
|
1126
|
+
}
|
|
1127
|
+
|
|
1128
|
+
const addElementsToMenu = () => {
|
|
1129
|
+
const optionButtons = document.querySelectorAll('a[role="menuitem"]');
|
|
1130
|
+
let cssClasses;
|
|
1131
|
+
|
|
1132
|
+
for (let navLink of optionButtons)
|
|
1133
|
+
if (navLink.textContent == 'Settings') {
|
|
1134
|
+
cssClasses = navLink.classList;
|
|
1135
|
+
break; }
|
|
1136
|
+
|
|
1137
|
+
const headlessNav = optionButtons[0].parentNode;
|
|
1138
|
+
|
|
1139
|
+
chatgpt.menu.elements.forEach(element => {
|
|
1140
|
+
element.setAttribute('class', cssClasses);
|
|
1141
|
+
if (!headlessNav.contains(element))
|
|
1142
|
+
try { headlessNav.insertBefore(element, headlessNav.firstChild); }
|
|
1143
|
+
catch (err) { console.error(err); }
|
|
1144
|
+
});
|
|
1145
|
+
};
|
|
1146
|
+
|
|
1147
|
+
this.elements.push(newElement);
|
|
1148
|
+
const menuBtn = document.querySelector('nav button[id*="headless"]');
|
|
1149
|
+
if (!this.addedEvent) { // to prevent adding more than one event
|
|
1150
|
+
menuBtn.addEventListener('click', () => { setTimeout(addElementsToMenu, 25); });
|
|
1151
|
+
this.addedEvent = true; }
|
|
1152
|
+
|
|
1153
|
+
return newElement.id; // Return the element id
|
|
1154
|
+
},
|
|
1155
|
+
|
|
1156
|
+
close: function() {
|
|
1157
|
+
const menuBtn = document.querySelector('nav [id*="menu-button"][aria-expanded="true"]');
|
|
1158
|
+
if (menuBtn)
|
|
1159
|
+
try { menuBtn.click(); } catch (err) { console.error('Error while closing the menu'); throw new Error(err); }
|
|
1160
|
+
else { console.error('Menu already hidden!'); throw new Error(); }
|
|
1161
|
+
},
|
|
1162
|
+
|
|
1163
|
+
open: function() {
|
|
1164
|
+
const menuBtn = document.querySelector('nav [id*="menu-button"][aria-expanded="false"]');
|
|
1165
|
+
if (menuBtn)
|
|
1166
|
+
try { menuBtn.click(); } catch (err) { console.error('Error while closing the menu'); throw new Error(err); }
|
|
1167
|
+
else { console.error('Menu already hidden!'); throw new Error(); }
|
|
1168
|
+
}
|
|
1169
|
+
},
|
|
1170
|
+
|
|
1171
|
+
minify: function() { chatgpt.code.minify(); },
|
|
1172
|
+
|
|
1173
|
+
notify: async function(msg, position, notifDuration, shadow) {
|
|
1174
|
+
notifDuration = notifDuration ? +notifDuration : 1.75; // sec duration to maintain notification visibility
|
|
1175
|
+
const fadeDuration = 0.3, // sec duration of fade-out
|
|
1176
|
+
vpYoffset = 23, vpXoffset = 27; // px offset from viewport border
|
|
1177
|
+
|
|
1178
|
+
// Create/append notification div
|
|
1179
|
+
const notificationDiv = document.createElement('div'); // make div
|
|
1180
|
+
notificationDiv.id = Math.floor(chatgpt.randomFloat() * 1000000) + Date.now();
|
|
1181
|
+
notificationDiv.classList.add('chatgpt-notif');
|
|
1182
|
+
notificationDiv.innerText = msg; // insert msg
|
|
1183
|
+
document.body.append(notificationDiv); // insert into DOM
|
|
1184
|
+
|
|
1185
|
+
// Create/append close button
|
|
1186
|
+
const closeBtn = document.createElement('div');
|
|
1187
|
+
closeBtn.title = 'Dismiss'; closeBtn.classList.add('notif-close-btn');
|
|
1188
|
+
const closeSVG = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
|
|
1189
|
+
closeSVG.setAttribute('height', '8px');
|
|
1190
|
+
closeSVG.setAttribute('viewBox', '0 0 14 14');
|
|
1191
|
+
closeSVG.setAttribute('fill', 'none');
|
|
1192
|
+
closeSVG.style.height = closeSVG.style.width = '8px'; // override SVG styles on non-OpenAI sites
|
|
1193
|
+
const closeSVGpath = document.createElementNS('http://www.w3.org/2000/svg', 'path');
|
|
1194
|
+
closeSVGpath.setAttribute('fill-rule', 'evenodd');
|
|
1195
|
+
closeSVGpath.setAttribute('clip-rule', 'evenodd');
|
|
1196
|
+
closeSVGpath.setAttribute('fill', 'white');
|
|
1197
|
+
closeSVGpath.setAttribute('d', 'M13.7071 1.70711C14.0976 1.31658 14.0976 0.683417 13.7071 0.292893C13.3166 -0.0976312 12.6834 -0.0976312 12.2929 0.292893L7 5.58579L1.70711 0.292893C1.31658 -0.0976312 0.683417 -0.0976312 0.292893 0.292893C-0.0976312 0.683417 -0.0976312 1.31658 0.292893 1.70711L5.58579 7L0.292893 12.2929C-0.0976312 12.6834 -0.0976312 13.3166 0.292893 13.7071C0.683417 14.0976 1.31658 14.0976 1.70711 13.7071L7 8.41421L12.2929 13.7071C12.6834 14.0976 13.3166 14.0976 13.7071 13.7071C14.0976 13.3166 14.0976 12.6834 13.7071 12.2929L8.41421 7L13.7071 1.70711Z');
|
|
1198
|
+
closeSVG.append(closeSVGpath); closeBtn.append(closeSVG); notificationDiv.append(closeBtn);
|
|
1199
|
+
|
|
1200
|
+
// Determine div position/quadrant
|
|
1201
|
+
notificationDiv.isTop = !position || !/low|bottom/i.test(position);
|
|
1202
|
+
notificationDiv.isRight = !position || !/left/i.test(position);
|
|
1203
|
+
notificationDiv.quadrant = (notificationDiv.isTop ? 'top' : 'bottom')
|
|
1204
|
+
+ (notificationDiv.isRight ? 'Right' : 'Left');
|
|
1205
|
+
|
|
1206
|
+
// Create/append/update notification style (if missing or outdated)
|
|
1207
|
+
const thisUpdated = 20231110; // datestamp of last edit for this file's `notifStyle`
|
|
1208
|
+
let notifStyle = document.querySelector('#chatgpt-notif-style'); // try to select existing style
|
|
1209
|
+
if (!notifStyle || parseInt(notifStyle.getAttribute('last-updated'), 10) < thisUpdated) { // if missing or outdated
|
|
1210
|
+
if (!notifStyle) { // outright missing, create/id/attr/append it first
|
|
1211
|
+
notifStyle = document.createElement('style'); notifStyle.id = 'chatgpt-notif-style';
|
|
1212
|
+
notifStyle.setAttribute('last-updated', thisUpdated.toString());
|
|
1213
|
+
document.head.append(notifStyle);
|
|
1214
|
+
}
|
|
1215
|
+
notifStyle.innerText = ( // update prev/new style contents
|
|
1216
|
+
'.chatgpt-notif {'
|
|
1217
|
+
+ 'background-color: black ; padding: 10px 13px 10px 18px ; border-radius: 11px ; border: 1px solid #f5f5f7 ;' // bubble style
|
|
1218
|
+
+ 'opacity: 0 ; position: fixed ; z-index: 9999 ; font-size: 1.8rem ; color: white ;' // visibility
|
|
1219
|
+
+ '-webkit-user-select: none ; -moz-user-select: none ; -ms-user-select: none ; user-select: none ;'
|
|
1220
|
+
+ `transform: translateX(${ !notificationDiv.isRight ? '-' : '' }35px) ;` // init off-screen for transition fx
|
|
1221
|
+
+ ( shadow ? ( 'box-shadow: -8px 13px 25px 0 ' + ( /\b(shadow|on)\b/gi.test(shadow) ? 'gray' : shadow )) : '' ) + '}'
|
|
1222
|
+
+ '.notif-close-btn { cursor: pointer ; float: right ; position: relative ; right: -4px ; margin-left: -3px ;'
|
|
1223
|
+
+ 'display: grid }' // top-align for non-OpenAI sites
|
|
1224
|
+
+ '@keyframes notif-zoom-fade-out { 0% { opacity: 1 ; transform: scale(1) }' // transition out keyframes
|
|
1225
|
+
+ '15% { opacity: 0.35 ; transform: rotateX(-27deg) scale(1.05) }'
|
|
1226
|
+
+ '45% { opacity: 0.05 ; transform: rotateX(-81deg) }'
|
|
1227
|
+
+ '100% { opacity: 0 ; transform: rotateX(-180deg) scale(1.15) }}'
|
|
1228
|
+
);
|
|
1229
|
+
}
|
|
1230
|
+
|
|
1231
|
+
// Enqueue notification
|
|
1232
|
+
let notifyProps = JSON.parse(localStorage.notifyProps);
|
|
1233
|
+
notifyProps.queue[notificationDiv.quadrant].push(notificationDiv.id);
|
|
1234
|
+
localStorage.notifyProps = JSON.stringify(notifyProps);
|
|
1235
|
+
|
|
1236
|
+
// Position notification (defaults to top-right)
|
|
1237
|
+
notificationDiv.style.top = notificationDiv.isTop ? vpYoffset.toString() + 'px' : '';
|
|
1238
|
+
notificationDiv.style.bottom = !notificationDiv.isTop ? vpYoffset.toString() + 'px' : '';
|
|
1239
|
+
notificationDiv.style.right = notificationDiv.isRight ? vpXoffset.toString() + 'px' : '';
|
|
1240
|
+
notificationDiv.style.left = !notificationDiv.isRight ? vpXoffset.toString() + 'px' : '';
|
|
1241
|
+
|
|
1242
|
+
// Reposition old notifications
|
|
1243
|
+
const thisQuadrantQueue = notifyProps.queue[notificationDiv.quadrant];
|
|
1244
|
+
if (thisQuadrantQueue.length > 1) {
|
|
1245
|
+
try { // to move old notifications
|
|
1246
|
+
for (const divId of thisQuadrantQueue.slice(0, -1)) { // exclude new div
|
|
1247
|
+
const oldDiv = document.getElementById(divId),
|
|
1248
|
+
offsetProp = oldDiv.style.top ? 'top' : 'bottom', // pick property to change
|
|
1249
|
+
vOffset = +/\d+/.exec(oldDiv.style[offsetProp])[0] + 5 + oldDiv.getBoundingClientRect().height;
|
|
1250
|
+
oldDiv.style[offsetProp] = `${ vOffset }px`; // change prop
|
|
1251
|
+
}
|
|
1252
|
+
} catch (err) {}
|
|
1253
|
+
}
|
|
1254
|
+
|
|
1255
|
+
// Show notification
|
|
1256
|
+
setTimeout(() => {
|
|
1257
|
+
notificationDiv.style.opacity = chatgpt.isDarkMode() ? 0.8 : 0.67; // show msg
|
|
1258
|
+
notificationDiv.style.transform = 'translateX(0)'; // bring from off-screen
|
|
1259
|
+
notificationDiv.style.transition = 'transform 0.15s ease, opacity 0.15s ease';
|
|
1260
|
+
}, 10);
|
|
1261
|
+
|
|
1262
|
+
// Init delay before hiding
|
|
1263
|
+
const hideDelay = fadeDuration > notifDuration ? 0 // don't delay if fade exceeds notification duration
|
|
1264
|
+
: notifDuration - fadeDuration; // otherwise delay for difference
|
|
1265
|
+
|
|
1266
|
+
// Init/schedule audio feedback
|
|
1267
|
+
let dismissAudio, dismissAudioTID; // be accessible to `dismissNotif()`
|
|
1268
|
+
if (isFFtmScript) {
|
|
1269
|
+
// Init base audio index
|
|
1270
|
+
let nthAudio; do nthAudio = Math.floor(Math.random() * 3) + 1; // randomize between 1-3...
|
|
1271
|
+
while (nthAudio === notifyProps.lastNthAudio); // ...until distinct from prev index (for variety)
|
|
1272
|
+
notifyProps.lastNthAudio = nthAudio; localStorage.notifyProps = JSON.stringify(notifyProps);
|
|
1273
|
+
|
|
1274
|
+
// Build audio element + src URL
|
|
1275
|
+
dismissAudio = new Audio();
|
|
1276
|
+
dismissAudio.src = endpoints.assets + '/media/audio/notifications/bubble-pop/'
|
|
1277
|
+
+ `${ nthAudio }-${ notificationDiv.isRight ? 'right' : 'left' }.mp3`;
|
|
1278
|
+
|
|
1279
|
+
// Schedule playback
|
|
1280
|
+
dismissAudioTID = setTimeout(() => dismissAudio.play().catch(() => {}), hideDelay * 1000);
|
|
1281
|
+
}
|
|
1282
|
+
|
|
1283
|
+
// Add notification dismissal to timeout schedule + button clicks
|
|
1284
|
+
const dismissNotif = () => {
|
|
1285
|
+
notificationDiv.style.animation = `notif-zoom-fade-out ${ fadeDuration }s ease-out`;
|
|
1286
|
+
if (isFFtmScript) dismissAudio?.play().catch(() => {});
|
|
1287
|
+
clearTimeout(dismissFuncTID); clearTimeout(dismissAudioTID);
|
|
1288
|
+
};
|
|
1289
|
+
const dismissFuncTID = setTimeout(dismissNotif, hideDelay * 1000); // maintain visibility for `hideDelay` secs, then dismiss
|
|
1290
|
+
closeSVG.addEventListener('click', dismissNotif, { once: true }); // add to close button clicks
|
|
1291
|
+
|
|
1292
|
+
// Destroy notification
|
|
1293
|
+
notificationDiv.addEventListener('animationend', () => {
|
|
1294
|
+
notificationDiv.remove(); // remove from DOM
|
|
1295
|
+
notifyProps = JSON.parse(localStorage.notifyProps);
|
|
1296
|
+
notifyProps.queue[notificationDiv.quadrant].shift(); // + memory
|
|
1297
|
+
localStorage.notifyProps = JSON.stringify(notifyProps); // + storage
|
|
1298
|
+
}, { once: true });
|
|
1299
|
+
},
|
|
1300
|
+
|
|
1301
|
+
obfuscate: function() { chatgpt.code.obfuscate(); },
|
|
1302
|
+
|
|
1303
|
+
printAllFunctions: function() {
|
|
1304
|
+
|
|
1305
|
+
// Define colors
|
|
1306
|
+
const colors = { // element: [light, dark]
|
|
1307
|
+
cmdPrompt: ['#ff00ff', '#00ff00'], // pink, green
|
|
1308
|
+
objName: ['#0611e9', '#f9ee16'], // blue, yellow
|
|
1309
|
+
methodName: ['#005aff', '#ffa500'], // blue, orange
|
|
1310
|
+
entryType: ['#467e06', '#b981f9'], // green, purple
|
|
1311
|
+
srcMethod: ['#ff0000', '#00ffff'] // red, cyan
|
|
1312
|
+
};
|
|
1313
|
+
Object.keys(colors).forEach(element => { // populate dark scheme colors if missing
|
|
1314
|
+
colors[element][1] = colors[element][1] ||
|
|
1315
|
+
'#' + (Number(`0x1${ colors[element][0].replace(/^#/, '') }`) ^ 0xFFFFFF)
|
|
1316
|
+
.toString(16).substring(1).toUpperCase(); // convert to hex
|
|
1317
|
+
});
|
|
1318
|
+
|
|
1319
|
+
// Create [functionNames]
|
|
1320
|
+
const functionNames = [];
|
|
1321
|
+
for (const prop in this) {
|
|
1322
|
+
if (typeof this[prop] == 'function') {
|
|
1323
|
+
const chatgptIsParent = !Object.keys(this).find(obj => Object.keys(this[obj]).includes(this[prop].name)),
|
|
1324
|
+
functionParent = chatgptIsParent ? 'chatgpt' : 'other';
|
|
1325
|
+
functionNames.push([functionParent, prop]);
|
|
1326
|
+
} else if (typeof this[prop] == 'object') {
|
|
1327
|
+
for (const nestedProp in this[prop]) {
|
|
1328
|
+
if (typeof this[prop][nestedProp] == 'function') {
|
|
1329
|
+
functionNames.push([prop, nestedProp]);
|
|
1330
|
+
}}}}
|
|
1331
|
+
functionNames.sort((a, b) => { return a[0].localeCompare(b[0]) || a[1].localeCompare(b[1]); });
|
|
1332
|
+
|
|
1333
|
+
// Print methods
|
|
1334
|
+
const isDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches,
|
|
1335
|
+
baseFontStyles = 'font-family: monospace ; font-size: larger ; ';
|
|
1336
|
+
console.log('\n%c🤖 chatgpt.js methods\n', 'font-family: sans-serif ; font-size: xxx-large ; font-weight: bold');
|
|
1337
|
+
for (const functionName of functionNames) {
|
|
1338
|
+
const isChatGptObjParent = /chatgpt|other/.test(functionName[0]),
|
|
1339
|
+
rootFunction = ( functionName[0] == 'chatgpt' ? this[functionName[1]].name
|
|
1340
|
+
: functionName[0] !== 'other' ? functionName[0] + '.' + functionName[1]
|
|
1341
|
+
: (( Object.keys(this).find(obj => Object.keys(this[obj]).includes(this[functionName[1]].name)) + '.' )
|
|
1342
|
+
+ this[functionName[1]].name )),
|
|
1343
|
+
isAsync = this[functionName[1]]?.constructor.name == 'AsyncFunction';
|
|
1344
|
+
console.log('%c>> %c' + ( isChatGptObjParent ? '' : `${ functionName[0] }.%c`) + functionName[1]
|
|
1345
|
+
+ ' - https://chatgptjs.org/userguide/' + /(?:.*\.)?(.*)/.exec(rootFunction)[1].toLowerCase() + ( isAsync ? '-async' : '' ) + '\n%c[%c'
|
|
1346
|
+
+ ((( functionName[0] == 'chatgpt' && functionName[1] == this[functionName[1]].name ) || // parent is chatgpt + names match or
|
|
1347
|
+
!isChatGptObjParent) // parent is chatgpt.obj
|
|
1348
|
+
? 'Function' : 'Alias of' ) + '%c: %c'
|
|
1349
|
+
+ rootFunction + '%c]',
|
|
1350
|
+
|
|
1351
|
+
// Styles
|
|
1352
|
+
baseFontStyles + 'font-weight: bold ; color:' + colors.cmdPrompt[+isDarkMode],
|
|
1353
|
+
baseFontStyles + 'font-weight: bold ;'
|
|
1354
|
+
+ 'color:' + colors[isChatGptObjParent ? 'methodName' : 'objName'][+isDarkMode],
|
|
1355
|
+
baseFontStyles + 'font-weight: ' + ( isChatGptObjParent ? 'initial' : 'bold' ) + ';'
|
|
1356
|
+
+ 'color:' + ( isChatGptObjParent ? 'initial' : colors.methodName[+isDarkMode] ),
|
|
1357
|
+
baseFontStyles + 'font-weight: ' + ( isChatGptObjParent ? 'bold' : 'initial' ) + ';'
|
|
1358
|
+
+ 'color:' + ( isChatGptObjParent ? colors.entryType[+isDarkMode] : 'initial' ),
|
|
1359
|
+
baseFontStyles + 'font-weight: ' + ( isChatGptObjParent ? 'initial' : 'bold' ) + ';'
|
|
1360
|
+
+ 'color:' + ( isChatGptObjParent ? 'initial' : colors.entryType[+isDarkMode] ),
|
|
1361
|
+
baseFontStyles + ( isChatGptObjParent ? 'font-style: italic' : 'font-weight: initial' ) + ';'
|
|
1362
|
+
+ 'color:' + ( isChatGptObjParent ? colors.srcMethod[+isDarkMode] : 'initial' ),
|
|
1363
|
+
baseFontStyles + ( isChatGptObjParent ? 'font-weight: initial' : 'font-style: italic' ) + ';'
|
|
1364
|
+
+ 'color:' + ( isChatGptObjParent ? 'initial' : colors.srcMethod[+isDarkMode] ),
|
|
1365
|
+
isChatGptObjParent ? '' : ( baseFontStyles + 'color: initial ; font-weight: initial' ));
|
|
1366
|
+
}
|
|
1367
|
+
},
|
|
1368
|
+
|
|
1369
|
+
randomFloat: function() {
|
|
1370
|
+
// * Generates a random, cryptographically secure value between 0 (inclusive) & 1 (exclusive)
|
|
1371
|
+
const crypto = window.crypto || window.msCrypto;
|
|
1372
|
+
return crypto.getRandomValues(new Uint32Array(1))[0] / 0xFFFFFFFF;
|
|
1373
|
+
},
|
|
1374
|
+
|
|
1375
|
+
refactor: function() { chatgpt.code.refactor(); },
|
|
1376
|
+
|
|
1377
|
+
regenerate: function() {
|
|
1378
|
+
for (const formButton of document.querySelectorAll('form button')) {
|
|
1379
|
+
if (formButton.textContent.toLowerCase().includes('regenerate')) {
|
|
1380
|
+
formButton.click(); return;
|
|
1381
|
+
}}},
|
|
1382
|
+
|
|
1383
|
+
renderHTML: function(node) {
|
|
1384
|
+
const reTags = /<([a-z\d]+)\b([^>]*)>([\s\S]*?)<\/\1>/g,
|
|
1385
|
+
reAttributes = /(\S+)=['"]?((?:.(?!['"]?\s+\S+=|[>']))+.)['"]?/g,
|
|
1386
|
+
nodeContent = node.childNodes;
|
|
1387
|
+
|
|
1388
|
+
// Preserve consecutive spaces + line breaks
|
|
1389
|
+
if (!this.renderHTML.preWrapSet) {
|
|
1390
|
+
node.style.whiteSpace = 'pre-wrap'; this.renderHTML.preWrapSet = true;
|
|
1391
|
+
setTimeout(() => { this.renderHTML.preWrapSet = false; }, 100);
|
|
1392
|
+
}
|
|
1393
|
+
|
|
1394
|
+
// Process child nodes
|
|
1395
|
+
for (const childNode of nodeContent) {
|
|
1396
|
+
|
|
1397
|
+
// Process text node
|
|
1398
|
+
if (childNode.nodeType == Node.TEXT_NODE) {
|
|
1399
|
+
const text = childNode.nodeValue,
|
|
1400
|
+
elems = Array.from(text.matchAll(reTags));
|
|
1401
|
+
|
|
1402
|
+
// Process 1st element to render
|
|
1403
|
+
if (elems.length > 0) {
|
|
1404
|
+
const elem = elems[0],
|
|
1405
|
+
[tagContent, tagName, tagAttributes, tagText] = elem.slice(0, 4),
|
|
1406
|
+
tagNode = document.createElement(tagName); tagNode.textContent = tagText;
|
|
1407
|
+
|
|
1408
|
+
// Extract/set attributes
|
|
1409
|
+
const attributes = Array.from(tagAttributes.matchAll(reAttributes));
|
|
1410
|
+
attributes.forEach(attribute => {
|
|
1411
|
+
const name = attribute[1], value = attribute[2].replace(/['"]/g, '');
|
|
1412
|
+
tagNode.setAttribute(name, value);
|
|
1413
|
+
});
|
|
1414
|
+
|
|
1415
|
+
const renderedNode = this.renderHTML(tagNode); // render child elements of newly created node
|
|
1416
|
+
|
|
1417
|
+
// Insert newly rendered node
|
|
1418
|
+
const beforeTextNode = document.createTextNode(text.substring(0, elem.index)),
|
|
1419
|
+
afterTextNode = document.createTextNode(text.substring(elem.index + tagContent.length));
|
|
1420
|
+
|
|
1421
|
+
// Replace text node with processed nodes
|
|
1422
|
+
node.replaceChild(beforeTextNode, childNode);
|
|
1423
|
+
node.insertBefore(renderedNode, beforeTextNode.nextSibling);
|
|
1424
|
+
node.insertBefore(afterTextNode, renderedNode.nextSibling);
|
|
1425
|
+
}
|
|
1426
|
+
|
|
1427
|
+
// Process element nodes recursively
|
|
1428
|
+
} else if (childNode.nodeType == Node.ELEMENT_NODE) this.renderHTML(childNode);
|
|
1429
|
+
}
|
|
1430
|
+
|
|
1431
|
+
return node; // if assignment used
|
|
1432
|
+
},
|
|
1433
|
+
|
|
1434
|
+
resend: async function() { chatgpt.send(await chatgpt.getChatData('latest', 'msg', 'user', 'latest')); },
|
|
1435
|
+
|
|
1436
|
+
response: {
|
|
1437
|
+
get: function() {
|
|
1438
|
+
// * Returns response via DOM by index arg if OpenAI chat page is active, otherwise uses API w/ following args:
|
|
1439
|
+
// chatToGet = index|title|id of chat to get (defaults to latest if '' unpassed)
|
|
1440
|
+
// responseToGet = index of response to get (defaults to latest if '' unpassed)
|
|
1441
|
+
// regenResponseToGet = index of regenerated response to get (defaults to latest if '' unpassed)
|
|
1442
|
+
|
|
1443
|
+
if (window.location.href.startsWith('https://chat.openai.com/c/'))
|
|
1444
|
+
return this.getFromDOM.apply(null, arguments);
|
|
1445
|
+
else return this.getFromAPI.apply(null, arguments);
|
|
1446
|
+
},
|
|
1447
|
+
|
|
1448
|
+
getFromAPI: function(chatToGet, responseToGet) {
|
|
1449
|
+
// chatToGet = index|title|id of chat to get (defaults to latest if '' or unpassed)
|
|
1450
|
+
// responseToGet = index of response to get (defaults to latest if '' or unpassed)
|
|
1451
|
+
|
|
1452
|
+
chatToGet = chatToGet || 'latest'; responseToGet = responseToGet || 'latest';
|
|
1453
|
+
return chatgpt.getChatData(chatToGet, 'msg', 'chatgpt', responseToGet);
|
|
1454
|
+
},
|
|
1455
|
+
|
|
1456
|
+
getFromDOM: function(pos) {
|
|
1457
|
+
const responseDivs = document.querySelectorAll('div[data-testid*="conversation-turn"]:nth-child(odd)'),
|
|
1458
|
+
strPos = pos.toString().toLowerCase();
|
|
1459
|
+
let response = '';
|
|
1460
|
+
if (responseDivs.length) {
|
|
1461
|
+
if (/last|final/.test(strPos)) // get last response
|
|
1462
|
+
response = responseDivs[responseDivs.length - 1].textContent;
|
|
1463
|
+
else { // get nth response
|
|
1464
|
+
const nthOfResponse = (
|
|
1465
|
+
|
|
1466
|
+
// Calculate base number
|
|
1467
|
+
Number.isInteger(pos) ? pos : // do nothing for integers
|
|
1468
|
+
/^\d+/.test(strPos) ? /^\d+/.exec(strPos)[0] : // extract first digits for strings w/ them
|
|
1469
|
+
( // convert words to integers for digitless strings
|
|
1470
|
+
/^(?:1|one|fir)(?:st)?$/.test(strPos) ? 1
|
|
1471
|
+
: /^(?:2|tw(?:o|en|el(?:ve|f))|seco)(?:nd|t[yi])?(?:e?th)?$/.test(strPos) ? 2
|
|
1472
|
+
: /^(?:3|th(?:ree|ir?))(?:rd|teen|t[yi])?(?:e?th)?$/.test(strPos) ? 3
|
|
1473
|
+
: /^(?:4|fou?r)(?:teen|t[yi])?(?:e?th)?$/.test(strPos) ? 4
|
|
1474
|
+
: /^(?:5|fi(?:ve|f))(?:teen|t[yi])?(?:e?th)?$/.test(strPos) ? 5
|
|
1475
|
+
: /^(?:6|six)(?:teen|t[yi])?(?:e?th)?$/.test(strPos) ? 6
|
|
1476
|
+
: /^(?:7|seven)(?:teen|t[yi])?(?:e?th)?$/.test(strPos) ? 7
|
|
1477
|
+
: /^(?:8|eight?)(?:teen|t[yi])?(?:e?th)?$/.test(strPos) ? 8
|
|
1478
|
+
: /^(?:9|nine?)(?:teen|t[yi])?(?:e?th)?$/.test(strPos) ? 9
|
|
1479
|
+
: /^(?:10|ten)(?:th)?$/.test(strPos) ? 10 : 1 )
|
|
1480
|
+
|
|
1481
|
+
// Transform base number if suffixed
|
|
1482
|
+
* ( /(ty|ieth)$/.test(strPos) ? 10 : 1 ) // x 10 if -ty/ieth
|
|
1483
|
+
+ ( /teen(th)?$/.test(strPos) ? 10 : 0 ) // + 10 if -teen/teenth
|
|
1484
|
+
|
|
1485
|
+
);
|
|
1486
|
+
response = responseDivs[nthOfResponse - 1].textContent;
|
|
1487
|
+
}
|
|
1488
|
+
response = response.replace(/^ChatGPTChatGPT/, ''); // strip sender name
|
|
1489
|
+
}
|
|
1490
|
+
return response;
|
|
1491
|
+
},
|
|
1492
|
+
|
|
1493
|
+
getLast: function() { return chatgpt.getChatData('active', 'msg', 'chatgpt', 'latest'); },
|
|
1494
|
+
|
|
1495
|
+
regenerate: function() {
|
|
1496
|
+
for (const formButton of document.querySelectorAll('form button')) {
|
|
1497
|
+
if (formButton.textContent.toLowerCase().includes('regenerate')) {
|
|
1498
|
+
formButton.click(); return;
|
|
1499
|
+
}}},
|
|
1500
|
+
|
|
1501
|
+
stopGenerating: function() {
|
|
1502
|
+
for (const svg of document.querySelectorAll('form button svg')) {
|
|
1503
|
+
if (svg.querySelector('path[d*="2 0 0 1 2"]')) {
|
|
1504
|
+
svg.parentNode.click(); return;
|
|
1505
|
+
}}}
|
|
1506
|
+
},
|
|
1507
|
+
|
|
1508
|
+
reviewCode: function() { chatgpt.code.review(); },
|
|
1509
|
+
|
|
1510
|
+
scrollToBottom: function() {
|
|
1511
|
+
try { document.querySelector('button[class*="cursor"][class*="bottom"]').click(); }
|
|
1512
|
+
catch (err) { console.error('', err); }
|
|
1513
|
+
},
|
|
1514
|
+
|
|
1515
|
+
send: function(msg, method='') {
|
|
1516
|
+
for (let i = 0; i < arguments.length; i++) if (typeof arguments[i] !== 'string')
|
|
1517
|
+
return console.error(`Argument ${ i + 1 } must be a string!`);
|
|
1518
|
+
const textArea = document.querySelector('form textarea'),
|
|
1519
|
+
sendButton = document.querySelector('form button[class*="bottom"]');
|
|
1520
|
+
textArea.value = msg;
|
|
1521
|
+
textArea.dispatchEvent(new Event('input', { bubbles: true })); // enable send button
|
|
1522
|
+
const delaySend = setInterval(() => {
|
|
1523
|
+
if (!sendButton?.hasAttribute('disabled')) { // send msg
|
|
1524
|
+
method.toLowerCase() == 'click' || chatgpt.browser.isMobile() ? sendButton.click()
|
|
1525
|
+
: textArea.dispatchEvent(new KeyboardEvent('keydown', { keyCode: 13, bubbles: true }));
|
|
1526
|
+
clearInterval(delaySend);
|
|
1527
|
+
}
|
|
1528
|
+
}, 25);
|
|
1529
|
+
},
|
|
1530
|
+
|
|
1531
|
+
sendInNewChat: function(msg) {
|
|
1532
|
+
if (typeof msg !== 'string') return console.error('Message must be a string!');
|
|
1533
|
+
for (const navLink of document.querySelectorAll('nav a')) {
|
|
1534
|
+
if (/(new|clear) chat/i.test(navLink.text)) {
|
|
1535
|
+
navLink.click(); break;
|
|
1536
|
+
}} setTimeout(() => { chatgpt.send(msg); }, 500);
|
|
1537
|
+
},
|
|
1538
|
+
|
|
1539
|
+
settings: {
|
|
1540
|
+
scheme: {
|
|
1541
|
+
isDark: function() { return document.documentElement.classList.contains('dark'); },
|
|
1542
|
+
isLight: function() { return document.documentElement.classList.contains('light'); },
|
|
1543
|
+
set: function(value) {
|
|
1544
|
+
|
|
1545
|
+
// Validate value
|
|
1546
|
+
const validValues = ['dark', 'light', 'system'];
|
|
1547
|
+
if (!value) return console.error('Please specify a scheme value!');
|
|
1548
|
+
if (!validValues.includes(value)) return console.error(`Invalid scheme value. Valid values are [${ validValues }]`);
|
|
1549
|
+
|
|
1550
|
+
// Determine scheme to set
|
|
1551
|
+
let schemeToSet = value;
|
|
1552
|
+
if (value == 'system') schemeToSet = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
|
|
1553
|
+
localStorage.setItem('theme', value);
|
|
1554
|
+
console.info(`Scheme set to ${ value.toUpperCase() }.`);
|
|
1555
|
+
|
|
1556
|
+
// Toggle scheme if necessary
|
|
1557
|
+
if (!document.documentElement.classList.contains(schemeToSet)) this.toggle();
|
|
1558
|
+
},
|
|
1559
|
+
toggle: function() {
|
|
1560
|
+
const [schemeToRemove, schemeToAdd] = this.isDark() ? ['dark', 'light'] : ['light', 'dark'];
|
|
1561
|
+
document.documentElement.classList.replace(schemeToRemove, schemeToAdd);
|
|
1562
|
+
document.documentElement.style.colorScheme = schemeToAdd;
|
|
1563
|
+
localStorage.setItem('theme', schemeToAdd);
|
|
1564
|
+
}
|
|
1565
|
+
}
|
|
1566
|
+
},
|
|
1567
|
+
|
|
1568
|
+
sentiment: async function(text, entity) {
|
|
1569
|
+
for (let i = 0; i < arguments.length; i++) if (typeof arguments[i] !== 'string')
|
|
1570
|
+
return console.error(`Argument ${ i + 1 } must be a string.`);
|
|
1571
|
+
chatgpt.send('What is the sentiment of the following text'
|
|
1572
|
+
+ ( entity ? ` towards the entity ${ entity },` : '')
|
|
1573
|
+
+ ' from strongly negative to strongly positive?\n\n' + text );
|
|
1574
|
+
console.info('Analyzing sentiment...');
|
|
1575
|
+
await chatgpt.isIdle();
|
|
1576
|
+
return chatgpt.getChatData('active', 'msg', 'chatgpt', 'latest');
|
|
1577
|
+
},
|
|
1578
|
+
|
|
1579
|
+
setScheme: function(value) { chatgpt.settings.scheme.set(value); },
|
|
1580
|
+
|
|
1581
|
+
shareChat: function(chatToGet, method = 'clipboard') {
|
|
1582
|
+
// chatToGet = index|title|id of chat to get (defaults to latest if '' or unpassed)
|
|
1583
|
+
// method = [ 'alert'|'clipboard' ] (defaults to 'clipboard' if '' or unpassed)
|
|
1584
|
+
|
|
1585
|
+
const validMethods = ['alert', 'notify', 'notification', 'clipboard', 'copy'];
|
|
1586
|
+
if (!validMethods.includes(method)) return console.error(
|
|
1587
|
+
'Invalid method \'' + method + '\' passed. Valid methods are [' + validMethods + '].');
|
|
1588
|
+
|
|
1589
|
+
const getChatNode = token => {
|
|
1590
|
+
return new Promise((resolve, reject) => {
|
|
1591
|
+
const xhr = new XMLHttpRequest();
|
|
1592
|
+
chatgpt.getChatData(chatToGet).then(chat => {
|
|
1593
|
+
xhr.open('GET', `${ endpoints.openAI.chat }/${ chat.id }`, true);
|
|
1594
|
+
xhr.setRequestHeader('Content-Type', 'application/json');
|
|
1595
|
+
xhr.setRequestHeader('Authorization', 'Bearer ' + token);
|
|
1596
|
+
xhr.onload = () => {
|
|
1597
|
+
if (xhr.status !== 200)
|
|
1598
|
+
return reject('🤖 chatgpt.js >> Request failed. Cannot retrieve chat node.');
|
|
1599
|
+
return resolve(JSON.parse(xhr.responseText).current_node); // chat messages until now
|
|
1600
|
+
};
|
|
1601
|
+
xhr.send();
|
|
1602
|
+
});});};
|
|
1603
|
+
|
|
1604
|
+
const makeChatToShare = (token, node) => {
|
|
1605
|
+
return new Promise((resolve, reject) => {
|
|
1606
|
+
const xhr = new XMLHttpRequest();
|
|
1607
|
+
chatgpt.getChatData(chatToGet).then(chat => {
|
|
1608
|
+
xhr.open('POST', endpoints.openAI.share_create, true);
|
|
1609
|
+
xhr.setRequestHeader('Content-Type', 'application/json');
|
|
1610
|
+
xhr.setRequestHeader('Authorization', 'Bearer ' + token);
|
|
1611
|
+
xhr.onload = () => {
|
|
1612
|
+
if (xhr.status !== 200)
|
|
1613
|
+
return reject('🤖 chatgpt.js >> Request failed. Cannot initialize share chat.');
|
|
1614
|
+
return resolve(JSON.parse(xhr.responseText)); // return untouched data
|
|
1615
|
+
};
|
|
1616
|
+
xhr.send(JSON.stringify({ // request body
|
|
1617
|
+
current_node_id: node, // by getChatNode
|
|
1618
|
+
conversation_id: chat.id, // current chat id
|
|
1619
|
+
is_anonymous: true // show user name in the conversation or not
|
|
1620
|
+
}));
|
|
1621
|
+
});});};
|
|
1622
|
+
|
|
1623
|
+
const confirmShareChat = (token, data) => {
|
|
1624
|
+
return new Promise((resolve, reject) => {
|
|
1625
|
+
const xhr = new XMLHttpRequest();
|
|
1626
|
+
xhr.open('PATCH', `${ endpoints.openAI.share }/${ data.share_id }`, true);
|
|
1627
|
+
xhr.setRequestHeader('Content-Type', 'application/json');
|
|
1628
|
+
xhr.setRequestHeader('Authorization', 'Bearer ' + token);
|
|
1629
|
+
xhr.onload = () => {
|
|
1630
|
+
if (xhr.status !== 200)
|
|
1631
|
+
return reject('🤖 chatgpt.js >> Request failed. Cannot share chat.');
|
|
1632
|
+
console.info(`Chat shared at '${ data.share_url }'`);
|
|
1633
|
+
return resolve(); // the response has nothing useful
|
|
1634
|
+
};
|
|
1635
|
+
xhr.send(JSON.stringify({ // request body
|
|
1636
|
+
share_id: data.share_id,
|
|
1637
|
+
highlighted_message_id: data.highlighted_message_id,
|
|
1638
|
+
title: data.title,
|
|
1639
|
+
is_public: true, // must be true or it'll cause a 404 error
|
|
1640
|
+
is_visible: data.is_visible,
|
|
1641
|
+
is_anonymous: data.is_anonymous
|
|
1642
|
+
}));
|
|
1643
|
+
});};
|
|
1644
|
+
|
|
1645
|
+
return new Promise(resolve => {
|
|
1646
|
+
chatgpt.getAccessToken().then(token => { // get access token
|
|
1647
|
+
getChatNode(token).then(node => { // get chat node
|
|
1648
|
+
makeChatToShare(token, node).then(data => {
|
|
1649
|
+
confirmShareChat(token, data).then(() => {
|
|
1650
|
+
if (['copy', 'clipboard'].includes(method)) navigator.clipboard.writeText(data.share_url);
|
|
1651
|
+
else chatgpt.alert('🚀 Share link created!',
|
|
1652
|
+
'"' + data.title + '" is available at: <a target="blank" rel="noopener" href="'
|
|
1653
|
+
+ data.share_url + '" >' + data.share_url + '</a>',
|
|
1654
|
+
[ function openLink() { window.open(data.share_url, '_blank', 'noopener'); },
|
|
1655
|
+
function copyLink() { navigator.clipboard.writeText(data.share_url); }]);
|
|
1656
|
+
resolve(data.share_url);
|
|
1657
|
+
});});});});});
|
|
1658
|
+
},
|
|
1659
|
+
|
|
1660
|
+
sidebar: {
|
|
1661
|
+
elements: [], observer: {},
|
|
1662
|
+
|
|
1663
|
+
activateObserver: function() {
|
|
1664
|
+
const chatHistoryNav = document.querySelector('nav'),
|
|
1665
|
+
firstButton = chatHistoryNav.querySelector('a');
|
|
1666
|
+
if (chatgpt.history.isOff()) // Hide enable history spam div
|
|
1667
|
+
try { firstButton.parentNode.nextElementSibling.style.display = 'none'; } catch (err) {}
|
|
1668
|
+
|
|
1669
|
+
// Stop the previous observer to preserve resources
|
|
1670
|
+
if (this.observer instanceof MutationObserver)
|
|
1671
|
+
try { this.observer.disconnect(); } catch (e) {}
|
|
1672
|
+
|
|
1673
|
+
if (!this.elements.length) return console.error('🤖 chatgpt.js >> No elements to append!');
|
|
1674
|
+
|
|
1675
|
+
let cssClasses;
|
|
1676
|
+
// Grab CSS from original website elements
|
|
1677
|
+
for (let navLink of document.querySelectorAll('nav a')) {
|
|
1678
|
+
if (/.*chat/.exec(navLink.text)[0]) {
|
|
1679
|
+
cssClasses = navLink.classList;
|
|
1680
|
+
navLink.parentNode.style.margin = '2px 0'; // add v-margins to ensure consistency across all inserted buttons
|
|
1681
|
+
break;
|
|
1682
|
+
}
|
|
1683
|
+
}
|
|
1684
|
+
|
|
1685
|
+
// Apply CSS to make the added elements look like they belong to the website
|
|
1686
|
+
this.elements.forEach(element => {
|
|
1687
|
+
element.setAttribute('class', cssClasses);
|
|
1688
|
+
element.style.maxHeight = element.style.minHeight = '44px'; // Fix the height of the element
|
|
1689
|
+
element.style.margin = '2px 0';
|
|
1690
|
+
});
|
|
1691
|
+
|
|
1692
|
+
const navBar = document.querySelector('nav');
|
|
1693
|
+
// Create MutationObserver instance
|
|
1694
|
+
this.observer = new MutationObserver(mutations => {
|
|
1695
|
+
mutations.forEach(mutation => {
|
|
1696
|
+
if ((mutation.type == 'childList' && mutation.addedNodes.length) ||
|
|
1697
|
+
(mutation.type == 'attributes' && mutation.attributeName == 'data-chatgptjs')) // check for trigger
|
|
1698
|
+
// Try to insert each element...
|
|
1699
|
+
this.elements.forEach(element => {
|
|
1700
|
+
// ...if it's not already present...
|
|
1701
|
+
if (!navBar.contains(element))
|
|
1702
|
+
try {
|
|
1703
|
+
// ...at the top of the sidebar
|
|
1704
|
+
navBar.insertBefore(element, navBar.querySelector('a').parentNode);
|
|
1705
|
+
} catch (err) { console.error(err); }
|
|
1706
|
+
});
|
|
1707
|
+
});
|
|
1708
|
+
});
|
|
1709
|
+
|
|
1710
|
+
this.observer.observe(document.documentElement, { childList: true, subtree: true, attributes: true });
|
|
1711
|
+
},
|
|
1712
|
+
|
|
1713
|
+
append: function(element, attrs = {}) {
|
|
1714
|
+
// element = 'button' | 'dropdown' REQUIRED (no default value)
|
|
1715
|
+
// attrs = { ... }
|
|
1716
|
+
// attrs for 'button': 'icon' = src string, 'label' = string, 'onclick' = function
|
|
1717
|
+
// attrs for 'dropdown': 'items' = [ { text: string, value: string }, ... ] array of objects
|
|
1718
|
+
// where 'text' is the displayed text of the option and 'value' is the value of the option
|
|
1719
|
+
const validElements = ['button', 'dropdown'];
|
|
1720
|
+
if (!element || typeof element !== 'string') // Element not passed or invalid type
|
|
1721
|
+
return console.error('🤖 chatgpt.js >> Please supply a valid string element name!');
|
|
1722
|
+
element = element.toLowerCase();
|
|
1723
|
+
if (!validElements.includes(element)) // Element not in list
|
|
1724
|
+
return console.error(`🤖 chatgpt.js >> Invalid element! Valid elements are [${validElements}]`);
|
|
1725
|
+
|
|
1726
|
+
const newElement = document.createElement(element == 'dropdown' ? 'select' : element);
|
|
1727
|
+
newElement.id = Math.floor(chatgpt.randomFloat() * 1000000) + Date.now(); // Add random id to the element
|
|
1728
|
+
|
|
1729
|
+
if (element == 'button') {
|
|
1730
|
+
newElement.textContent = attrs?.label && typeof attrs.label == 'string'
|
|
1731
|
+
? attrs.label
|
|
1732
|
+
: 'chatgpt.js button';
|
|
1733
|
+
|
|
1734
|
+
const icon = document.createElement('img');
|
|
1735
|
+
icon.src = attrs?.icon && typeof attrs.icon == 'string' // Can also be base64 encoded image string
|
|
1736
|
+
? attrs.icon // Add icon to button element if given, else default one
|
|
1737
|
+
: ( endpoints.assets + '/starters/chrome/extension/icons/icon128.png' );
|
|
1738
|
+
icon.width = 18;
|
|
1739
|
+
newElement.insertBefore(icon, newElement.firstChild);
|
|
1740
|
+
|
|
1741
|
+
newElement.onclick = attrs?.onclick && typeof attrs.onclick == 'function'
|
|
1742
|
+
? attrs.onclick
|
|
1743
|
+
: function() {};
|
|
1744
|
+
}
|
|
1745
|
+
|
|
1746
|
+
else if (element == 'dropdown') {
|
|
1747
|
+
if (!attrs?.items || // There no are options to add
|
|
1748
|
+
!Array.isArray(attrs.items) || // It's not an array
|
|
1749
|
+
!attrs.items.length) // The array is empty
|
|
1750
|
+
attrs.items = [{ text: '🤖 chatgpt.js option', value: 'chatgpt.js option value' }]; // Set default dropdown entry
|
|
1751
|
+
|
|
1752
|
+
if (!attrs.items.every(el => typeof el == 'object')) // The entries of the array are not objects
|
|
1753
|
+
return console.error('\'items\' must be an array of objects!');
|
|
1754
|
+
|
|
1755
|
+
attrs.items.forEach(item => {
|
|
1756
|
+
const optionElement = document.createElement('option');
|
|
1757
|
+
optionElement.textContent = item?.text;
|
|
1758
|
+
optionElement.value = item?.value;
|
|
1759
|
+
newElement.add(optionElement);
|
|
1760
|
+
});
|
|
1761
|
+
}
|
|
1762
|
+
|
|
1763
|
+
|
|
1764
|
+
// Fix for blank background on dropdown elements
|
|
1765
|
+
if (element == 'dropdown') newElement.style.backgroundColor = 'var(--gray-900, rgb(32, 33, 35))';
|
|
1766
|
+
|
|
1767
|
+
this.elements.push(newElement);
|
|
1768
|
+
this.activateObserver();
|
|
1769
|
+
document.body.setAttribute('data-chatgptjs', 'observer-trigger'); // add attribute to trigger the observer
|
|
1770
|
+
|
|
1771
|
+
return newElement.id; // Return the element id
|
|
1772
|
+
},
|
|
1773
|
+
|
|
1774
|
+
hide: function() { this.isOn() ? this.toggle() : console.info('Sidebar already hidden!'); },
|
|
1775
|
+
show: function() { this.isOff() ? this.toggle() : console.info('Sidebar already shown!'); },
|
|
1776
|
+
isOff: function() { return !this.isOn(); },
|
|
1777
|
+
isOn: function() {
|
|
1778
|
+
return chatgpt.browser.isMobile() ?
|
|
1779
|
+
document.documentElement.style.overflow == 'hidden'
|
|
1780
|
+
: document.querySelector('#__next > div > div').style.visibility != 'hidden';
|
|
1781
|
+
},
|
|
1782
|
+
|
|
1783
|
+
toggle: function() {
|
|
1784
|
+
const isMobileDevice = chatgpt.browser.isMobile(),
|
|
1785
|
+
navBtnSelector = isMobileDevice ? '#__next button' : 'main button' ,
|
|
1786
|
+
isToggleBtn = isMobileDevice ? () => true // since 1st one is toggle
|
|
1787
|
+
: btn => Array.from(btn.querySelectorAll('*'))
|
|
1788
|
+
.some(child => child.style.transform.includes('translateY'));
|
|
1789
|
+
for (const btn of document.querySelectorAll(navBtnSelector))
|
|
1790
|
+
if (isToggleBtn(btn)) { btn.click(); return; }
|
|
1791
|
+
}
|
|
1792
|
+
},
|
|
1793
|
+
|
|
1794
|
+
startNewChat: function() {
|
|
1795
|
+
for (const navLink of document.querySelectorAll('nav a')) {
|
|
1796
|
+
if (/(new|clear) chat/i.test(navLink.text)) {
|
|
1797
|
+
navLink.click(); return;
|
|
1798
|
+
}}},
|
|
1799
|
+
|
|
1800
|
+
stop: function() { this.response.stopGenerating(); },
|
|
1801
|
+
|
|
1802
|
+
suggest: async function(ideaType, details) {
|
|
1803
|
+
if (!ideaType) return console.error('ideaType (1st argument) not supplied'
|
|
1804
|
+
+ '(e.g. \'gifts\', \'names\', \'recipes\', etc.)');
|
|
1805
|
+
for (let i = 0; i < arguments.length; i++) if (typeof arguments[i] !== 'string')
|
|
1806
|
+
return console.error(`Argument ${ i + 1 } must be a string.`);
|
|
1807
|
+
chatgpt.send('Suggest some names. ' + ( details || '' ));
|
|
1808
|
+
console.info(`Creating ${ ideaType }...`);
|
|
1809
|
+
await chatgpt.isIdle();
|
|
1810
|
+
return chatgpt.getChatData('active', 'msg', 'chatgpt', 'latest');
|
|
1811
|
+
},
|
|
1812
|
+
|
|
1813
|
+
speak: function(msg, options = {}) {
|
|
1814
|
+
// Usage example: chatgpt.speak(await chatgpt.getLastResponse(), { voice: 1, pitch: 2, speed: 3 })
|
|
1815
|
+
// options.voice = index of voices available on user device
|
|
1816
|
+
// options.pitch = float for pitch of speech from 0 to 2
|
|
1817
|
+
// options.speed = float for rate of speech from 0.1 to 10
|
|
1818
|
+
|
|
1819
|
+
const { voice = 2, pitch = 2, speed = 1.1 } = options;
|
|
1820
|
+
|
|
1821
|
+
// Validate args
|
|
1822
|
+
if (typeof msg !== 'string') return console.error('Message must be a string!');
|
|
1823
|
+
for (let key in options) {
|
|
1824
|
+
const value = options[key];
|
|
1825
|
+
if (typeof value !== 'number' && !/^\d+$/.test(value))
|
|
1826
|
+
return console.error(`Invalid ${ key } index '${ value }'. Must be a number!`);
|
|
1827
|
+
}
|
|
1828
|
+
|
|
1829
|
+
try { // to speak msg using {options}
|
|
1830
|
+
const voices = speechSynthesis.getVoices(),
|
|
1831
|
+
utterance = new SpeechSynthesisUtterance();
|
|
1832
|
+
utterance.text = msg;
|
|
1833
|
+
utterance.voice = voices[voice];
|
|
1834
|
+
utterance.pitch = pitch;
|
|
1835
|
+
utterance.rate = speed;
|
|
1836
|
+
speechSynthesis.speak(utterance);
|
|
1837
|
+
} catch (err) { console.error( err); }
|
|
1838
|
+
},
|
|
1839
|
+
|
|
1840
|
+
summarize: async function(text) {
|
|
1841
|
+
if (!text) return console.error('Text (1st) argument not supplied. Pass some text!');
|
|
1842
|
+
if (typeof text !== 'string') return console.error('Text argument must be a string!');
|
|
1843
|
+
chatgpt.send('Summarize the following text:\n\n' + text);
|
|
1844
|
+
console.info('Summarizing text...');
|
|
1845
|
+
await chatgpt.isIdle();
|
|
1846
|
+
return chatgpt.getChatData('active', 'msg', 'chatgpt', 'latest');
|
|
1847
|
+
},
|
|
1848
|
+
|
|
1849
|
+
toggleScheme: function() { chatgpt.settings.scheme.toggle(); },
|
|
1850
|
+
|
|
1851
|
+
translate: async function(text, outputLang) {
|
|
1852
|
+
if (!text) return console.error('Text (1st) argument not supplied. Pass some text!');
|
|
1853
|
+
if (!outputLang) return console.error('outputLang (2nd) argument not supplied. Pass a language!');
|
|
1854
|
+
for (let i = 0; i < arguments.length; i++) if (typeof arguments[i] !== 'string')
|
|
1855
|
+
return console.error(`Argument ${ i + 1 } must be a string!`);
|
|
1856
|
+
chatgpt.send('Translate the following text to ' + outputLang
|
|
1857
|
+
+ '. Only reply with the translation.\n\n' + text);
|
|
1858
|
+
console.info('Translating text...');
|
|
1859
|
+
await chatgpt.isIdle();
|
|
1860
|
+
return chatgpt.getChatData('active', 'msg', 'chatgpt', 'latest');
|
|
1861
|
+
},
|
|
1862
|
+
|
|
1863
|
+
unminify: function() { chatgpt.code.unminify(); },
|
|
1864
|
+
|
|
1865
|
+
uuidv4: function() {
|
|
1866
|
+
let d = new Date().getTime(); // get current timestamp in ms (to ensure UUID uniqueness)
|
|
1867
|
+
const uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
|
|
1868
|
+
const r = ( // generate random nibble
|
|
1869
|
+
( d + (window.crypto.getRandomValues(new Uint32Array(1))[0] / (Math.pow(2, 32) - 1))*16)%16 | 0 );
|
|
1870
|
+
d = Math.floor(d/16); // correspond each UUID digit to unique 4-bit chunks of timestamp
|
|
1871
|
+
return ( c == 'x' ? r : (r&0x3|0x8) ).toString(16); // generate random hexadecimal digit
|
|
1872
|
+
});
|
|
1873
|
+
return uuid;
|
|
1874
|
+
},
|
|
1875
|
+
|
|
1876
|
+
writeCode: function() { chatgpt.code.write(); }
|
|
1877
|
+
};
|
|
1878
|
+
|
|
1879
|
+
chatgpt.scheme = { ...chatgpt.settings.scheme }; // copy `chatgpt.settings.scheme` methods into `chatgpt.scheme`
|
|
1880
|
+
|
|
1881
|
+
// Create chatgpt.[actions]Button(identifier) functions
|
|
1882
|
+
const buttonActions = ['click', 'get'], targetTypes = [ 'button', 'link', 'div', 'response' ];
|
|
1883
|
+
for (const buttonAction of buttonActions) {
|
|
1884
|
+
chatgpt[buttonAction + 'Button'] = function handleButton(buttonIdentifier) {
|
|
1885
|
+
const button = /^[.#]/.test(buttonIdentifier) ? document.querySelector(buttonIdentifier)
|
|
1886
|
+
: /send/i.test(buttonIdentifier) ? document.querySelector('form button[class*="bottom"]')
|
|
1887
|
+
: /scroll/i.test(buttonIdentifier) ? document.querySelector('button[class*="cursor"]')
|
|
1888
|
+
: (function() { // get via text content
|
|
1889
|
+
for (const button of document.querySelectorAll('button')) { // try buttons
|
|
1890
|
+
if (button.textContent.toLowerCase().includes(buttonIdentifier.toLowerCase())) {
|
|
1891
|
+
return button; }}
|
|
1892
|
+
for (const navLink of document.querySelectorAll('nav a')) { // try nav links if no button
|
|
1893
|
+
if (navLink.textContent.toLowerCase().includes(buttonIdentifier.toLowerCase())) {
|
|
1894
|
+
return navLink; }}})();
|
|
1895
|
+
if (buttonAction == 'click') { button.click(); } else { return button; }
|
|
1896
|
+
};
|
|
1897
|
+
}
|
|
1898
|
+
|
|
1899
|
+
// Create alias functions
|
|
1900
|
+
const functionAliases = [
|
|
1901
|
+
['actAs', 'actas', 'act', 'become', 'persona', 'premadePrompt', 'preMadePrompt', 'prePrompt', 'preprompt', 'roleplay', 'rolePlay', 'rp'],
|
|
1902
|
+
['activateAutoRefresh', 'activateAutoRefresher', 'activateRefresher', 'activateSessionRefresher',
|
|
1903
|
+
'autoRefresh', 'autoRefresher', 'autoRefreshSession', 'refresher', 'sessionRefresher'],
|
|
1904
|
+
['deactivateAutoRefresh', 'deactivateAutoRefresher', 'deactivateRefresher', 'deactivateSessionRefresher'],
|
|
1905
|
+
['detectLanguage', 'getLanguage'],
|
|
1906
|
+
['executeCode', 'codeExecute'],
|
|
1907
|
+
['exportChat', 'chatExport', 'export'],
|
|
1908
|
+
['getLastPrompt', 'getLastQuery', 'getMyLastMsg', 'getMyLastQuery'],
|
|
1909
|
+
['getTextarea', 'getTextArea', 'getChatbox', 'getChatBox'],
|
|
1910
|
+
['isFullScreen', 'isFullscreen'],
|
|
1911
|
+
['logOut', 'logout', 'logOff', 'logoff', 'signOut', 'signout', 'signOff', 'signoff'],
|
|
1912
|
+
['minify', 'codeMinify', 'minifyCode'],
|
|
1913
|
+
['new', 'newChat', 'startNewChat'],
|
|
1914
|
+
['obfuscate', 'codeObfuscate', 'obfuscateCode'],
|
|
1915
|
+
['printAllFunctions', 'showAllFunctions'],
|
|
1916
|
+
['refactor', 'codeRefactor', 'refactorCode'],
|
|
1917
|
+
['refreshReply', 'regenerate', 'regenerateReply'],
|
|
1918
|
+
['refreshSession', 'sessionRefresh'],
|
|
1919
|
+
['renderHTML', 'renderHtml', 'renderLinks', 'renderTags'],
|
|
1920
|
+
['reviewCode', 'codeReview'],
|
|
1921
|
+
['send', 'sendChat', 'sendMsg'],
|
|
1922
|
+
['sendInNewChat', 'sendNewChat'],
|
|
1923
|
+
['sentiment', 'analyzeSentiment', 'sentimentAnalysis'],
|
|
1924
|
+
['stop', 'stopGenerating'],
|
|
1925
|
+
['suggest', 'suggestion', 'recommend'],
|
|
1926
|
+
['toggleAutoRefresh', 'toggleAutoRefresher', 'toggleRefresher', 'toggleSessionRefresher'],
|
|
1927
|
+
['toggleScheme', 'toggleMode'],
|
|
1928
|
+
['translate', 'translation', 'translator'],
|
|
1929
|
+
['unminify', 'unminifyCode', 'codeUnminify'],
|
|
1930
|
+
['writeCode', 'codeWrite']
|
|
1931
|
+
];
|
|
1932
|
+
const synonyms = [
|
|
1933
|
+
['account', 'acct'],
|
|
1934
|
+
['activate', 'turnOn'],
|
|
1935
|
+
['analyze', 'check', 'evaluate', 'review'],
|
|
1936
|
+
['ask', 'send', 'submit'],
|
|
1937
|
+
['chat', 'conversation', 'convo'],
|
|
1938
|
+
['data', 'details'],
|
|
1939
|
+
['deactivate', 'deActivate', 'turnOff'],
|
|
1940
|
+
['execute', 'interpret', 'interpreter', 'run'],
|
|
1941
|
+
['generating', 'generation'],
|
|
1942
|
+
['minify', 'uglify'],
|
|
1943
|
+
['refactor', 'rewrite'],
|
|
1944
|
+
['regenerate', 'regen'],
|
|
1945
|
+
['render', 'parse'],
|
|
1946
|
+
['reply', 'response'],
|
|
1947
|
+
['sentiment', 'attitude', 'emotion', 'feeling', 'opinion', 'perception'],
|
|
1948
|
+
['speak', 'say', 'speech', 'talk', 'tts'],
|
|
1949
|
+
['summarize', 'tldr'],
|
|
1950
|
+
['unminify', 'beautify', 'prettify', 'prettyPrint']
|
|
1951
|
+
];
|
|
1952
|
+
const camelCaser = (words) => {
|
|
1953
|
+
return words.map((word, index) => index === 0 || word == 's' ? word : word.charAt(0).toUpperCase() + word.slice(1)).join(''); };
|
|
1954
|
+
for (const prop in chatgpt) {
|
|
1955
|
+
|
|
1956
|
+
// Create new function for each alias
|
|
1957
|
+
for (const subAliases of functionAliases) {
|
|
1958
|
+
if (subAliases.includes(prop)) {
|
|
1959
|
+
if (subAliases.some(element => element.includes('.'))) {
|
|
1960
|
+
const nestedFunction = subAliases.find(element => element.includes('.')).split('.')[1];
|
|
1961
|
+
for (const nestAlias of subAliases) {
|
|
1962
|
+
if (/^(\w+)/.exec(nestAlias)[1] !== prop) { // don't alias og function
|
|
1963
|
+
chatgpt[nestAlias] = chatgpt[prop][nestedFunction]; // make new function, reference og one
|
|
1964
|
+
}}} else { // alias direct functions
|
|
1965
|
+
for (const dirAlias of subAliases) {
|
|
1966
|
+
if (dirAlias !== prop) { // don't alias og function
|
|
1967
|
+
chatgpt[dirAlias] = chatgpt[prop]; // make new function, reference og one
|
|
1968
|
+
}}}
|
|
1969
|
+
}}
|
|
1970
|
+
|
|
1971
|
+
do { // create new function per synonym per word per function
|
|
1972
|
+
var newFunctionsCreated = false;
|
|
1973
|
+
for (const funcName in chatgpt) {
|
|
1974
|
+
if (typeof chatgpt[funcName] == 'function') {
|
|
1975
|
+
const funcWords = funcName.split(/(?=[A-Zs])/); // split function name into constituent words
|
|
1976
|
+
for (const funcWord of funcWords) {
|
|
1977
|
+
const synonymValues = [].concat(...synonyms // flatten into single array w/ word's synonyms
|
|
1978
|
+
.filter(arr => arr.includes(funcWord.toLowerCase())) // filter in relevant synonym sub-arrays
|
|
1979
|
+
.map(arr => arr.filter(synonym => synonym !== funcWord.toLowerCase()))); // filter out matching word
|
|
1980
|
+
for (const synonym of synonymValues) { // create function per synonym
|
|
1981
|
+
const newFuncName = camelCaser(funcWords.map(word => (word == funcWord ? synonym : word)));
|
|
1982
|
+
if (!chatgpt[newFuncName]) { // don't alias existing functions
|
|
1983
|
+
chatgpt[newFuncName] = chatgpt[funcName]; // make new function, reference og one
|
|
1984
|
+
newFunctionsCreated = true;
|
|
1985
|
+
}}}}}} while (newFunctionsCreated); // loop over new functions to encompass all variations
|
|
1986
|
+
}
|
|
1987
|
+
|
|
1988
|
+
// Prefix console logs w/ '🤖 chatgpt.js >> '
|
|
1989
|
+
const consolePrefix = '🤖 chatgpt.js >> ', ogError = console.error, ogInfo = console.info;
|
|
1990
|
+
console.error = (...args) => {
|
|
1991
|
+
if (!args[0].startsWith(consolePrefix)) ogError(consolePrefix + args[0], ...args.slice(1));
|
|
1992
|
+
else ogError(...args);
|
|
1993
|
+
};
|
|
1994
|
+
console.info = (msg) => {
|
|
1995
|
+
if (!msg.startsWith(consolePrefix)) ogInfo(consolePrefix + msg);
|
|
1996
|
+
else ogInfo(msg);
|
|
1997
|
+
};
|
|
1998
|
+
|
|
1999
|
+
// Export chatgpt object
|
|
2000
|
+
try { window.chatgpt = chatgpt; } catch (err) {} // for Greasemonkey
|
|
2001
|
+
try { module.exports = chatgpt; } catch (err) {} // for CommonJS
|