Danzen
New Coder
I have to expired people post with a callback function and onPostExpired(callback):
JavaScript:
<script type="text/javascript">
(async function() {
//opgave 1
let flashChatter = await apiSimpleSignup();
flashChatter.onPostReceived((post) => {
let textbox = document.getElementById("tekstboks")
let list = document.createElement("ul")
textbox.appendChild(list)
let tid = document.createElement("li")
let tidText = document.createTextNode("timestamp:" + post.timestamp)
tid.appendChild(tidText)
let kanal = document.createElement("li")
let channeltext = document.createTextNode("channel:" + post.channel)
kanal.appendChild(channeltext)
let userName = document.createElement("li")
let usertext = document.createTextNode("username:" + post.username)
userName.appendChild(usertext)
let besked = document.createElement("li")
let messagetext = document.createTextNode("message:" + post.message)
besked.appendChild(messagetext)
textbox.appendChild(tid)
textbox.appendChild(kanal)
textbox.appendChild(userName)
textbox.appendChild(besked)
textbox.classList.add('postid')
console.log(post);
});
// opgave 2
let fname = document.getElementById("fname")
let button = document.getElementById("send")
button.addEventListener("click", function (){
let postObject = {
message: fname.value
}
flashChatter.post(postObject)
});
// opgave 4
})();
//opgave 3
(async function() {
let flashChatter = await apiSimpleSignup();
flashChatter.usernames((users) => {
let liste = document.getElementById("brugere")
for(user of users.data){
let punkt = document.createElement("li")
let punktTekst = document.createTextNode("Bruger:" + " " + user)
punkt.appendChild(punktTekst)
liste.appendChild(punkt)
}
})
flashChatter.onUserConnected(fjern()){
}
function fjern () => {
let fjern = document.getElementsByClassName('postid')
fjern.remove();
};
})();
Last edited by a moderator: