chatgpt.js是一个功能强大的JavaScript库,可轻松与ChatGPTDOM进行交互。
功能丰富面向对象易于使用轻量级(但性能最优)导入库ES6:(asyc()=>{awaitimport('https://code.chatgptjs.org/chatgpt-latest.mi.js');//这里是你的代码})();ES5:varxhr=ewXMLHttpRequest()xhr.ope('GET','https://code.chatgptjs.org/chatgpt-latest.mi.js')xhr.oload=fuctio(){if(xhr.status===200){varchatgptJS=documet.createElemet('script')chatgptJS.textCotet=xhr.resposeTextdocumet.head.appedChild(chatgptJS)yourCode()//运行你的代码}}xhr.sed()fuctioyourCode(){//这里是你的代码}Greasemokey:笔记 使用入门模板: kudoai/chatgpt.js-greasemokey-starter
诸如GreasyFork之类的用户脚本存储库维护着预先批准的CDN的白名单(例如来自 cd.jsdelivr.et 的特定于提交的引用),因此导入URL相当长以保持对这些站点的可发布性:...//@requirehttps://cd.jsdelivr.et/gh/kudoai/chatgpt.js@24a755998291094d0cd3b2bd395dff7c6756bbf9/dist/chatgpt-1.12.0.mi.js//==/UserScript==//这里是你的代码如果你不打算发布到这些存储库,则可以使用更简单的 https://code.chatgptjs.org/chatgpt-latest.mi.js 来导入最新的缩小版本。Chrome:笔记 使用入门模板: kudoai/chatgpt.js-chrome-starter
由于Google 最终将逐步淘汰 MaifestV2,远程代码将不再被允许,因此在本地导入chatgpt.js是理想的:将 https://raw.githubusercotet.com/kudoai/chatgpt.js/mai/chatgpt.js 保存到子目录(本例中为 lib)
将ES6导出语句添加到 lib/chatgpt.js 的末尾
...export{chatgpt}在项目的(V3) maifest.jso 中,添加 lib/chatgpt.js 作为Web可访问资源"web_accessible_resources":[{"matches":["<all_urls>"],"resources":["lib/chatgpt.js"]}],在需要 chatgpt.js (前景/背景相似)的脚本中,像这样导入它:(asyc()=>{cost{chatgpt}=awaitimport(chrome.rutime.getURL('lib/chatgpt.js'));//这里是你的代码})();用法chatgpt.js 的编写考虑到了超级灵活性。例如:chatgpt.getLastRespose()chatgpt.getLastReply()chatgpt.respose.getLast()chatgpt.get('reply','last')每个调用都会同样获取最后一个回应。如果您认为它有效,那么它可能就是有效的……所以只需输入它!(谁有时间看文档?)如果它不起作用,只需提交 issue 或 PR,它将被集成,简单易行!
评论