Giter VIP home page Giter VIP logo

chatgpt.js's Introduction




🤖 A powerful client-side JavaScript library for ChatGPT

About

chatgpt.js is a powerful JavaScript library that allows for super easy interaction w/ the ChatGPT DOM.

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

⚡ Importing the library

ES6:

(async () => {
  await import('https://code.chatgptjs.org/chatgpt-latest.min.js');
  // Your code here...
})();

ES5:

var xhr = new XMLHttpRequest();
xhr.open('GET', 'https://code.chatgptjs.org/chatgpt-latest.min.js');
xhr.onload = function () {
  if (xhr.status === 200) {
    var chatgptJS = document.createElement('script');
    chatgptJS.textContent = xhr.responseText;
    document.head.appendChild(chatgptJS);
    yourCode(); // runs your code
  }
};
xhr.send();

function yourCode() {
  // Your code here...
}

Greasemonkey:

Note To 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:

...
// @require https://cdn.jsdelivr.net/gh/kudoai/chatgpt.js@24a755998291094d0cd3b2bd395dff7c6756bbf9/dist/chatgpt-1.12.0.min.js
// ==/UserScript==

// Your code here...

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

Chrome:

Note To 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:

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

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

...
export { chatgpt }
  1. In project's (V3) manifest.json, add lib/chatgpt.js as a web accessible resource
    "web_accessible_resources": [{
        "matches": ["<all_urls>"],
        "resources": ["lib/chatgpt.js"]
    }],
  1. In scripts that need chatgpt.js (foreground/background alike), import it like so:
(async () => {
  const { chatgpt } = await import(chrome.runtime.getURL('lib/chatgpt.js'));
  // Your code here...
})();

💻 Usage

chatgpt.js was written w/ ultra flexibility in mind.

For example:

chatgpt.getLastResponse();
chatgpt.getLastReply();
chatgpt.response.getLast();
chatgpt.get('reply', 'last');

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

If it didn't, simply submit an issue or PR and it will be integrated, ezpz!

🤖 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




If you've made something w/ chatgpt.js you want to share, email [email protected] or just open a pull request!

🧠 Contributors

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




Consider giving this repo a ⭐ if it helped you!

Releases / Discuss / Back to top ↑

chatgpt.js's People

Contributors

adamlui avatar madkarmaa avatar mefengl avatar kudo-sync-bot avatar sabbaticaldev avatar zin6969 avatar cyfung1031 avatar dependabot[bot] avatar xiaoyingyo avatar eltociear avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.