Open a Character.AI data export (ZIP or JSON) locally and save chats as .txt. Pure parser ported from kamiko.fun's hosted viewer, including the nested turn_key.chat_id split; minimal dependency-free ZIP reader using DecompressionStream in the browser and zlib in Node; synthetic sample fixture; MIT. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
262 lines
12 KiB
HTML
262 lines
12 KiB
HTML
<!doctype html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<title>Character.AI export viewer: open your chat export locally</title>
|
|
<meta name="description" content="Open a Character.AI data export (ZIP or JSON) in your browser, read every chat and save them as text. Nothing is uploaded.">
|
|
<style>
|
|
:root { color-scheme: dark; }
|
|
* { box-sizing: border-box; }
|
|
body { margin: 0; background: #0b0b0d; color: #f2f2f2; font: 15px/1.5 system-ui, -apple-system, Segoe UI, Roboto, sans-serif; }
|
|
main { max-width: 760px; margin: 0 auto; padding: 32px 20px 64px; }
|
|
h1 { font-size: 24px; margin: 0 0 6px; }
|
|
h2 { font-size: 15px; margin: 24px 0 8px; }
|
|
p { margin: 6px 0; }
|
|
.muted { color: rgba(255,255,255,.65); font-size: 13px; }
|
|
a { color: #6ee7b7; }
|
|
.drop { margin-top: 18px; border: 1px dashed rgba(255,255,255,.3); border-radius: 12px; padding: 22px; text-align: center; background: rgba(255,255,255,.04); }
|
|
.drop.over { border-color: #6ee7b7; background: rgba(110,231,183,.08); }
|
|
button { cursor: pointer; border: 1px solid rgba(255,255,255,.2); background: rgba(255,255,255,.06); color: #fff; border-radius: 8px; padding: 6px 12px; font: inherit; font-size: 13px; font-weight: 600; }
|
|
button:hover { background: rgba(255,255,255,.14); }
|
|
button[disabled] { opacity: .4; cursor: default; }
|
|
.row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }
|
|
.alert { border: 1px solid rgba(248,113,113,.4); background: rgba(248,113,113,.1); color: #fecaca; border-radius: 8px; padding: 10px 12px; }
|
|
.warn { color: #fde68a; font-size: 13px; }
|
|
ul, ol { list-style: none; margin: 8px 0 0; padding: 0; }
|
|
.card { border: 1px solid rgba(255,255,255,.15); background: rgba(255,255,255,.04); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; }
|
|
.chats { max-height: 220px; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
|
|
.chats button { width: 100%; display: flex; justify-content: space-between; gap: 12px; text-align: left; font-weight: 500; border: 0; background: rgba(255,255,255,.05); }
|
|
.chats button[aria-pressed="true"] { background: rgba(255,255,255,.2); }
|
|
.chats button span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
.chats button span:last-child { color: rgba(255,255,255,.5); flex-shrink: 0; }
|
|
.msg { background: rgba(255,255,255,.05); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; }
|
|
.msg .who { font-size: 11px; color: rgba(255,255,255,.5); }
|
|
.msg .who b { color: #6ee7b7; }
|
|
.msg .text { white-space: pre-wrap; overflow-wrap: anywhere; margin-top: 2px; }
|
|
.hidden { display: none; }
|
|
footer { margin-top: 40px; font-size: 13px; color: rgba(255,255,255,.55); }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<main>
|
|
<h1>Character.AI export viewer</h1>
|
|
<p class="muted">Open the export ZIP Character.AI sent you, or any JSON file from inside it. It is read in this tab and never uploaded. Save any chat, or all of them, as plain text.</p>
|
|
|
|
<div class="drop" id="drop">
|
|
<p><strong>Drop your Character.AI export here</strong></p>
|
|
<p class="muted">The ZIP, or one or more of its JSON files.</p>
|
|
<button type="button" id="pick">Choose file</button>
|
|
<input type="file" id="file" class="hidden" multiple accept=".zip,.json,application/zip,application/json">
|
|
</div>
|
|
|
|
<div id="status" aria-live="polite" style="margin-top:12px"></div>
|
|
|
|
<section id="result" class="hidden">
|
|
<div class="row">
|
|
<p id="summary"></p>
|
|
<button type="button" id="download-all">Download all as .txt</button>
|
|
</div>
|
|
<p id="skipped" class="warn hidden"></p>
|
|
|
|
<div id="characters-wrap" class="hidden">
|
|
<h2>Characters</h2>
|
|
<ul id="characters"></ul>
|
|
</div>
|
|
|
|
<div id="chats-wrap" class="hidden">
|
|
<h2>Chats</h2>
|
|
<ul id="chats" class="chats"></ul>
|
|
</div>
|
|
|
|
<div id="chat" class="hidden">
|
|
<div class="row">
|
|
<h2 id="chat-title"></h2>
|
|
<button type="button" id="download-one">Download this chat as .txt</button>
|
|
</div>
|
|
<ol id="messages"></ol>
|
|
<button type="button" id="more" class="hidden"></button>
|
|
</div>
|
|
</section>
|
|
|
|
<footer>
|
|
<p>Free and open source (MIT). Hosted version: <a href="https://kamiko.fun/character-ai-export-viewer/">kamiko.fun/character-ai-export-viewer</a>. The export format is undocumented, so parsing is best-effort: some files will not open, and speaker names are shown only when the file carries them.</p>
|
|
</footer>
|
|
</main>
|
|
|
|
<script src="./parser.js"></script>
|
|
<script src="./zip.js"></script>
|
|
<script>
|
|
(function () {
|
|
'use strict';
|
|
const { parseCaiExport, chatToText, allChatsToText, chatFileName } = window.CaiExport;
|
|
const { readJsonEntries } = window.CaiZip;
|
|
|
|
/** Largest file this page will try to open, so a wrong pick cannot freeze the tab. */
|
|
const MAX_FILE_BYTES = 400 * 1024 * 1024;
|
|
/** Messages painted at once; the rest appear on demand so a 20,000 line chat stays responsive. */
|
|
const PAGE_SIZE = 300;
|
|
|
|
const el = (id) => document.getElementById(id);
|
|
const drop = el('drop');
|
|
const input = el('file');
|
|
const status = el('status');
|
|
|
|
let data = null;
|
|
let openKey = null;
|
|
let shown = PAGE_SIZE;
|
|
|
|
async function inflateRaw(bytes) {
|
|
if (typeof DecompressionStream === 'undefined') throw new Error('no_inflate');
|
|
const stream = new Blob([bytes]).stream().pipeThrough(new DecompressionStream('deflate-raw'));
|
|
return new Uint8Array(await new Response(stream).arrayBuffer());
|
|
}
|
|
|
|
async function readSources(files) {
|
|
const sources = [];
|
|
const skipped = [];
|
|
for (const file of files) {
|
|
if (file.size > MAX_FILE_BYTES) throw new Error('too_large');
|
|
if (file.name.toLowerCase().endsWith('.zip')) {
|
|
const bytes = new Uint8Array(await file.arrayBuffer());
|
|
const result = await readJsonEntries(bytes, inflateRaw);
|
|
if (result.error === 'not_a_zip') throw new Error('not_a_zip');
|
|
sources.push(...result.files);
|
|
skipped.push(...result.skipped);
|
|
} else {
|
|
sources.push({ name: file.name, text: await file.text() });
|
|
}
|
|
}
|
|
return { sources, skipped };
|
|
}
|
|
|
|
function count(n, noun) { return n + ' ' + noun + (n === 1 ? '' : 's'); }
|
|
|
|
function setStatus(kind, message) {
|
|
status.innerHTML = '';
|
|
if (!message) return;
|
|
const p = document.createElement('p');
|
|
p.textContent = message;
|
|
if (kind === 'error') { p.className = 'alert'; p.setAttribute('role', 'alert'); }
|
|
else p.className = 'muted';
|
|
status.appendChild(p);
|
|
}
|
|
|
|
function downloadText(name, text) {
|
|
const url = URL.createObjectURL(new Blob([text], { type: 'text/plain;charset=utf-8' }));
|
|
const a = document.createElement('a');
|
|
a.href = url; a.download = name;
|
|
document.body.appendChild(a); a.click(); a.remove();
|
|
setTimeout(() => URL.revokeObjectURL(url), 1000);
|
|
}
|
|
|
|
function stamp(time) { return time ? time.slice(0, 16).replace('T', ' ') : ''; }
|
|
|
|
function renderCharacters() {
|
|
const wrap = el('characters-wrap'); const list = el('characters');
|
|
list.innerHTML = '';
|
|
wrap.classList.toggle('hidden', data.characters.length === 0);
|
|
for (const c of data.characters) {
|
|
const li = document.createElement('li'); li.className = 'card';
|
|
const name = document.createElement('p'); name.innerHTML = '<strong></strong>'; name.firstChild.textContent = c.name;
|
|
li.appendChild(name);
|
|
if (c.description) { const d = document.createElement('p'); d.className = 'muted'; d.textContent = c.description; li.appendChild(d); }
|
|
if (c.greeting) { const g = document.createElement('p'); g.className = 'muted'; g.textContent = 'Greeting: ' + c.greeting; li.appendChild(g); }
|
|
list.appendChild(li);
|
|
}
|
|
}
|
|
|
|
function renderChatList() {
|
|
const wrap = el('chats-wrap'); const list = el('chats');
|
|
list.innerHTML = '';
|
|
wrap.classList.toggle('hidden', data.chats.length === 0);
|
|
for (const chat of data.chats) {
|
|
const li = document.createElement('li');
|
|
const b = document.createElement('button'); b.type = 'button';
|
|
b.setAttribute('aria-pressed', String(chat.key === openKey));
|
|
const title = document.createElement('span'); title.textContent = chat.title;
|
|
const n = document.createElement('span'); n.textContent = String(chat.messages.length);
|
|
b.append(title, n);
|
|
b.addEventListener('click', () => { openKey = chat.key; shown = PAGE_SIZE; renderChatList(); renderChat(); });
|
|
li.appendChild(b); list.appendChild(li);
|
|
}
|
|
}
|
|
|
|
function renderChat() {
|
|
const chat = data.chats.find((c) => c.key === openKey) || null;
|
|
const box = el('chat');
|
|
box.classList.toggle('hidden', !chat);
|
|
if (!chat) return;
|
|
el('chat-title').textContent = chat.title;
|
|
const ol = el('messages'); ol.innerHTML = '';
|
|
for (const m of chat.messages.slice(0, shown)) {
|
|
const li = document.createElement('li'); li.className = 'msg';
|
|
if (m.speaker || m.time) {
|
|
const who = document.createElement('p'); who.className = 'who';
|
|
if (m.speaker) { const b = document.createElement('b'); b.textContent = m.speaker; who.appendChild(b); }
|
|
if (m.speaker && m.time) who.append(' ');
|
|
if (m.time) who.append(stamp(m.time));
|
|
li.appendChild(who);
|
|
}
|
|
const text = document.createElement('p'); text.className = 'text'; text.textContent = m.text;
|
|
li.appendChild(text); ol.appendChild(li);
|
|
}
|
|
const more = el('more');
|
|
const left = chat.messages.length - shown;
|
|
more.classList.toggle('hidden', left <= 0);
|
|
more.textContent = left > 0 ? 'Show more (' + left + ' left)' : '';
|
|
more.onclick = () => { shown += PAGE_SIZE; renderChat(); };
|
|
el('download-one').onclick = () => downloadText(chatFileName(chat, data.chats.indexOf(chat)), chatToText(chat));
|
|
}
|
|
|
|
function renderAll(skipped) {
|
|
el('result').classList.remove('hidden');
|
|
el('summary').textContent = count(data.characters.length, 'character') + ', ' + count(data.chats.length, 'chat') + ', ' + count(data.messageCount, 'message');
|
|
el('download-all').classList.toggle('hidden', data.chats.length === 0);
|
|
el('download-all').onclick = () => downloadText('character-ai-chats.txt', allChatsToText(data.chats));
|
|
const notes = [];
|
|
if (data.unreadable.length) notes.push('Skipped, not valid JSON: ' + data.unreadable.join(', '));
|
|
if (skipped.length) notes.push('Skipped, could not unpack: ' + skipped.join(', '));
|
|
el('skipped').textContent = notes.join(' ');
|
|
el('skipped').classList.toggle('hidden', notes.length === 0);
|
|
renderCharacters(); renderChatList(); renderChat();
|
|
}
|
|
|
|
async function load(fileList) {
|
|
const files = fileList ? Array.from(fileList) : [];
|
|
if (files.length === 0) return;
|
|
setStatus('info', 'Reading your file.');
|
|
el('result').classList.add('hidden');
|
|
data = null; openKey = null;
|
|
try {
|
|
const { sources, skipped } = await readSources(files);
|
|
if (sources.length === 0) { setStatus('error', 'No JSON files were found in that ZIP.'); return; }
|
|
const parsed = parseCaiExport(sources);
|
|
if (parsed.chats.length === 0 && parsed.characters.length === 0) {
|
|
setStatus('error', parsed.unreadable.length === sources.length
|
|
? 'Could not read this file. It is not valid JSON.'
|
|
: 'Could not read this file. No chats or characters were found in it.');
|
|
return;
|
|
}
|
|
data = parsed; openKey = parsed.chats[0] ? parsed.chats[0].key : null; shown = PAGE_SIZE;
|
|
setStatus('info', '');
|
|
renderAll(skipped);
|
|
} catch (error) {
|
|
const code = error instanceof Error ? error.message : '';
|
|
setStatus('error',
|
|
code === 'too_large' ? 'That file is over 400 MB, which is too large to open in a browser tab.'
|
|
: code === 'no_inflate' ? 'This browser cannot unpack ZIP files. Unzip the export first and pick the JSON files inside it.'
|
|
: 'Could not open this file. Choose the ZIP from Character.AI or one of the JSON files inside it.');
|
|
}
|
|
}
|
|
|
|
el('pick').addEventListener('click', () => input.click());
|
|
input.addEventListener('change', (e) => { load(e.target.files); e.target.value = ''; });
|
|
drop.addEventListener('dragover', (e) => { e.preventDefault(); drop.classList.add('over'); });
|
|
drop.addEventListener('dragleave', () => drop.classList.remove('over'));
|
|
drop.addEventListener('drop', (e) => { e.preventDefault(); drop.classList.remove('over'); load(e.dataTransfer.files); });
|
|
})();
|
|
</script>
|
|
</body>
|
|
</html>
|