Last active
April 14, 2023 01:59
-
-
Save oquno/02f0a151d7a483a020969acc38e85227 to your computer and use it in GitHub Desktop.
ChatGPTに相談して書いてもらったチャットログをHTML出力するために実行するブックマークレットを手直ししたもの
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
javascript:(function() { | |
const userStyle = 'font-weight: bold; color: blue;'; | |
const aiStyle = 'font-weight: bold; color: green;'; | |
const messages = document.querySelectorAll(".flex .flex-col .items-start.gap-4"); | |
let chatHistory = ''; | |
messages.forEach(message => { | |
const role = message.childNodes[0].classList && message.childNodes[0].classList.contains('markdown') ? 'ChatGPT' : 'ユーザー'; | |
const style = role === 'ユーザー' ? userStyle : aiStyle; | |
chatHistory += `<p><span style="${style}">${role}: </span>${message.innerHTML}</p>`; | |
}); | |
const htmlTemplate = ` | |
<!DOCTYPE html> | |
<html lang="ja"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>ChatGPTとの会話</title> | |
</head> | |
<body> | |
<h1>ChatGPTとの会話</h1> | |
${chatHistory} | |
</body> | |
</html> | |
`; | |
const fileName = 'chat_history.html'; | |
const blob = new Blob([htmlTemplate], {type: 'text/html'}); | |
const link = document.createElement('a'); | |
link.href = URL.createObjectURL(blob); | |
link.download = fileName; | |
link.click(); | |
URL.revokeObjectURL(link.href); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment