`;
- });
- text = text.replace(/(?)\n/g, ' ');
-
- // Highlight searched words in the content if the checkbox is active
- const searchTerm = document.getElementById("search-bar").value.toLowerCase().trim();
- const searchInContent = document.getElementById("search-content-toggle") && document.getElementById("search-content-toggle").checked;
- if (searchTerm && searchInContent) {
- const words = searchTerm.split(/\s+/).filter(word => word.length > 0);
- words.forEach(word => {
- const regex = new RegExp(`(${word.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\$&')})`, 'gi');
- text = text.replace(regex, `$1`);
- });
- }
- return text;
- }
-
+
// Update the chat counter if defined
document.getElementById("chat-counter-text").textContent = conversations.length + " " + translations[lang].chatCountSuffix;
@@ -1340,6 +1437,15 @@
Settings
const lang = localStorage.getItem('language') || 'en';
const chatLink = document.getElementById("chat-link");
+ // Show export button if there are messages and set chat ID
+ const exportButton = document.getElementById("export-button");
+ if (chat.messages && chat.messages.length > 0) {
+ exportButton.style.display = "inline-flex";
+ exportButton.setAttribute("data-chat-id", chatId);
+ } else {
+ exportButton.style.display = "none";
+ }
+
// Only show the link if there are messages
if (chat.messages && chat.messages.length > 0) {
if (chat.service === "Claude" && chat.uuid) {
@@ -1526,7 +1632,152 @@
Settings
console.error(translations[lang].copyError + ": " + err);
});
});
-
+
+ // Export functionality
+ // Function to export as Markdown
+ function exportAsMarkdown(chatData) {
+ const lang = localStorage.getItem('language') || 'en';
+ let markdown = `# ${chatData.title}\n\n`;
+
+ if (chatData.created_time) {
+ markdown += `**Date:** ${chatData.created_time}\n`;
+ }
+ markdown += `\n---\n\n`;
+
+ chatData.messages.forEach((msg, index) => {
+ const sender = msg.role === 'user' ? translations[lang].userSender : chatData.service;
+ markdown += `## ${sender}\n\n${msg.text}\n\n`;
+ });
+
+ const filename = sanitizeFilename(chatData.title) + '.md';
+ downloadFile(markdown, filename, 'text/markdown');
+ }
+
+ // Function to export as HTML
+ function exportAsHTML(chatData) {
+ // Get the current chat content HTML
+ const chatContent = document.getElementById('chat-content');
+ const chatTitle = document.getElementById('chat-title');
+ const contentHeader = document.querySelector('.content-header');
+
+ if (!chatContent || !chatTitle) return;
+
+ // Clone the content header and chat content
+ const headerClone = contentHeader.cloneNode(true);
+ const contentClone = chatContent.cloneNode(true);
+
+ // Remove share button only (not its parent which contains the title)
+ const shareButton = headerClone.querySelector('#share-button');
+ if (shareButton) shareButton.remove();
+
+ // Remove the entire right side div (export container and chat link)
+ const rightSideDiv = headerClone.querySelector('div[style*="display:inline-flex"]:last-child');
+ if (rightSideDiv) rightSideDiv.remove();
+
+ // Add date metadata if available
+ if (chatData.created_time) {
+ const titleContainer = headerClone.querySelector('div[style*="display:inline-flex"]');
+ if (titleContainer) {
+ const dateSpan = document.createElement('span');
+ dateSpan.style.marginLeft = '10px';
+ dateSpan.style.fontSize = '0.9rem';
+ dateSpan.style.color = 'var(--text-light)';
+ dateSpan.textContent = `(${chatData.created_time})`;
+ titleContainer.appendChild(dateSpan);
+ }
+ }
+
+ // Build the HTML document
+ const html = `
+
+
+
+
+ ${escapeHtml(chatData.title)}
+
+
+
+