chatgpt.jsChatGPT 的強(qiáng)大客戶端 JavaScript 庫
chatgpt.js 是一個(gè)功能強(qiáng)大的 JavaScript 庫,可輕松與 ChatGPT DOM 進(jìn)行交互。
- 功能豐富
- 面向?qū)ο?/li>
- 易于使用
- 輕量級(jí)(但性能最優(yōu))
導(dǎo)入庫
ES6:
(async () => { await import('https://code.chatgptjs.org/chatgpt-latest.min.js'); // 這里是你的代碼 })();
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() // 運(yùn)行你的代碼 } } xhr.send() function yourCode() { // 這里是你的代碼 }
Greasemonkey:
筆記 使用入門模板: kudoai/chatgpt.js-greasemonkey-starter
諸如 Greasy Fork 之類的用戶腳本存儲(chǔ)庫維護(hù)著預(yù)先批準(zhǔn)的 CDN 的白名單(例如來自 cdn.jsdelivr.net 的特定于提交的引用),因此導(dǎo)入 URL 相當(dāng)長(zhǎng)以保持對(duì)這些站點(diǎn)的可發(fā)布性:
... // @require https://cdn.jsdelivr.net/gh/kudoai/chatgpt.js@24a755998291094d0cd3b2bd395dff7c6756bbf9/dist/chatgpt-1.12.0.min.js // ==/UserScript== // 這里是你的代碼
如果你不打算發(fā)布到這些存儲(chǔ)庫,則可以使用更簡(jiǎn)單的 https://code.chatgptjs.org/chatgpt-latest.min.js 來導(dǎo)入最新的縮小版本。
Chrome:
筆記 使用入門模板: kudoai/chatgpt.js-chrome-starter
由于 Google 最終將逐步淘汰 Manifest V2,遠(yuǎn)程代碼將不再被允許,因此在本地導(dǎo)入 chatgpt.js 是理想的:
-
將 https://raw.githubusercontent.com/kudoai/chatgpt.js/main/chatgpt.js 保存到子目錄 (本例中為
lib) -
將 ES6 導(dǎo)出語句添加到
lib/chatgpt.js的末尾
... export { chatgpt }
- 在項(xiàng)目的 (V3)
manifest.json中,添加lib/chatgpt.js作為 Web 可訪問資源
"web_accessible_resources": [{
"matches": ["<all_urls>"],
"resources": ["lib/chatgpt.js"]
}],
- 在需要
chatgpt.js(前景/背景相似) 的腳本中, 像這樣導(dǎo)入它:
(async () => { const { chatgpt } = await import(chrome.runtime.getURL('lib/chatgpt.js')); // 這里是你的代碼 })();
評(píng)論
圖片
表情
