@kudoai/chatgpt.js 2.9.1 → 2.9.3

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/docs/USERGUIDE.md CHANGED
@@ -148,7 +148,7 @@
148
148
 
149
149
  ```js
150
150
  (async () => {
151
- await import('https://cdn.jsdelivr.net/npm/@kudoai/chatgpt.js@2.9.1/dist/chatgpt.min.js');
151
+ await import('https://cdn.jsdelivr.net/npm/@kudoai/chatgpt.js@2.9.3/dist/chatgpt.min.js');
152
152
  // Your code here...
153
153
  })();
154
154
  ```
@@ -157,7 +157,7 @@
157
157
 
158
158
  ```js
159
159
  var xhr = new XMLHttpRequest();
160
- xhr.open('GET', 'https://cdn.jsdelivr.net/npm/@kudoai/chatgpt.js@2.9.1/dist/chatgpt.min.js');
160
+ xhr.open('GET', 'https://cdn.jsdelivr.net/npm/@kudoai/chatgpt.js@2.9.3/dist/chatgpt.min.js');
161
161
  xhr.onload = function () {
162
162
  if (xhr.status === 200) {
163
163
  var chatgptJS = document.createElement('script');
@@ -179,7 +179,7 @@ function yourCode() {
179
179
 
180
180
  ```js
181
181
  ...
182
- // @require https://cdn.jsdelivr.net/npm/@kudoai/chatgpt.js@2.9.1/dist/chatgpt.min.js
182
+ // @require https://cdn.jsdelivr.net/npm/@kudoai/chatgpt.js@2.9.3/dist/chatgpt.min.js
183
183
  // ==/UserScript==
184
184
 
185
185
  // Your code here...
@@ -1854,7 +1854,7 @@ chatgpt.sidebar.toggle();
1854
1854
 
1855
1855
  ### isLoaded `async`
1856
1856
 
1857
- Resolves a promise when the ChatGPT sidebar has finished loading.
1857
+ Resolves a promise when the ChatGPT sidebar has finished loading. (Times out 5s after New Chat button loads, since New Chat link does not always appear.)
1858
1858
 
1859
1859
  Example code:
1860
1860
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kudoai/chatgpt.js",
3
- "version": "2.9.1",
3
+ "version": "2.9.3",
4
4
  "description": "Client-side JavaScript library for ChatGPT",
5
5
  "author": {
6
6
  "name": "KudoAI & contributors",
@@ -25,6 +25,7 @@
25
25
  "test": "echo \"Error: no test specified\" && exit 1",
26
26
  "preview:docs": "docsify serve docs",
27
27
  "build:js": "bash utils/build.sh",
28
+ "build:docs-js": "minify-js docs --no-mangle",
28
29
  "build:css": "scss-to-css",
29
30
  "bump:patch": "bash utils/bump.sh patch",
30
31
  "bump:minor": "bash utils/bump.sh minor",
@@ -66,7 +67,7 @@
66
67
  "@adamlui/minify.js": "^1.7.0",
67
68
  "@adamlui/scss-to-css": "^1.10.0",
68
69
  "docsify-cli": "^4.4.4",
69
- "eslint": "^9.2.0",
70
+ "eslint": "^9.3.0",
70
71
  "eslint-plugin-json-schema-validator": "^5.1.0",
71
72
  "husky": "^9.0.11"
72
73
  }
@@ -20,7 +20,7 @@
20
20
  </h6>
21
21
  </div>
22
22
 
23
- # <img height=21 src="https://www.google.com/chrome/static/images/favicons/apple-icon-60x60.png"> chatgpt.js-chrome-starter
23
+ # <img height=21 src="https://media.chatgptjs.org/images/icons/platforms/chrome/icon32.png?8c852fa5"> chatgpt.js-chrome-starter
24
24
 
25
25
  <h3>A starting point for developing your own Chrome extension using <a href="https://github.com/KudoAI/chatgpt.js">chatgpt.js</a></h3>
26
26
 
@@ -77,13 +77,13 @@ These are some of the extensions featured by Google that use chatgpt.js:
77
77
 
78
78
 
79
79
  <a href="https://chatgptinfinity.com" target="_blank" rel="noopener">
80
- <img width=777 src="https://raw.githubusercontent.com/adamlui/chatgpt-infinity/main/chrome/media/images/tiles/marquee-promo-tile-1400x560.png">
80
+ <img width=777 src="https://cdn.jsdelivr.net/gh/adamlui/chatgpt-infinity@0f48c4e/chrome/media/images/tiles/marquee-promo-tile-1400x560.png">
81
81
  </a>
82
82
 
83
83
  <p><br>
84
84
 
85
85
  <a href="https://chatgptwidescreen.com" target="_blank" rel="noopener">
86
- <img width=777 src="https://raw.githubusercontent.com/adamlui/chatgpt-widescreen/main/chrome/media/images/tiles/marquee-promo-tile-1400x560.png">
86
+ <img width=777 src="https://cdn.jsdelivr.net/gh/adamlui/chatgpt-widescreen@3ed0950/chrome/media/images/tiles/marquee-promo-tile-1400x560.png">
87
87
  </a>
88
88
 
89
89
  </div>
@@ -147,7 +147,7 @@ const chatgpt = { // eslint-disable-line no-redeclare
147
147
 
148
148
  // Insert text into elements
149
149
  modalTitle.innerText = title || '';
150
- modalMessage.innerText = msg || ''; this.renderHTML(modalMessage);
150
+ modalMessage.innerText = msg || ''; chatgpt.renderHTML(modalMessage);
151
151
 
152
152
  // Create/append buttons (if provided) to buttons div
153
153
  const modalButtons = document.createElement('div');
@@ -400,7 +400,7 @@ const chatgpt = { // eslint-disable-line no-redeclare
400
400
  } catch (err) {
401
401
  console.error(err.message);
402
402
  if (arguments.length == 0) {
403
- console.info('Using backend API method instead.'); this.clearChats('api'); }
403
+ console.info('Using backend API method instead.'); chatgpt.clearChats('api'); }
404
404
  }
405
405
 
406
406
  } else { // API method
@@ -497,7 +497,7 @@ const chatgpt = { // eslint-disable-line no-redeclare
497
497
  }
498
498
  },
499
499
 
500
- continue: function() { this.response.continue(); },
500
+ continue: function() { chatgpt.response.continue(); },
501
501
 
502
502
  detectLanguage: async function(text) {
503
503
  if (!text) return console.error('Text argument not supplied. Pass some text!');
@@ -869,7 +869,8 @@ const chatgpt = { // eslint-disable-line no-redeclare
869
869
 
870
870
  getNewChatButton: function() {
871
871
  for (const navBtnSVG of document.querySelectorAll('nav button svg'))
872
- if (navBtnSVG.querySelector('path[d*="M15.673 3.913a3.121"]')) // new chat icon found
872
+ if (navBtnSVG.querySelector('path[d*="M15.673 3.913a3.121"], ' // pencil-on-pad icon
873
+ + 'path[d*="M3.07 10.876C3.623"]')) // refresh icon if temp chat
873
874
  return navBtnSVG.parentNode;
874
875
  },
875
876
 
@@ -917,7 +918,7 @@ const chatgpt = { // eslint-disable-line no-redeclare
917
918
  return new Promise(resolve => {
918
919
  (function checkChatHistory() {
919
920
  if (document.querySelector('nav')) resolve(true);
920
- else setTimeout(checkChatHistory, 100);
921
+ else setTimeout(checkChatHistory, 200);
921
922
  })();
922
923
  });}
923
924
  },
@@ -1056,7 +1057,7 @@ const chatgpt = { // eslint-disable-line no-redeclare
1056
1057
  return new Promise(resolve => {
1057
1058
  (function checkIsIdle() {
1058
1059
  if (chatgpt.getRegenerateButton()) resolve(true);
1059
- else setTimeout(checkIsIdle, 100);
1060
+ else setTimeout(checkIsIdle, 200);
1060
1061
  })();
1061
1062
  });},
1062
1063
 
@@ -1064,7 +1065,7 @@ const chatgpt = { // eslint-disable-line no-redeclare
1064
1065
  return new Promise(resolve => {
1065
1066
  (function checkIsLoaded() {
1066
1067
  if (chatgpt.getNewChatButton()) resolve(true);
1067
- else setTimeout(checkIsLoaded, 100);
1068
+ else setTimeout(checkIsLoaded, 200);
1068
1069
  })();
1069
1070
  });},
1070
1071
 
@@ -1367,9 +1368,9 @@ const chatgpt = { // eslint-disable-line no-redeclare
1367
1368
  nodeContent = node.childNodes;
1368
1369
 
1369
1370
  // Preserve consecutive spaces + line breaks
1370
- if (!this.renderHTML.preWrapSet) {
1371
- node.style.whiteSpace = 'pre-wrap'; this.renderHTML.preWrapSet = true;
1372
- setTimeout(() => { this.renderHTML.preWrapSet = false; }, 100);
1371
+ if (!chatgpt.renderHTML.preWrapSet) {
1372
+ node.style.whiteSpace = 'pre-wrap'; chatgpt.renderHTML.preWrapSet = true;
1373
+ setTimeout(() => { chatgpt.renderHTML.preWrapSet = false; }, 100);
1373
1374
  }
1374
1375
 
1375
1376
  // Process child nodes
@@ -1393,7 +1394,7 @@ const chatgpt = { // eslint-disable-line no-redeclare
1393
1394
  tagNode.setAttribute(name, value);
1394
1395
  });
1395
1396
 
1396
- const renderedNode = this.renderHTML(tagNode); // render child elements of newly created node
1397
+ const renderedNode = chatgpt.renderHTML(tagNode); // render child elements of newly created node
1397
1398
 
1398
1399
  // Insert newly rendered node
1399
1400
  const beforeTextNode = document.createTextNode(text.substring(0, elem.index)),
@@ -1406,7 +1407,7 @@ const chatgpt = { // eslint-disable-line no-redeclare
1406
1407
  }
1407
1408
 
1408
1409
  // Process element nodes recursively
1409
- } else if (childNode.nodeType == Node.ELEMENT_NODE) this.renderHTML(childNode);
1410
+ } else if (childNode.nodeType == Node.ELEMENT_NODE) chatgpt.renderHTML(childNode);
1410
1411
  }
1411
1412
 
1412
1413
  return node; // if assignment used
@@ -1485,7 +1486,7 @@ const chatgpt = { // eslint-disable-line no-redeclare
1485
1486
  for (let i = 0; i < arguments.length; i++) if (typeof arguments[i] !== 'string')
1486
1487
  return console.error(`Argument ${ i + 1 } must be a string!`);
1487
1488
  const textArea = document.querySelector('form textarea'),
1488
- sendBtn = this.getSendButton();
1489
+ sendBtn = chatgpt.getSendButton();
1489
1490
  textArea.value = msg;
1490
1491
  textArea.dispatchEvent(new Event('input', { bubbles: true })); // enable send button
1491
1492
 
@@ -1761,17 +1762,22 @@ const chatgpt = { // eslint-disable-line no-redeclare
1761
1762
  if (isToggleBtn(btn)) { btn.click(); return; }
1762
1763
  },
1763
1764
 
1764
- isLoaded: function() {
1765
- return new Promise(resolve => {
1766
- (function checkIsLoaded() {
1767
- if (document.querySelector('nav a[href="/"]')) resolve(true);
1768
- else setTimeout(checkIsLoaded, 100);
1769
- })();
1770
- });}
1765
+ isLoaded: async function() {
1766
+ await chatgpt.isLoaded();
1767
+ return Promise.race([
1768
+ new Promise(resolve => {
1769
+ (function checkNewChatLink() {
1770
+ if (chatgpt.getNewChatLink()) resolve(true);
1771
+ else setTimeout(checkNewChatLink, 200);
1772
+ })();
1773
+ }),
1774
+ new Promise(resolve => setTimeout(resolve, 5000)) // since New Chat link not always present
1775
+ ]);
1776
+ }
1771
1777
  },
1772
1778
 
1773
- startNewChat: function() { try { this.getNewChatBtn().click(); } catch (err) { console.error(err.message); }},
1774
- stop: function() { this.response.stopGenerating(); },
1779
+ startNewChat: function() { try { chatgpt.getNewChatBtn().click(); } catch (err) { console.error(err.message); }},
1780
+ stop: function() { chatgpt.response.stopGenerating(); },
1775
1781
 
1776
1782
  suggest: async function(ideaType, details) {
1777
1783
  if (!ideaType) return console.error('ideaType (1st argument) not supplied'
@@ -2,7 +2,7 @@
2
2
  "manifest_version": 3,
3
3
  "name": "ChatGPT Extension",
4
4
  "description": "A Chrome template to start using chatgpt.js like a boss!",
5
- "version": "2024.5.17",
5
+ "version": "2024.5.24",
6
6
  "author": "chatgpt.js",
7
7
  "icons": {
8
8
  "16": "icons/icon16.png",
@@ -12,13 +12,13 @@
12
12
 
13
13
  <img src="../chrome/media/images/screenshots/extension-loaded.png">
14
14
 
15
- <h2><a href="../chrome"><img style="margin: 0 2px -1px 0" height=18 src="https://www.google.com/chrome/static/images/favicons/apple-icon-60x60.png"></a> <a href="../chrome">Chrome starter</a></h2>
15
+ <h2><a href="../chrome"><img style="margin: 0 2px -1px 0" height=18 src="https://media.chatgptjs.org/images/icons/platforms/chrome/icon32.png?8c852fa5"></a> <a href="../chrome">Chrome starter</a></h2>
16
16
 
17
17
  Template for creating a Chrome extension using chatgpt.js (including pop-up menu + settings management)
18
18
 
19
19
  [Repo](https://github.com/KudoAI/chatgpt.js-chrome-starter) / [Readme](../chrome#readme) / [Get help](https://github.com/KudoAI/chatgpt.js-chrome-starter/issues)
20
20
 
21
- <h2><a href="../greasemonkey"><img style="margin: 0 2px -0.065rem 0" height=19 src="https://cdn.jsdelivr.net/gh/KudoAI/chatgpt.js@e26f2cf/starters/media/images/icons/tampermonkey-icon28.png"><img style="margin: 0 2px -0.035rem 1px" height=19.5 src="https://cdn.jsdelivr.net/gh/KudoAI/chatgpt.js@0c37090/starters/media/images/icons/violentmonkey-icon100.png"></a> <a href="../greasemonkey">Greasemonkey starter</a></h2>
21
+ <h2><a href="../greasemonkey"><img style="margin: 0 2px -0.065rem 0" height=19 src="https://media.chatgptjs.org/images/icons/platforms/tampermonkey/icon28.png?a3e53bf7"><img style="margin: 0 2px -0.035rem 1px" height=19.5 src="https://media.chatgptjs.org/images/icons/platforms/violentmonkey/icon25.png?a3e53bf7"></a> <a href="../greasemonkey">Greasemonkey starter</a></h2>
22
22
 
23
23
  Template for creating a Greasemonkey userscript using chatgpt.js
24
24
 
@@ -3,13 +3,13 @@
3
3
  // @description A Greasemonkey template to start using chatgpt.js like a boss
4
4
  // @author chatgpt.js
5
5
  // @namespace https://chatgpt.js.org
6
- // @version 2024.5.17.2
6
+ // @version 2024.5.24.1
7
7
  // @license MIT
8
8
  // @match *://chatgpt.com/*
9
9
  // @match *://chat.openai.com/*
10
- // @icon https://cdn.jsdelivr.net/gh/KudoAI/chatgpt.js@2.9.1d875/starters/greasemonkey/media/images/icons/robot/icon48.png
11
- // @icon64 https://cdn.jsdelivr.net/gh/KudoAI/chatgpt.js@2.9.1d875/starters/greasemonkey/media/images/icons/robot/icon64.png
12
- // @require https://cdn.jsdelivr.net/npm/@kudoai/chatgpt.js@2.9.1/dist/chatgpt.min.js
10
+ // @icon https://cdn.jsdelivr.net/gh/KudoAI/chatgpt.js@2.9.3/starters/greasemonkey/media/images/icons/robot/icon48.png
11
+ // @icon64 https://cdn.jsdelivr.net/gh/KudoAI/chatgpt.js@2.9.3/starters/greasemonkey/media/images/icons/robot/icon64.png
12
+ // @require https://cdn.jsdelivr.net/npm/@kudoai/chatgpt.js@2.9.3/dist/chatgpt.min.js
13
13
  // @grant GM_getValue
14
14
  // @grant GM_setValue
15
15
  // @noframes