Made this to help me extract Chat GPT logs, for future reference.
Chat GPT did help in helping me write this :)
- Go to Chat GPT
- Type some questions
- Open dev tools, and paste whatever you need from
extract-gpt-chat-logs.jsinto the dev tools console
| // Get the avatar elements, so we can find the content, | |
| // which is the next sibling | |
| avatarClassSelector = '[class*="items-end"]'; // NOTE: This can easily break in the future | |
| elements = document.querySelectorAll(avatarClassSelector); | |
| isQuestion = (index) => index % 2 === 0; | |
| // All the data | |
| questionsAndAnswers = Array.from(elements) | |
| .map((element, index) => { | |
| const contentEl = element.nextElementSibling; | |
| const item = { | |
| contentHtml: contentEl.innerHTML, | |
| text: contentEl.textContent, | |
| }; | |
| if (isQuestion(index)) { | |
| return { question: item }; | |
| } else { | |
| return { answer: item }; | |
| } | |
| }) | |
| .reduce((accumulator, currentValue) => { | |
| if (currentValue.hasOwnProperty("question")) { | |
| accumulator.push(currentValue); | |
| } else { | |
| const lastObject = accumulator[accumulator.length - 1]; | |
| const mergedObject = Object.assign(lastObject, currentValue); | |
| accumulator[accumulator.length - 1] = mergedObject; | |
| } | |
| return accumulator; | |
| }, []); | |
| // Simplified data | |
| questionsAndAnswersText = questionsAndAnswers.map(({ question, answer }) => { | |
| return { | |
| question: question.text, | |
| answer: answer.text, | |
| } | |
| }); | |
| // Show text in the console in groups | |
| questionsAndAnswersText.forEach(({ question, answer }) => { | |
| console.groupCollapsed(question); | |
| console.log(answer); | |
| console.groupEnd(); | |
| }); | |
| // Show text in the console as a table | |
| console.table(questionsAndAnswersText); |