Untitled
Guest 408 30th Apr, 2022
const form = document.querySelector(".typing-area"),
incoming_id = form.querySelector(".incoming_id").value,
inputField = form.querySelector(".input-field"),
sendBtn = form.querySelector("button"),
chatBox = document.querySelector(".chat-box");
form.onsubmit = (e)=>{
e.preventDefault();
}
inputField.focus();
inputField.onkeyup = ()=>{
if(inputField.value != ""){
sendBtn.classList.add("active");
}else{
sendBtn.classList.remove("active");
}
}
sendBtn.onclick = ()=>{
let xhr = new XMLHttpRequest();
xhr.open("POST", "php/insert-chat.php", true);
xhr.onload = ()=>{
if(xhr.readyState === XMLHttpRequest.DONE){
if(xhr.status === 200){
inputField.value = "";
scrollToBottom();
}
}
}
let formData = new FormData(form);
xhr.send(formData);
}
chatBox.onmouseenter = ()=>{
chatBox.classList.add("active");
}
chatBox.onmouseleave = ()=>{
chatBox.classList.remove("active");
}
setInterval(() =>{
let xhr = new XMLHttpRequest();
xhr.open("POST", "php/get-chat.php", true);
xhr.onload = ()=>{
if(xhr.readyState === XMLHttpRequest.DONE){
if(xhr.status === 200){
let data = xhr.response;
chatBox.innerHTML = data;
if(!chatBox.classList.contains("active")){
scrollToBottom();
}
}
}
}
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr.send("incoming_id="+incoming_id);
}, 500);
function scrollToBottom(){
chatBox.scrollTop = chatBox.scrollHeight;
}
To share this paste please copy this url and send to your friends
RAW Paste Data
Recent Pastes
- Untitled
Markup | 19 | 11 hours ago
- Untitled
Markup | 24 | 14 hours ago
- Wanted to see what your conviction is on this theme
Markdown | 14 | 14 hours ago
- Untitled
Markup | 65 | 1 day ago
- mega555kf7lsmb54yd6etzginolhxxi4ytdoma2rf77ngq55fhfcnyid.onion
Template Toolkit 2 | 25 | 1 day ago
- Untitled
Markup | 70 | 2 days ago
- Untitled
Markup | 77 | 2 days ago