Skip to content

Instantly share code, notes, and snippets.

@oquno
Last active April 14, 2023 01:59
Show Gist options
  • Save oquno/02f0a151d7a483a020969acc38e85227 to your computer and use it in GitHub Desktop.
Save oquno/02f0a151d7a483a020969acc38e85227 to your computer and use it in GitHub Desktop.
ChatGPTに相談して書いてもらったチャットログをHTML出力するために実行するブックマークレットを手直ししたもの
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