Last active
March 26, 2025 20:52
-
-
Save yetanotherchris/10e1679b7f6e9694928d9249bb9c2f3b to your computer and use it in GitHub Desktop.
ChatGPT export (HTML) sort and add a table of contents
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<body> | |
<ul id="titles"></ul> | |
<div id="root"></div> | |
</body> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// on load, add messages to the root div | |
window.onload = function() { | |
var root = document.getElementById("root"); | |
jsonData = jsonData.sort((a,b) => { | |
a = a.title.toLowerCase(); | |
b = b.title.toLowerCase(); | |
return (a < b) ? -1 : (a > b) ? 1 : 0; | |
}); | |
for (var i = 0; i < jsonData.length; i++) { | |
var conversation = jsonData[i]; | |
var title = conversation.title; | |
if (title == "") { | |
title = "Untitled"; | |
} | |
var titleId = title.toLowerCase().replace(/\s+/g,"-"); | |
var titleLi = document.createElement("li"); | |
titleLi.innerHTML = "<a href='#" +titleId+ "'>" + title + "</a>"; | |
var titlesUl = document.getElementById("titles"); | |
titlesUl.appendChild(titleLi); | |
var messages = getConversationMessages(conversation); | |
var div = document.createElement("div"); | |
div.className = "conversation"; | |
div.innerHTML = "<h4 id="+titleId+">" + title + "</h4>"; | |
for (var j = 0; j < messages.length; j++) { | |
var message = document.createElement("pre"); | |
message.className = "message"; | |
message.innerHTML = `<div class="author">${messages[j].author}</div>` | |
if (messages[j].parts) { | |
for (var k = 0; k < messages[j].parts.length; k++) { | |
var part = messages[j].parts[k]; | |
if (part.text) { | |
message.innerHTML += `<div>${part.text}</div>`; | |
} else if (assetsJson) { | |
if (part.transcript) { | |
message.innerHTML += `<div>[Transcript]: ${part.transcript}</div>`; | |
} else if (part.asset) { | |
var link = assetsJson[part.asset.asset_pointer]; | |
if (link) { | |
message.innerHTML += `<div>[File]: <a href="${link}">${link}</a></div>`; | |
} else { | |
message.innerHTML += `<div>[File]: -Deleted-</div>`; | |
} | |
} | |
} | |
} | |
} | |
div.appendChild(message); | |
} | |
root.appendChild(div); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment