Created
June 5, 2025 19:24
-
-
Save jimbrig/069eaafc88196e43cd1ec239783608e2 to your computer and use it in GitHub Desktop.
Export ChatGPT to Markdown JS
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
function h(html) { | |
return html.replace(/<p>/g, '\n\n') | |
.replace(/<\/p>/g, '') | |
.replace(/<b>/g, '**') | |
.replace(/<\/b>/g, '**') | |
.replace(/<i>/g, '_') | |
.replace(/<\/i>/g, '_') | |
.replace(/<code[^>]*>/g, (match) => { | |
const lm = match.match(/class="[^"]*language-([^"]*)"/); | |
return lm ? '\n```' + lm[1] + '\n' : '```'; | |
}) | |
.replace(/<\/code[^>]*>/g, '```') | |
.replace(/<[^>]*>/g, '') | |
.replace(/Copy code/g, '') | |
.replace(/This content may violate our content policy. If you believe this to be in error, please submit your feedback — your input will aid our research in this area./g, '') | |
.trim(); | |
} | |
(() => { | |
const e = document.querySelectorAll(".text-base"); | |
let t = ""; | |
for (const s of e) { | |
if (s.querySelector(".whitespace-pre-wrap")) { | |
t += `**${s.querySelector('img') ? 'You' : 'ChatGPT'}**: ${h(s.querySelector(".whitespace-pre-wrap").innerHTML)}\n\n`; | |
} | |
} | |
const o = document.createElement("a"); | |
o.download = "Conversation with ChatGPT.md"; | |
o.href = URL.createObjectURL(new Blob([t])); | |
o.style.display = "none"; | |
document.body.appendChild(o); | |
o.click(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment