Skip to content

Instantly share code, notes, and snippets.

@yukiarimo
Created May 3, 2024 22:53
Show Gist options
  • Save yukiarimo/5d2adcf4211e59fa1ecbaefc35c5ab1d to your computer and use it in GitHub Desktop.
Save yukiarimo/5d2adcf4211e59fa1ecbaefc35c5ab1d to your computer and use it in GitHub Desktop.
Character AI Downloader 2.0
let htmlString = document.body.innerHTML
const parser = new DOMParser();
const doc = parser.parseFromString(htmlString, 'text/html');
const messages = [];
const divs = doc.querySelectorAll('.group.relative.max-w-3xl.min-max-w-3xl.m-auto.w-full.p-2');
divs.forEach(div => {
const nameElement = div.querySelector('.text-small');
if (nameElement) {
const name = nameElement.textContent.trim();
if (name === 'Rushia Uruha' || name === 'Yuki' || name === 'Yukiaiiiii') {
const messageElement = div.querySelector('.prose.dark\\:prose-invert.max-w-3xl p');
if (messageElement) {
const message = messageElement.textContent.trim();
messages.push({ name, message });
}
}
}
});
// reverse the order of the messages
messages.reverse();
/* turn messages into a string following the format:
Rushia Uruha: message
Yuki: message
Rushia Uruha: message
Yuki: message
*/
let result = '';
messages.forEach(({ name, message }) => {
result += `${name}: ${message}\n`;
});
// download the result as a text file
const blob = new Blob([result], { type: 'text/plain' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url
a.download = 'messages.txt';
a.click();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment