ChatGPT 티키타카
2023.03.24
ChatGPT 끼리 대화 하는 js 프로그램
- New chat (openai.com) 에 접속
- 아래 코드를 복사해서 브라우저 콘솔(F12 -> Console)에 붙여넣고 실행(Enter)
- 프롬프트 창이 뜨면 주제(첫 질문)을 입력
document.body.removeChild(document.body.firstChild)
document.body.innerHTML = `<table>
<tr>
<td><iframe style = 'width:49vw;height:100vh;border-right:2px solid blue;' id = 'gptchat1' src = 'https://chat.openai.com/chat/36327d80-e9a4-4cd2-a4e7-agptbattle1'></iframe></td>
<td><iframe style = 'width:49vw;height:100vh;border-left:2px solid orange;' id = 'gptchat2' src = 'https://chat.openai.com/chat/1aa8ab10-2e0a-4856-8d83-agptbattle2'></iframe></td>
</tr>
</table>`
//for for it to load
await new Promise(r => setTimeout(r, 10000));
const f1 = document.getElementById("gptchat1")
const f2 = document.getElementById("gptchat2")
const c1t = f1.contentDocument.querySelector("textArea")
const c1b = f1.contentDocument.getElementsByClassName("absolute p-1 rounded-md text-gray-500 bottom-1.5 right-1 md:bottom-2.5 md:right-2 hover:bg-gray-100 dark:hover:text-gray-400 dark:hover:bg-gray-900 disabled:hover:bg-transparent dark:disabled:hover:bg-transparent")[0]
const c2t = f2.contentDocument.querySelector("textArea")
const c2b = f2.contentDocument.getElementsByClassName("absolute p-1 rounded-md text-gray-500 bottom-1.5 right-1 md:bottom-2.5 md:right-2 hover:bg-gray-100 dark:hover:text-gray-400 dark:hover:bg-gray-900 disabled:hover:bg-transparent dark:disabled:hover:bg-transparent")[0]
const r1 = f1.contentDocument.getElementsByClassName("w-full border-b border-black/10 dark:border-gray-900/50 text-gray-800 dark:text-gray-100 group bg-gray-50 dark:bg-[#444654]")
const r2 = f2.contentDocument.getElementsByClassName("w-full border-b border-black/10 dark:border-gray-900/50 text-gray-800 dark:text-gray-100 group bg-gray-50 dark:bg-[#444654]")
let q1 = ""
let q2 = ""
const c1btn = f1.contentDocument.getElementsByClassName("absolute p-1 rounded-md text-gray-500 bottom-1.5 md:bottom-2.5 hover:bg-gray-100 dark:hover:text-gray-400 dark:hover:bg-gray-900 disabled:hover:bg-transparent dark:disabled:hover:bg-transparent")[0]
const c2btn = f2.contentDocument.getElementsByClassName("absolute p-1 rounded-md text-gray-500 bottom-1.5 md:bottom-2.5 hover:bg-gray-100 dark:hover:text-gray-400 dark:hover:bg-gray-900 disabled:hover:bg-transparent dark:disabled:hover:bg-transparent")[0]
const answertxt = "(이 질문에 대답하고 나에게 아무것이나 질문 해줘):\n ";
const observer1 = new MutationObserver(function (mutationsList) {
for (let mutation of mutationsList) {
if (mutation.type === "attributes" && mutation.attributeName === "disabled") {
if (c1btn.disabled == false) {
q1 = Array.from(r1[r1.length - 1].children[0].children[1].children[0].children[0].children[0].children).at(-1).textContent
c2t.value = answertxt + q1
c2b.click()
}
}
}
});
observer1.observe(c1btn, { attributes: true });
const observer2 = new MutationObserver(function (mutationsList) {
for (let mutation of mutationsList) {
if (mutation.type === "attributes" && mutation.attributeName === "disabled") {
if (c2btn.disabled == false) {
q2 = Array.from(r2[r2.length - 1].children[0].children[1].children[0].children[0].children[0].children).at(-1).textContent
c1t.value = answertxt + q2
c1b.click()
}
}
}
});
observer2.observe(c2btn, { attributes: true });
var userInput = prompt("질문의 주제를 정하세요:");
chatstart(answertxt + userInput)
function chatstart(text) {
c1t.value = text
c1b.click();
}