fix: move event listener to prevent script crash

This commit is contained in:
Russell Ballestrini 2025-06-30 17:24:31 -04:00
parent 8c5c71eb02
commit 8f256b19fa

View file

@ -1118,42 +1118,38 @@ async function handleUploadFromElement(button) {
// Initialize the legacy chat interface (for backward compatibility)
function initializeChatInterface() {
try {
// Only initialize if there are legacy elements (chat-container, user-input, etc.)
const legacyElements = document.querySelector('#chat-container, #user-input, #chat-box');
if (!legacyElements) return;
const pageContent = extractWebpageContent();
chatHistory.push({
role: "system",
content: `Here's the content of the webpage: ${pageContent}`
});
// Only initialize if there are legacy elements (chat-container, user-input, etc.)
const legacyElements = document.querySelector('#chat-container, #user-input, #chat-box');
if (!legacyElements) return;
const pageContent = extractWebpageContent();
chatHistory.push({
role: "system",
content: `Here's the content of the webpage: ${pageContent}`
});
marked.setOptions({
highlight: function(code, lang) {
const language = hljs.getLanguage(lang) ? lang : 'plaintext';
return hljs.highlight(code, { language }).value;
}
});
// Add the Read Page button
addReadPageButton();
marked.setOptions({
highlight: function(code, lang) {
const language = hljs.getLanguage(lang) ? lang : 'plaintext';
return hljs.highlight(code, { language }).value;
}
});
// Add the Read Page button
addReadPageButton();
// Add the File Upload button and picker
addFileUploadButton();
} catch (error) {
console.error('Error in initializeChatInterface:', error);
}
// Add the File Upload button and picker
addFileUploadButton();
// Event listeners
document.getElementById("user-input").addEventListener("keydown", function(event) {
if (event.key === "Enter" && !event.shiftKey) {
event.preventDefault();
handleUserInput();
}
});
}
// Event listeners
document.getElementById("user-input").addEventListener("keydown", function(event) {
if (event.key === "Enter" && !event.shiftKey) {
event.preventDefault();
handleUserInput();
}
});
// Function to create floating AI button
function createFloatingAIButton() {