Created
February 6, 2024 13:47
-
-
Save metaist/b0c036577cb668cabb7900ee092d6e18 to your computer and use it in GitHub Desktop.
ChatGPT Download Bookmarklet
This file contains 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
javascript: function h(html) { | |
return html | |
.replace(/<li>[^<]*?<p>/g, "<p>1. ") | |
.replace(/<pre>[^<]*<div .+?<\/div>/g, "") | |
.replace(/<ol start="(\d+)">[^<]*?<li>/g, "\n\n$1. ") | |
.replace(/<ol>/g, "\n") | |
.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, "```\n") | |
.replace(/<li>/g, "1. ") | |
.replace(/<\/li>/g, "\n") | |
.replace(/<[^>]*>/g, "") | |
.replace(/Copy code/g, "") | |
.replace(/```(.+)```\n/g, "```$1```") | |
.replace(/>/g, ">") | |
.replace(/</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 > .text-base"); | |
let t = ""; | |
for (const s of e) | |
s.querySelector(".whitespace-pre-wrap") && | |
((t += t == "" ? "" : "--------\n"), | |
(t += `**${ | |
s.querySelector(".rounded-sm").getAttribute("alt") || "ChatGPT" | |
}**: ${h(s.querySelector(".whitespace-pre-wrap").innerHTML)}\n\n`)); | |
const o = document.createElement("a"); | |
(o.download = | |
(document.querySelector("div.bg-token-surface-secondary")?.innerText || "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