chatgpt.js

A powerful, open source client-side JavaScript library for ChatGPT

README

undefined

🤖 A powerful client-side JavaScript library for ChatGPT


About


chatgpt.jsis a powerfulJavaScript library that allows for super easyinteraction w/ the ChatGPT DOM.

Feature-rich
Object-oriented
Easy-to-use
Lightweight (yet optimally performant)

undefined

⚡ Importing the library


ES6:


  1. ``` js
  2. (async () => {
  3.     await import('https://code.chatgptjs.org/chatgpt-latest.min.js');
  4.     // Your code here...
  5. })();
  6. ```

ES5:


  1. ``` js
  2. var xhr = new XMLHttpRequest();
  3. xhr.open('GET', 'https://code.chatgptjs.org/chatgpt-latest.min.js');
  4. xhr.onload = function () {
  5.     if (xhr.status === 200) {
  6.         var chatgptJS = document.createElement('script');
  7.         chatgptJS.textContent = xhr.responseText;
  8.         document.head.appendChild(chatgptJS);
  9.         yourCode(); // runs your code
  10.     }
  11. };
  12. xhr.send();

  13. function yourCode() {
  14.     // Your code here...
  15. }
  16. ```

Greasemonkey:


NoteTo use a starter template: kudoai/chatgpt.js-greasemonkey-starter


Userscript repositories like Greasy Fork maintain a whitelist of pre-approved CDNs (such as commit-specific references from cdn.jsdelivr.net) so the import URL is substantially lengthier to preserve publishability to these sites:

  1. ``` js
  2. ...
  3. // @require https://cdn.jsdelivr.net/gh/kudoai/chatgpt.js@2535c87dc1204a4dbe464b69450bfff6197d3d99/dist/chatgpt-2.3.5.min.js
  4. // ==/UserScript==

  5. // Your code here...
  6. ```

If you don't plan on publishing to these repos, the simpler https://code.chatgptjs.org/chatgpt-latest.min.jscan be used instead to import the latest minified release.

Chrome:


NoteTo use a starter template: kudoai/chatgpt.js-chrome-starter


Since Google will eventually phase out Manifest V2, remote code will no longer be allowed, so importing chatgpt.js locally is ideal:

Save https://raw.githubusercontent.com/kudoai/chatgpt.js/main/chatgpt.js to a subdirectory (libin this example)

Add ES6 export statement to end of lib/chatgpt.js

  1. ``` js
  2. ...
  3. export { chatgpt }
  4. ```

In project's (V3) manifest.json, add lib/chatgpt.jsas a web accessible resource

  1. ``` json
  2.     "web_accessible_resources": [{
  3.         "matches": ["<all_urls>"],
  4.         "resources": ["lib/chatgpt.js"]
  5.     }],
  6. ```

In scripts that need chatgpt.js(foreground/background alike), import it like so:

  1. ``` js
  2. (async () => {
  3.     const { chatgpt } = await import(chrome.runtime.getURL('lib/chatgpt.js'));
  4.     // Your code here...
  5. })();
  6. ```

undefined

💻 Usage


chatgpt.jswas written w/ ultra flexibility in mind.

For example:

  1. ``` js
  2. chatgpt.getLastResponse();
  3. chatgpt.getLastReply();
  4. chatgpt.response.getLast();
  5. chatgpt.get('reply', 'last');
  6. ```

Each call equally fetches the last response. If you think it works, it probably will... so just type it!

If it didn't, check out the extended userguide , or simply submit an issue or PR and it will be integrated, ezpz!

undefined

🤖 Made with chatgpt.js


Auto-clear your ChatGPT query history for maximum privacy. Install / Readme / Discuss

Automatically send DAN prompts to ChatGPT. Install / Readme / Discuss

Display ChatGPT answers in Brave Search sidebar (powered by GPT-4!) Install / Readme / Discuss

Automatically continue generating multiple ChatGPT responses.Install /Readme / Discuss


Keeps ChatGPT sessions fresh to eliminate network errors + Cloudflare checks. Install / Readme / Discuss


Display ChatGPT answers in DuckDuckGo sidebar (powered by GPT-4!) Install / Readme / Discuss

undefined

undefined

If you've made something w/ chatgpt.js you want to share, email showcase@chatgptjs.org or just open a pull request !

undefined

🧠 Contributors


This library exists thanks to code, translations, issues & ideas from the following contributors: