I am building a response generator using gpt.
this is the function that creates a comment item
// Function to create a comment item
function createCommentItem(comment) {
const li = document.createElement('li');
li.innerHTML = `
<input type="checkbox" class="comment-checkbox" data-comment-id="${comment.commentId}" data-comment-text="${comment.response}">
<strong>${comment.author}:</strong> ${comment.text}
<p><strong>Response:</strong> ${comment.response.replace(/'/g, "'")}</p>
<p><strong>Date:</strong> ${new Date(comment.publishedAt).toLocaleDateString()}</p>
<button class="reply-btn">Reply</button>
`;
const replyButton = li.querySelector('.reply-btn');
replyButton.addEventListener('click', () => replyToComment(comment.commentId, comment.response.replace(/'/g, "'")));
return li;
}
this is the function that generate the reply
// Function to reply to a single comment
async function replyToComment(commentId, text) {
try {
const response = await fetch('/reply-to-comment', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ commentId, text })
});
if (response.ok) {
alert('Reply posted successfully');
} else {
alert('Failed to post reply');
}
} catch (error) {
console.error('Error posting reply:', error);
alert('Error posting reply');
}
}
When clicked on the Reply button this code should post the response on text on Youtube however response-1 doesn’t appear on youtube but response-2 does
Response-1:
You’re welcome! If you have any more questions or need further information, feel free to ask.
Response-2:
(Note: this is hindi text, written in english language)
Haan, aksar ek question ke baad aur questions aate hain. Agar aapko kisi topic par detailed information chahiye toh aap multiple questions bhi pooch sakte hain. Main puri koshish karungi aapke sawalon ka jawab dena.
The '
is interfering with the code. I have tried using encoding, removing special characters, adding event listener separately but nothing seems to work.
Ravish Agrawal is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.