comparison src/chat.js @ 35:27c41f22d2a9

improve fixPosts
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 12 Nov 2024 17:17:59 -0700
parents 62d04ca486dd
children 436216d17a1b
comparison
equal deleted inserted replaced
34:62d04ca486dd 35:27c41f22d2a9
3 let title = document.title; 3 let title = document.title;
4 let currentChatId = null; 4 let currentChatId = null;
5 let eventSource; 5 let eventSource;
6 let lastUpdate; 6 let lastUpdate;
7 let hasUnseen = false; 7 let hasUnseen = false;
8 let userId;
8 9
9 function evalEvent(event) { 10 function evalEvent(event) {
10 // console.log(event); 11 // console.log(event);
11 eval(event.data); 12 eval(event.data);
12 } 13 }
69 addPost(); 70 addPost();
70 } 71 }
71 } 72 }
72 73
73 function fixPosts() { 74 function fixPosts() {
74 let spans = document.querySelectorAll('span[when][fix]'); 75 let divs = document.querySelectorAll('div[post][fix]');
75 for( let span of spans ) {
76 span.textContent = new Date(Number(span.textContent)).toLocaleString();
77 span.removeAttribute('fix');
78 }
79 let divs = document.querySelectorAll('div[text][fix]');
80 for( let div of divs ) { 76 for( let div of divs ) {
81 div.innerHTML = urlsToLinks(div.innerHTML); 77 let whenSpan = div.querySelector('span[when]');
78 whenSpan.textContent = new Date(Number(whenSpan.textContent)).toLocaleString();
79 let textDiv = div.querySelector('div[text]');
80 textDiv.innerHTML = urlsToLinks(textDiv.innerHTML);
81 if( div.getAttribute('author') === userId )
82 div.querySelector('span[pulldown]').innerHTML = document.querySelector('div[hidden] span[pulldown]').innerHTML;
82 div.removeAttribute('fix'); 83 div.removeAttribute('fix');
83 } 84 }
84 } 85 }
85 86
86 function deleteChat() { 87 function deleteChat() {