Mercurial Hosting > chat
diff src/chat.js @ 33:e2b7f6393dab
add online
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 10 Nov 2024 19:57:14 -0700 |
parents | 0f40501b0b56 |
children | 62d04ca486dd |
line wrap: on
line diff
--- a/src/chat.js Sat Nov 09 21:41:11 2024 -0700 +++ b/src/chat.js Sun Nov 10 19:57:14 2024 -0700 @@ -173,6 +173,7 @@ } window.onfocus = function() { + // console.log('onfocus'); document.title = title; hasUnseen = false; }; @@ -207,8 +208,9 @@ } setInterval(function(){ + showOnline(); ajax(`heartbeat.js?last_update=${lastUpdate}`); -}, 60000 ); +}, 10000 ); function resync(updated) { lastUpdate = updated; @@ -223,3 +225,30 @@ sound.play(); } +let online = {}; + +function setOnline(userId) { + online[userId] = Date.now(); +} + +function showOnline() { + let old = Date.now() - 20000; + for( let id of Object.keys(online) ) { + if( online[id] < old ) + delete online[id]; + } + let a = []; + for( let id in online ) { + a.push( `span[online="${id}"]` ); + } + let style = document.querySelector('style[online]'); + if( a.length === 0 ) { + style.innerHTML = ''; + } else { + style.innerHTML = ` + ${a.join(', ')} { + background-color: green; + } +` ; + } +}