Advertisement
sanjaycedti

Untitled

Jan 1st, 2023
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. async function getNewMessages() {
  2.   // the goal here is trying to get new messages and replacing the old messages with the new ones.
  3.   await fetch(`/get_new_messages/s/${sId}`).then(async function(response) {
  4.     const body = await response.text();
  5.     const jsonText = body.replaceAll('\u0027', '\u0022');
  6.     const item = await JSON.parse(jsonText)/*.replaceAll(`'`, `"`);*/
  7.     console.log("Edited array: "+jsonText);
  8.     console.log("Raw array: "+body);
  9.     console.log("Parsed array"+arr)
  10.    
  11.     document.querySelector('.channel-messages ul').innerHTML = null;
  12.  
  13.     for (const obj of item.messages) {
  14.       const message = obj.message
  15.       const sent_by = obj.sent_by
  16.       document.querySelector('.channel-messages ul').insertAdjacentHTML('beforeend', `<li style="padding-left: 10px; color: white; width: 100%;" onmouseover="const collection = this.children; this.style.background = '#535357'; this.style.color = 'white';" onmouseout="const collection = this.children; this.style.background = 'transparent'; this.style.color = 'white';"><b><img src="/assets/images/Goobler-meowsicles.png" width=40/> <onclickFunc onclick="">${sent_by}</onclickFunc> <span class="badge" style="background: mediumpurple;">TESTER <i class="fa fa-check"></i></span> </b> <br>${message}</li>`);
  17.       console.log(obj.message)
  18.     }
  19.    
  20.     //original code
  21.     /*document.querySelector('.channel-messages ul').insertAdjacentHTML('beforeend', `<li style="padding-left: 10px; color: white; width: 100%;" onmouseover="const collection = this.children; this.style.background = '#535357'; this.style.color = 'white';" onmouseout="const collection = this.children; this.style.background = 'transparent'; this.style.color = 'white';"><b><img src="/assets/images/Goobler-meowsicles.png" width=40/> <onclickFunc onclick="">${json.message}</onclickFunc> <span class="badge" style="background: mediumpurple;">TESTER <i class="fa fa-check"></i></span> </b> <br>${json["messages"]['message']}</li>`);*/
  22.   })
  23.   //location.reload()
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement