fix: move event listener to prevent script crash
This commit is contained in:
parent
8c5c71eb02
commit
8f256b19fa
1 changed files with 28 additions and 32 deletions
60
uncloseai.js
60
uncloseai.js
|
|
@ -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() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue