update AI page

This commit is contained in:
Raven Scott 2024-10-02 04:03:47 -04:00
parent 856e79732e
commit 741ce8b01d

View File

@ -7,13 +7,14 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="<%= process.env.OWNER_NAME %>'s Blog"> <meta name="description" content="<%= process.env.OWNER_NAME %>'s Blog">
<title> <title>
<%= title %> | <%= process.env.OWNER_NAME %>'s' Blog <%= title %> | <%= process.env.OWNER_NAME %>'s Blog
</title> </title>
<!-- Bootstrap CSS --> <!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css"> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css">
<!-- Font Awesome CSS for Icons --> <!-- Font Awesome CSS for Icons -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.6.0/styles/atom-one-dark.min.css"> <link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.6.0/styles/atom-one-dark.min.css">
<!-- Custom CSS --> <!-- Custom CSS -->
<link rel="stylesheet" href="<%= process.env.HOST_URL %>/css/styles.css"> <link rel="stylesheet" href="<%= process.env.HOST_URL %>/css/styles.css">
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png"> <link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
@ -29,7 +30,6 @@
margin: 0; margin: 0;
padding: 0; padding: 0;
overflow: hidden; overflow: hidden;
/* Prevent page scroll */
background-color: #121212; background-color: #121212;
color: white; color: white;
font-family: Arial, sans-serif; font-family: Arial, sans-serif;
@ -39,13 +39,6 @@
background-color: #121212 !important; background-color: #121212 !important;
} }
textarea::placeholder {
color: #007bff;
/* Blue color to match the button */
opacity: 0;
/* Ensures the placeholder text is fully opaque */
}
.chat-container { .chat-container {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
@ -62,13 +55,11 @@
flex-grow: 1; flex-grow: 1;
background-color: #1e1e1e; background-color: #1e1e1e;
overflow: hidden; overflow: hidden;
/* Ensures no overflow beyond screen */
} }
.messages { .messages {
flex-grow: 1; flex-grow: 1;
overflow-y: auto; overflow-y: auto;
/* Enable scrolling */
padding: 20px; padding: 20px;
background-color: #2e2e2e; background-color: #2e2e2e;
border-radius: 5px; border-radius: 5px;
@ -128,84 +119,12 @@
background-color: #555; background-color: #555;
} }
.alert {
margin-top: 10px;
}
/* Buttons side-by-side with sticky behavior */
.input-area { .input-area {
background-color: #1e1e1e; background-color: #1e1e1e;
padding: 10px 20px; padding: 10px 20px;
z-index: 10; z-index: 10;
flex-shrink: 0; flex-shrink: 0;
color: white; color: white;
/* Prevents shrinking */
}
.alert {
margin-top: 10px;
text-align: center;
/* Center the text content */
display: flex;
/* Make sure the alert is a flex container */
justify-content: center;
/* Center flex items horizontally */
align-items: center;
/* Center flex items vertically (if needed) */
}
/* WebKit-based browsers (Chrome, Safari, Edge) */
.messages::-webkit-scrollbar {
width: 8px;
/* Make the scrollbar thin */
}
.messages::-webkit-scrollbar-track {
background: #2e2e2e;
/* Background color for the scrollbar track */
}
.messages::-webkit-scrollbar-thumb {
background-color: #007bff;
/* Blue color for the scrollbar */
border-radius: 10px;
/* Rounded corners for the scrollbar thumb */
border: 2px solid #2e2e2e;
/* Adds space around the thumb */
}
/* Firefox */
.messages {
scrollbar-width: thin;
/* Make the scrollbar thin in Firefox */
scrollbar-color: #007bff #2e2e2e;
/* Blue thumb with dark track */
}
.input-area .btn-primary,
.input-area .btn-secondary {
width: 49%;
}
.btn-primary {
background-color: #007bff;
border-color: #007bff;
}
.btn-primary:hover {
background-color: #0056b3;
border-color: #0056b3;
}
.btn-secondary {
background-color: #6c757d;
border-color: #6c757d;
}
.btn-secondary:hover {
background-color: #5a6268;
border-color: #545b62;
} }
.footer { .footer {
@ -214,16 +133,35 @@
padding: 10px; padding: 10px;
background-color: #121212; background-color: #121212;
} }
</style>
<link rel="apple-touch-icon" sizes="180x180" href="<%= process.env.HOST_URL %>/apple-touch-icon.png"> .copy-button {
<link rel="icon" type="image/png" sizes="32x32" href="<%= process.env.HOST_URL %>/favicon-32x32.png"> background-color: #444;
<link rel="icon" type="image/png" sizes="16x16" href="<%= process.env.HOST_URL %>/favicon-16x16.png"> /* Button background color */
<link rel="manifest" href="<%= process.env.HOST_URL %>/site.webmanifest"> color: white;
<meta name="msapplication-TileColor" content="#da532c"> /* Button text color */
<meta name="theme-color" content="#ffffff"> border: none;
<!-- reCAPTCHA API --> /* Remove border */
<script src="https://www.google.com/recaptcha/api.js" async defer></script> cursor: pointer;
/* Pointer cursor for interaction */
padding: 5px 10px;
/* Adjusted padding for smaller size */
margin-top: 5px;
/* Space at the top */
display: inline-block;
/* Keep the button in line */
font-size: 14px;
/* Slightly smaller font size for compactness */
width: 147px;
/* Prevent the button from stretching */
text-align: left;
/* Align the text left */
}
.copy-button:hover {
background-color: #555;
/* Darker shade on hover */
}
</style>
</head> </head>
<body class="bg-dark text-white"> <body class="bg-dark text-white">
@ -277,7 +215,6 @@
</div> </div>
</div> </div>
</div> </div>
<!-- Footer --> <!-- Footer -->
@ -367,6 +304,11 @@
addCopyButton(block); // Add copy button to code blocks addCopyButton(block); // Add copy button to code blocks
} }
}); });
// Add "Copy Full Response" button after each assistant response
if (sender === 'assistant') {
addCopyFullResponseButton(messages, messageElement);
}
} }
// Adds a copy button to a code block // Adds a copy button to a code block
@ -378,6 +320,16 @@
block.parentNode.appendChild(button); block.parentNode.appendChild(button);
} }
// Adds "Copy Full Response" button below the assistant response
function addCopyFullResponseButton(messagesContainer, messageElement) {
const copyFullResponseButton = document.createElement('button');
copyFullResponseButton.classList.add('copy-button');
copyFullResponseButton.textContent = 'Copy Full Response';
copyFullResponseButton.addEventListener('click', () => copyFullResponse(messageElement));
messagesContainer.appendChild(copyFullResponseButton);
}
// Copies code block content to the clipboard // Copies code block content to the clipboard
function copyToClipboard(block) { function copyToClipboard(block) {
const text = block.innerText; const text = block.innerText;
@ -388,6 +340,33 @@
}); });
} }
// Copies the full response content to the clipboard in Markdown format
function copyFullResponse(messageElement) {
const markdownContent = convertToMarkdown(messageElement);
navigator.clipboard.writeText(markdownContent).then(() => {
displayAlert('success', 'Full response copied to clipboard!');
}).catch((err) => {
displayAlert('error', 'Failed to copy response: ' + err);
});
}
// Converts the HTML content of the response to Markdown
function convertToMarkdown(element) {
let markdown = '';
const nodes = element.childNodes;
nodes.forEach(node => {
if (node.nodeName === 'P') {
markdown += `${node.innerText}\n\n`;
} else if (node.nodeName === 'PRE') {
const codeBlock = node.querySelector('code').innerText;
markdown += `\`\`\`\n${codeBlock}\n\`\`\`\n\n`;
}
});
return markdown;
}
// Displays an alert message // Displays an alert message
function displayAlert(type, message) { function displayAlert(type, message) {
const alertElement = document.getElementById(`${type}-alert`); const alertElement = document.getElementById(`${type}-alert`);
@ -424,27 +403,23 @@
const response = await sendResetRequest(); const response = await sendResetRequest();
if (response.ok) { if (response.ok) {
// Clear the messages in the UI
const messagesContainer = document.getElementById('messages'); const messagesContainer = document.getElementById('messages');
messagesContainer.innerHTML = ''; // Clear all messages messagesContainer.innerHTML = ''; // Clear all messages
// Optionally display a success message
if (displaySuccessMessage) { if (displaySuccessMessage) {
displayAlert('success', 'Messages Cleared!'); displayAlert('success', 'Messages Cleared!');
} }
} else { } else {
// Handle error response from the server
displayAlert('error', 'Failed to reset conversation. Please try again.'); displayAlert('error', 'Failed to reset conversation. Please try again.');
} }
} catch (error) { } catch (error) {
// Handle network or other errors
displayAlert('error', 'An error occurred while resetting the conversation.'); displayAlert('error', 'An error occurred while resetting the conversation.');
} }
} }
// Resets the chat on page load without displaying the success message // Resets the chat on page load without displaying the success message
document.addEventListener('DOMContentLoaded', function () { document.addEventListener('DOMContentLoaded', function () {
resetChat(false); // Call without displaying success message resetChat(false);
}); });
</script> </script>